Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2018-06-06 14:39:19 +08:00
parent 5223c4996f
commit f9b8a7fd29
6 changed files with 385 additions and 3 deletions
+23
View File
@@ -0,0 +1,23 @@
# - Try to find libprotobuf-c
# Once done this will define
# LIBPROTOBUFC_FOUND - System has libprotobuf-c
# LIBPROTOBUFC_INCLUDE_DIR - The libprotobuf-c include directories
# LIBPROTOBUFC_LIBRARY - The libraries needed to use libprotobuf-c
find_path(LIBPROTOBUFC_INCLUDE_DIR protobuf-c)
find_library(LIBPROTOBUFC_LIBRARY protobuf-c PATH_SUFFIXES lib64)
if(LIBPROTOBUFC_INCLUDE_DIR)
file(STRINGS "${LIBPROTOBUFC_INCLUDE_DIR}/protobuf-c/protobuf-c.h"
LIBPROTOBUFC_VERSION REGEX "^#define[ \t]+PROTOBUF_C_VERSION[ \t]+[\"0-9]+")
string(REGEX REPLACE "[^0-9.]+" "" LIBPROTOBUFC_VERSION "${LIBPROTOBUFC_VERSION}")
endif()
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBPROTOBUFC_FOUND to TRUE
# if all listed variables are TRUE and the requested version matches.
find_package_handle_standard_args(Libprotobuf-c REQUIRED_VARS
LIBPROTOBUFC_LIBRARY LIBPROTOBUFC_INCLUDE_DIR
VERSION_VAR LIBPROTOBUFC_VERSION)
mark_as_advanced(LIBPROTOBUFC_INCLUDE_DIR LIBPROTOBUFC_LIBRARY)
+20
View File
@@ -0,0 +1,20 @@
enum rtty_message_type {
LOGIN = 1;
LOGINACK = 2;
LOGOUT = 3;
TTY = 4;
ANNOUNCE = 5;
UPFILE = 6;
DOWNFILE = 7;
}
message rtty_message {
required uint32 header = 1; // byte0[0-3]: version, byte0[4-7]: message type
required string sid = 2; // session id
message data {
optional int32 code = 1;
optional bytes data = 2;
optional string name = 3;
optional uint32 size = 4;
}
}
+4 -3
View File
@@ -8,11 +8,12 @@ set(RTTY_VERSION_PATCH 2)
# Check the third party Libraries
find_package(Libubox REQUIRED)
find_package(Libuwsc 1.2 REQUIRED)
find_package(Libprotobuf-c REQUIRED)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUWSC_INCLUDE_DIR} ${LIBUBOX_INCLUDE_DIR})
set(EXTRA_LIBS ${LIBUWSC_LIBRARY} ${LIBUBOX_LIBRARY} blobmsg_json util crypt)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${LIBUWSC_INCLUDE_DIR} ${LIBUBOX_INCLUDE_DIR} ${LIBPROTOBUFC_INCLUDE_DIR})
set(EXTRA_LIBS ${LIBUWSC_LIBRARY} ${LIBUBOX_LIBRARY} ${LIBPROTOBUFC_LIBRARY} blobmsg_json util crypt)
add_executable(rtty main.c utils.c protocol.c command.c)
add_executable(rtty main.c utils.c protocol.c command.c rtty.pb-c.c)
target_link_libraries(rtty ${EXTRA_LIBS})
# configure a header file to pass some of the CMake settings to the source code
+1
View File
@@ -37,6 +37,7 @@
#include "utils.h"
#include "protocol.h"
#include "command.h"
#include "rtty.pb-c.h"
#define RECONNECT_INTERVAL 5
+224
View File
@@ -0,0 +1,224 @@
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: rtty.proto */
/* Do not generate deprecated warnings for self */
#ifndef PROTOBUF_C__NO_DEPRECATED
#define PROTOBUF_C__NO_DEPRECATED
#endif
#include "rtty.pb-c.h"
void rtty_message__data__init
(RttyMessage__Data *message)
{
static RttyMessage__Data init_value = RTTY_MESSAGE__DATA__INIT;
*message = init_value;
}
void rtty_message__init
(RttyMessage *message)
{
static RttyMessage init_value = RTTY_MESSAGE__INIT;
*message = init_value;
}
size_t rtty_message__get_packed_size
(const RttyMessage *message)
{
assert(message->base.descriptor == &rtty_message__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t rtty_message__pack
(const RttyMessage *message,
uint8_t *out)
{
assert(message->base.descriptor == &rtty_message__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t rtty_message__pack_to_buffer
(const RttyMessage *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &rtty_message__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
RttyMessage *
rtty_message__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (RttyMessage *)
protobuf_c_message_unpack (&rtty_message__descriptor,
allocator, len, data);
}
void rtty_message__free_unpacked
(RttyMessage *message,
ProtobufCAllocator *allocator)
{
assert(message->base.descriptor == &rtty_message__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
static const ProtobufCFieldDescriptor rtty_message__data__field_descriptors[4] =
{
{
"code",
1,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_INT32,
offsetof(RttyMessage__Data, has_code),
offsetof(RttyMessage__Data, code),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"data",
2,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_BYTES,
offsetof(RttyMessage__Data, has_data),
offsetof(RttyMessage__Data, data),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"name",
3,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(RttyMessage__Data, name),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"size",
4,
PROTOBUF_C_LABEL_OPTIONAL,
PROTOBUF_C_TYPE_UINT32,
offsetof(RttyMessage__Data, has_size),
offsetof(RttyMessage__Data, size),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned rtty_message__data__field_indices_by_name[] = {
0, /* field[0] = code */
1, /* field[1] = data */
2, /* field[2] = name */
3, /* field[3] = size */
};
static const ProtobufCIntRange rtty_message__data__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 4 }
};
const ProtobufCMessageDescriptor rtty_message__data__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"rtty_message.data",
"Data",
"RttyMessage__Data",
"",
sizeof(RttyMessage__Data),
4,
rtty_message__data__field_descriptors,
rtty_message__data__field_indices_by_name,
1, rtty_message__data__number_ranges,
(ProtobufCMessageInit) rtty_message__data__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor rtty_message__field_descriptors[2] =
{
{
"header",
1,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_UINT32,
0, /* quantifier_offset */
offsetof(RttyMessage, header),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
{
"sid",
2,
PROTOBUF_C_LABEL_REQUIRED,
PROTOBUF_C_TYPE_STRING,
0, /* quantifier_offset */
offsetof(RttyMessage, sid),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned rtty_message__field_indices_by_name[] = {
0, /* field[0] = header */
1, /* field[1] = sid */
};
static const ProtobufCIntRange rtty_message__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 2 }
};
const ProtobufCMessageDescriptor rtty_message__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"rtty_message",
"RttyMessage",
"RttyMessage",
"",
sizeof(RttyMessage),
2,
rtty_message__field_descriptors,
rtty_message__field_indices_by_name,
1, rtty_message__number_ranges,
(ProtobufCMessageInit) rtty_message__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCEnumValue rtty_message_type__enum_values_by_number[7] =
{
{ "LOGIN", "RTTY_MESSAGE_TYPE__LOGIN", 1 },
{ "LOGINACK", "RTTY_MESSAGE_TYPE__LOGINACK", 2 },
{ "LOGOUT", "RTTY_MESSAGE_TYPE__LOGOUT", 3 },
{ "TTY", "RTTY_MESSAGE_TYPE__TTY", 4 },
{ "ANNOUNCE", "RTTY_MESSAGE_TYPE__ANNOUNCE", 5 },
{ "UPFILE", "RTTY_MESSAGE_TYPE__UPFILE", 6 },
{ "DOWNFILE", "RTTY_MESSAGE_TYPE__DOWNFILE", 7 },
};
static const ProtobufCIntRange rtty_message_type__value_ranges[] = {
{1, 0},{0, 7}
};
static const ProtobufCEnumValueIndex rtty_message_type__enum_values_by_name[7] =
{
{ "ANNOUNCE", 4 },
{ "DOWNFILE", 6 },
{ "LOGIN", 0 },
{ "LOGINACK", 1 },
{ "LOGOUT", 2 },
{ "TTY", 3 },
{ "UPFILE", 5 },
};
const ProtobufCEnumDescriptor rtty_message_type__descriptor =
{
PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC,
"rtty_message_type",
"rtty_message_type",
"RttyMessageType",
"",
7,
rtty_message_type__enum_values_by_number,
7,
rtty_message_type__enum_values_by_name,
1,
rtty_message_type__value_ranges,
NULL,NULL,NULL,NULL /* reserved[1234] */
};
+113
View File
@@ -0,0 +1,113 @@
/* Generated by the protocol buffer compiler. DO NOT EDIT! */
/* Generated from: rtty.proto */
#ifndef PROTOBUF_C_rtty_2eproto__INCLUDED
#define PROTOBUF_C_rtty_2eproto__INCLUDED
#include <protobuf-c/protobuf-c.h>
PROTOBUF_C__BEGIN_DECLS
#if PROTOBUF_C_VERSION_NUMBER < 1000000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1002001 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif
typedef struct _RttyMessage RttyMessage;
typedef struct _RttyMessage__Data RttyMessage__Data;
/* --- enums --- */
typedef enum _RttyMessageType {
RTTY_MESSAGE_TYPE__LOGIN = 1,
RTTY_MESSAGE_TYPE__LOGINACK = 2,
RTTY_MESSAGE_TYPE__LOGOUT = 3,
RTTY_MESSAGE_TYPE__TTY = 4,
RTTY_MESSAGE_TYPE__ANNOUNCE = 5,
RTTY_MESSAGE_TYPE__UPFILE = 6,
RTTY_MESSAGE_TYPE__DOWNFILE = 7
PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(RTTY_MESSAGE_TYPE)
} RttyMessageType;
/* --- messages --- */
struct _RttyMessage__Data
{
ProtobufCMessage base;
protobuf_c_boolean has_code;
int32_t code;
protobuf_c_boolean has_data;
ProtobufCBinaryData data;
char *name;
protobuf_c_boolean has_size;
uint32_t size;
};
#define RTTY_MESSAGE__DATA__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&rtty_message__data__descriptor) \
, 0,0, 0,{0,NULL}, NULL, 0,0 }
struct _RttyMessage
{
ProtobufCMessage base;
/*
* byte0[0-3]: version, byte0[4-7]: message type
*/
uint32_t header;
/*
* session id
*/
char *sid;
};
#define RTTY_MESSAGE__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&rtty_message__descriptor) \
, 0, NULL }
/* RttyMessage__Data methods */
void rtty_message__data__init
(RttyMessage__Data *message);
/* RttyMessage methods */
void rtty_message__init
(RttyMessage *message);
size_t rtty_message__get_packed_size
(const RttyMessage *message);
size_t rtty_message__pack
(const RttyMessage *message,
uint8_t *out);
size_t rtty_message__pack_to_buffer
(const RttyMessage *message,
ProtobufCBuffer *buffer);
RttyMessage *
rtty_message__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
void rtty_message__free_unpacked
(RttyMessage *message,
ProtobufCAllocator *allocator);
/* --- per-message closures --- */
typedef void (*RttyMessage__Data_Closure)
(const RttyMessage__Data *message,
void *closure_data);
typedef void (*RttyMessage_Closure)
(const RttyMessage *message,
void *closure_data);
/* --- services --- */
/* --- descriptors --- */
extern const ProtobufCEnumDescriptor rtty_message_type__descriptor;
extern const ProtobufCMessageDescriptor rtty_message__descriptor;
extern const ProtobufCMessageDescriptor rtty_message__data__descriptor;
PROTOBUF_C__END_DECLS
#endif /* PROTOBUF_C_rtty_2eproto__INCLUDED */