REM:
1. 增加添加用户信息接口
This commit is contained in:
huangxin 2022-06-13 18:49:12 +08:00
parent 78e1d2ba55
commit f6b5fe515c
15 changed files with 3725 additions and 60 deletions

View File

@ -13,7 +13,7 @@ PKG_SEARCH_MODULE(LIBSSL REQUIRED libssl)
PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto) PKG_SEARCH_MODULE(LIBCRYPTO REQUIRED libcrypto)
SET(COMMON_LIBS ${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS}) SET(COMMON_LIBS ${LIBCURL_LDFLAGS} ${LIBSSL_LDFLAGS} ${LIBCRYPTO_LDFLAGS})
SET(COMMON_LIBS ${COMMON_LIBS} "-ldl -lpthread -lzlog -lm -luv -lcjson -lzmq -luuid -lconfig -ljemalloc") SET(COMMON_LIBS ${COMMON_LIBS} "-ldl -lpthread -lzlog -lm -luv -lzmq -luuid -lconfig -ljemalloc")
INCLUDE_DIRECTORIES(include ./ ./include ./libs/include ./lwip/src/include ./lwip/src/arch_linux/include ${COMMON_INCLUDE}) INCLUDE_DIRECTORIES(include ./ ./include ./libs/include ./lwip/src/include ./lwip/src/arch_linux/include ${COMMON_INCLUDE})

View File

@ -9,10 +9,9 @@ extern "C" {
#endif #endif
#include <uthash/uthash.h> #include <uthash/uthash.h>
#include "netif/ppp/ppp.h" #include "netif/ppp/ppp.h"
#include "misc.h"
#define PPPOE_MAX_TIMEOUT (30) #define PPPOE_MAX_TIMEOUT (30)
#define MAX_IP_V4_STR (16)
#define MAX_MAC_ADDR_STR (18)
typedef enum { typedef enum {
STATUS_TASK_INIT, STATUS_TASK_INIT,

View File

@ -4,7 +4,7 @@ PROJECT(${LIB_PROJECT_TARGET})
include(ExternalProject) include(ExternalProject)
INCLUDE_DIRECTORIES(include ./ ${COMMON_INCLUDE}) INCLUDE_DIRECTORIES(include ./ ./include ../lwip/src/include ../lwip/src/arch_linux/include ../include ${COMMON_INCLUDE})
FILE(GLOB C_HEADS include/*.h include/uthash/*.h include/s2j/*.h) FILE(GLOB C_HEADS include/*.h include/uthash/*.h include/s2j/*.h)
AUX_SOURCE_DIRECTORY(args C_SRC) AUX_SOURCE_DIRECTORY(args C_SRC)

View File

@ -37,7 +37,10 @@ extern "C" {
#endif #endif
#define VERIFY_STRING(s) (((s) != NULL) && (strlen(s) > 0)) #define VERIFY_STRING(s) (((s) != NULL) && (strlen(s) > 0))
#define PRINTABLE_STRING(s) ((s) == NULL ? "NULL" : (s)) #define SAFETY_STR_STRING(s) ((s) == NULL ? "NULL" : (s))
#define MAX_IP_V4_STR (16)
#define MAX_MAC_ADDR_STR (18)
int file_exists(const char *pPath); int file_exists(const char *pPath);
const char *basename_v2(const char *path); const char *basename_v2(const char *path);

View File

@ -10,8 +10,6 @@ extern "C" {
#include "misc.h" #include "misc.h"
typedef const char *(*DATACHNNELCB)(const char *pMsg, void *pArgs);
typedef struct { typedef struct {
char cmd[MAX_PATH]; char cmd[MAX_PATH];
char key[MAX_PATH]; char key[MAX_PATH];
@ -22,7 +20,7 @@ int mq_init(void);
void mq_uninit(void); void mq_uninit(void);
const char *on_msg_cmd(const char *pCmd); const char *on_msg_cmd(const char *pCmd);
int mq_data_init(DATACHNNELCB dataCb); int mq_data_init();
int mq_data_send_msg(const char *pMsg); int mq_data_send_msg(const char *pMsg);
void *get_mq_context(void); void *get_mq_context(void);

View File

@ -0,0 +1,293 @@
/*
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#ifdef __cplusplus
extern "C"
{
#endif
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
#define __WINDOWS__
#endif
#ifdef __WINDOWS__
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
For *nix builds that support visibility attribute, you can define similar behavior by
setting default visibility to hidden by adding
-fvisibility=hidden (for gcc)
or
-xldscope=hidden (for sun cc)
to CFLAGS
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
*/
#define CJSON_CDECL __cdecl
#define CJSON_STDCALL __stdcall
/* export symbols by default, this is necessary for copy pasting the C and header file */
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_EXPORT_SYMBOLS
#endif
#if defined(CJSON_HIDE_SYMBOLS)
#define CJSON_PUBLIC(type) type CJSON_STDCALL
#elif defined(CJSON_EXPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
#elif defined(CJSON_IMPORT_SYMBOLS)
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
#endif
#else /* !__WINDOWS__ */
#define CJSON_CDECL
#define CJSON_STDCALL
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
#else
#define CJSON_PUBLIC(type) type
#endif
#endif
/* project version */
#define CJSON_VERSION_MAJOR 1
#define CJSON_VERSION_MINOR 7
#define CJSON_VERSION_PATCH 14
#include <stddef.h>
/* cJSON Types: */
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next;
struct cJSON *prev;
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child;
/* The type of the item, as above. */
int type;
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
typedef struct cJSON_Hooks
{
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
} cJSON_Hooks;
typedef int cJSON_bool;
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
* This is to prevent stack overflows. */
#ifndef CJSON_NESTING_LIMIT
#define CJSON_NESTING_LIMIT 1000
#endif
/* returns the version of cJSON as a string */
CJSON_PUBLIC(const char*) cJSON_Version(void);
/* Supply malloc, realloc and free functions to cJSON */
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
/* Render a cJSON entity to text for transfer/storage. */
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
/* Returns the number of items in an array (or object). */
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
/* Get item "string" from object. Case insensitive. */
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
/* Check item type and return its value */
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
/* These functions check the type of an item */
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
/* These calls create a cJSON item of the appropriate type. */
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
/* raw json */
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
/* Append item to the specified array/object. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
/* Remove/Detach items from Arrays/Objects. */
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
* but should point to a readable and writable adress area. */
CJSON_PUBLIC(void) cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
/* helper for the cJSON_SetNumberValue macro */
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
CJSON_PUBLIC(void) cJSON_free(void *object);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -29,9 +29,9 @@
#ifndef __S2J_H__ #ifndef __S2J_H__
#define __S2J_H__ #define __S2J_H__
#include <cjson/cJSON.h>
#include <string.h> #include <string.h>
#include "s2jdef.h" #include "s2jdef.h"
#include "cJSON.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -29,8 +29,8 @@
#ifndef __S2JDEF_H__ #ifndef __S2JDEF_H__
#define __S2JDEF_H__ #define __S2JDEF_H__
#include <cjson/cJSON.h>
#include <string.h> #include <string.h>
#include "cJSON.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -91,7 +91,7 @@ int user_init(const char *pAppCfgFile, const char *pCfgDirectory, const char *pK
dzlog_error("Message queue init error: %d\n", ret); dzlog_error("Message queue init error: %d\n", ret);
} }
if ((ret = mq_data_init(NULL)) != ERR_SUCCESS) { if ((ret = mq_data_init()) != ERR_SUCCESS) {
dzlog_error("Message queue init error: %d\n", ret); dzlog_error("Message queue init error: %d\n", ret);
} }

3095
srcs/libs/json/cJSON.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,37 +9,267 @@
#include "msg_queue.h" #include "msg_queue.h"
#include "config.h" #include "config.h"
#include "user_errno.h"
#include "misc.h" #include "misc.h"
#include "task_manager.h" #include "s2j/s2j.h"
#include "pppoe_info.h"
#include "user_errno.h"
#include "user_info.h"
#define AGENT_CMD_ADDUSER ("add-ywg-pppoe-vcpe")
static void *g_pDataCh = NULL; static void *g_pDataCh = NULL;
static DATACHNNELCB g_pDataChCb = NULL;
static void process_data_msg(void *pDataCh, zmq_msg_t *pMsg) { typedef struct {
const char *pResp; const char *entity;
zmq_msg_t msg; const char *message;
const char *pRecMsg = strdup((const char *)zmq_msg_data(pMsg)); const char *params;
} MQ_DATA_MSG, *PMQ_DATA_MSG;
typedef struct {
char vsvxlanIP[MAX_IP_V4_STR];
char vsvxlanMac[MAX_MAC_ADDR_STR];
} ADD_USER_VXLAN, *PADD_USER_VXLAN;
typedef struct {
unsigned int vni;
unsigned int userId;
unsigned int c_tag_in;
unsigned int s_tag_in;
char clientMac[MAX_MAC_ADDR_STR];
char pppoeUser[MAX_PATH];
char pppoePass[MAX_PATH];
} ADD_USER_USER, *PADD_USER_USER;
typedef struct {
ADD_USER_VXLAN vxlan;
PADD_USER_USER pUser;
unsigned int userCount;
} ADD_INFO, *PADD_INFO;
typedef struct {
PADD_INFO pInfo;
unsigned int infoCount;
} MQ_DATA_ADD_USER, *PMQ_DATA_ADD_USER;
static PMQ_DATA_MSG create_mq_data_msg(PMQ_DATA_MSG *pMsg) {
*pMsg = (PMQ_DATA_MSG)malloc(sizeof(MQ_DATA_MSG));
return *pMsg;
}
static void free_add_user(PMQ_DATA_ADD_USER p) {
int i, j;
for (i = 0; i < p->infoCount; i++) {
for (j = 0; j < p[i].pInfo->userCount; j++) {
if (p[i].pInfo->pUser) {
free(p[i].pInfo->pUser);
}
}
}
free(p->pInfo);
free(p);
}
static void free_mq_data_msg(PMQ_DATA_MSG pMsg) {
if (pMsg->entity) {
free((void *)pMsg->entity);
}
if (pMsg->message) {
free((void *)pMsg->entity);
}
if (pMsg->params) {
free((void *)pMsg->params);
}
free(pMsg);
}
static void *j2s_add_user(cJSON *pJson) {
s2j_create_struct_obj(pUser, ADD_USER_USER);
s2j_struct_get_basic_element(pUser, pJson, int, vni);
s2j_struct_get_basic_element(pUser, pJson, int, userId);
s2j_struct_get_basic_element(pUser, pJson, int, c_tag_in);
s2j_struct_get_basic_element(pUser, pJson, int, s_tag_in);
s2j_struct_get_basic_element(pUser, pJson, string, clientMac);
s2j_struct_get_basic_element(pUser, pJson, string, pppoeUser);
s2j_struct_get_basic_element(pUser, pJson, string, pppoePass);
return pUser;
}
PMQ_DATA_ADD_USER decode_add_user_msg(const char *pStrJson, PMQ_DATA_ADD_USER *pAddUser) {
cJSON *pJsonRoot = cJSON_Parse(pStrJson);
if (pJsonRoot) {
int i;
cJSON *pvxlanMac;
cJSON *pvxlanIp;
cJSON *puser;
int nItems = cJSON_GetArraySize(pJsonRoot);
if (nItems <= 0) {
cJSON_Delete(pJsonRoot);
return NULL;
}
*pAddUser = (PMQ_DATA_ADD_USER)malloc(sizeof(MQ_DATA_ADD_USER));
if (*pAddUser == NULL) {
cJSON_Delete(pJsonRoot);
return NULL;
}
memset(*pAddUser, 0, sizeof(MQ_DATA_ADD_USER));
(*pAddUser)->infoCount = nItems;
(*pAddUser)->pInfo = (PADD_INFO)malloc(sizeof(ADD_INFO) * nItems);
if ((*pAddUser)->pInfo == NULL) {
cJSON_Delete(pJsonRoot);
free(*pAddUser);
return NULL;
}
memset((*pAddUser)->pInfo, 0, sizeof(ADD_INFO) * nItems);
for (i = 0; i < nItems; i++) {
PADD_INFO pCurrent = &((*pAddUser)->pInfo[i]);
cJSON *pcurInfo = cJSON_GetArrayItem(pJsonRoot, i);
pvxlanMac = cJSON_GetObjectItem(pcurInfo, "vsvxlanMac");
pvxlanIp = cJSON_GetObjectItem(pcurInfo, "vsvxlanIP");
puser = cJSON_GetObjectItem(pcurInfo, "users");
if (pvxlanMac) {
strncpy(pCurrent->vxlan.vsvxlanMac, SAFETY_STR_STRING(pvxlanMac->valuestring), MAX_MAC_ADDR_STR);
}
if (pvxlanIp) {
strncpy(pCurrent->vxlan.vsvxlanIP, SAFETY_STR_STRING(pvxlanIp->valuestring), MAX_IP_V4_STR);
}
if (puser) {
int nUser = cJSON_GetArraySize(puser);
if (nUser > 0) {
pCurrent->userCount = nUser;
pCurrent->pUser = (PADD_USER_USER)malloc(sizeof(ADD_USER_USER) * nUser);
if (pCurrent->pUser) {
int j;
memset(pCurrent->pUser, 0, sizeof(ADD_USER_USER) * nUser);
for (j = 0; j < nUser; j++) {
PADD_USER_USER p = &pCurrent->pUser[j];
cJSON *pJsonU = cJSON_GetArrayItem(puser, j);
PADD_USER_USER pTmp = j2s_add_user(pJsonU);
if (pTmp) {
memcpy(p, pTmp, sizeof(ADD_USER_USER));
free(pTmp);
}
}
}
}
}
}
cJSON_Delete(pJsonRoot);
return *pAddUser;
}
return NULL;
}
PMQ_DATA_MSG decode_data_msg(const char *pStrJson) {
cJSON *pJsonRoot = cJSON_Parse(pStrJson);
if (pJsonRoot) {
PMQ_DATA_MSG pMsg = NULL;
create_mq_data_msg(&pMsg);
if (pMsg) {
cJSON *pJsonEntity = cJSON_GetObjectItem(pJsonRoot, "entity");
cJSON *pJsonMessage = cJSON_GetObjectItem(pJsonRoot, "message");
cJSON *pJsonParam = cJSON_GetObjectItem(pJsonRoot, "params");
if (pJsonEntity) {
pMsg->entity = strdup(SAFETY_STR_STRING(pJsonEntity->valuestring));
}
if (pJsonMessage) {
pMsg->message = strdup(SAFETY_STR_STRING(pJsonMessage->valuestring));
}
if (pJsonParam) {
pMsg->params = strdup(SAFETY_STR_STRING(pJsonParam->valuestring));
}
}
cJSON_Delete(pJsonRoot);
return pMsg;
}
return NULL;
}
static void process_data_msg(void *UNUSED(pDataCh), zmq_msg_t *pMsg) {
PMQ_DATA_MSG pMqMsg;
unsigned int size = zmq_msg_size(pMsg) + 1;
char *pdata = zmq_msg_data(pMsg);
unsigned char *pBuf = (unsigned char *)malloc(size);
if (pBuf == NULL) {
return;
}
memset(pBuf, 0, size);
memcpy(pBuf, zmq_msg_data(pMsg), size - 1);
dzlog_info("receive(%zu): %s\n", strlen(pdata), pBuf);
dzlog_info("receive(%zu): %s\n", zmq_msg_size(pMsg), pRecMsg);
zmq_msg_close(pMsg); zmq_msg_close(pMsg);
if (g_pDataChCb) { pMqMsg = decode_data_msg((const char *)pBuf);
pResp = g_pDataChCb(pRecMsg, pDataCh);
if (pResp != NULL && strlen(pResp) > 0) { if (pMqMsg) {
zmq_msg_init_size(&msg, strlen(pResp) + 1); if (strcmp(AGENT_CMD_ADDUSER, pMqMsg->message) == 0) {
memcpy(zmq_msg_data(&msg), pResp, strlen(pResp)); PMQ_DATA_ADD_USER p = NULL;
zmq_msg_send(&msg, pDataCh, 0); dzlog_debug("Process: %s\n", pMqMsg->params);
free((void *)pResp); decode_add_user_msg(pMqMsg->params, &p);
if (p) {
int m, n;
for (m = 0; m < p->infoCount; m++) {
PADD_INFO pInfo = &(p->pInfo[m]);
for (n = 0; n < pInfo->userCount; n++) {
PADD_USER_USER pUser = &(pInfo->pUser[n]);
#if 1
USER_PARAMS userInfo;
memset(&userInfo, 0, sizeof(USER_PARAMS));
userInfo.pppoe_user = pUser->pppoeUser;
userInfo.pppoe_passwd = pUser->pppoePass;
userInfo.vni = pUser->vni;
userInfo.userid = pUser->userId;
userInfo.q1 = pUser->c_tag_in;
userInfo.q2 = pUser->s_tag_in;
str_to_mac(pUser->clientMac, userInfo.mac_addr);
user_info_add(userInfo.userid, &userInfo);
#endif
}
}
free_add_user(p);
}
}
free_mq_data_msg(pMqMsg);
} }
zmq_msg_close(&msg); free(pBuf);
} else {
dzlog_warn("Unhandled message: %s\n", pRecMsg);
}
free((void *)pRecMsg);
} }
int mq_data_send_msg(const char *pMsg) { int mq_data_send_msg(const char *pMsg) {
@ -48,6 +278,7 @@ int mq_data_send_msg(const char *pMsg) {
if (pMsg) { if (pMsg) {
dzlog_debug("Send PPPoE Session: %s\n", pMsg); dzlog_debug("Send PPPoE Session: %s\n", pMsg);
zmq_msg_init_size(&msg, strlen(pMsg) + 1); zmq_msg_init_size(&msg, strlen(pMsg) + 1);
memset(zmq_msg_data(&msg), 0, strlen(pMsg) + 1);
memcpy(zmq_msg_data(&msg), pMsg, strlen(pMsg)); memcpy(zmq_msg_data(&msg), pMsg, strlen(pMsg));
zmq_msg_send(&msg, g_pDataCh, 0); zmq_msg_send(&msg, g_pDataCh, 0);
zmq_msg_close(&msg); zmq_msg_close(&msg);
@ -70,7 +301,7 @@ _Noreturn static void mqDataChannelCb(void *pDataCh) {
} }
} }
int mq_data_init(DATACHNNELCB dataCb) { int mq_data_init() {
static uv_thread_t uvThread; static uv_thread_t uvThread;
void *pContext = zmq_ctx_new(); void *pContext = zmq_ctx_new();
@ -80,8 +311,6 @@ int mq_data_init(DATACHNNELCB dataCb) {
return -ERR_MQ_CREATE_MQ; return -ERR_MQ_CREATE_MQ;
} }
g_pDataChCb = dataCb;
g_pDataCh = zmq_socket(pContext, ZMQ_PAIR); g_pDataCh = zmq_socket(pContext, ZMQ_PAIR);
if (g_pDataCh == NULL) { if (g_pDataCh == NULL) {
@ -92,7 +321,7 @@ int mq_data_init(DATACHNNELCB dataCb) {
memset(buf, 0, 1024); memset(buf, 0, 1024);
sprintf(buf, "%s", cfg_get_zero_mq_data_path()); sprintf(buf, "%s", cfg_get_zero_mq_data_path());
dzlog_info("Start message queue connect: %s\n", cfg_get_zero_mq_data_path()); dzlog_info("Start message queue connect: %s\n", buf);
if (zmq_connect(g_pDataCh, buf) != 0) { if (zmq_connect(g_pDataCh, buf) != 0) {
zmq_close(g_pDataCh); zmq_close(g_pDataCh);

View File

@ -224,9 +224,7 @@ int vxlan_peer_add(unsigned int vni, const char* pIp, const char* pMac) {
PVXLAN_PEER vxlan_peer; PVXLAN_PEER vxlan_peer;
if (!VERIFY_STRING(pIp) || !VERIFY_STRING(pMac)) { if (!VERIFY_STRING(pIp) || !VERIFY_STRING(pMac)) {
dzlog_error("Input parameters error: %s, %s\n", dzlog_error("Input parameters error: %s, %s\n", SAFETY_STR_STRING(pIp), SAFETY_STR_STRING(pMac));
PRINTABLE_STRING(pIp),
PRINTABLE_STRING(pMac));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }
@ -269,7 +267,7 @@ int vxlan_peer_add(unsigned int vni, const char* pIp, const char* pMac) {
int vxlan_link_init(const char *pEthName) { int vxlan_link_init(const char *pEthName) {
if (!VERIFY_STRING(pEthName)) { if (!VERIFY_STRING(pEthName)) {
dzlog_error("Input parameters error: %s\n", PRINTABLE_STRING(pEthName)); dzlog_error("Input parameters error: %s\n", SAFETY_STR_STRING(pEthName));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }
@ -295,9 +293,9 @@ int vxlan_link_init(const char *pEthName) {
if (!VERIFY_STRING(pEthName) || !VERIFY_STRING(pPeerIp) || !VERIFY_STRING(pPeerMac)) { if (!VERIFY_STRING(pEthName) || !VERIFY_STRING(pPeerIp) || !VERIFY_STRING(pPeerMac)) {
dzlog_error("Input parameters error: %s, %s, %s\n", dzlog_error("Input parameters error: %s, %s, %s\n",
PRINTABLE_STRING(pEthName), SAFETY_STR_STRING(pEthName),
PRINTABLE_STRING(pPeerIp), SAFETY_STR_STRING(pPeerIp),
PRINTABLE_STRING(pPeerMac)); SAFETY_STR_STRING(pPeerMac));
return -ERR_INPUT_PARAMS; return -ERR_INPUT_PARAMS;
} }

View File

@ -5,9 +5,7 @@
#include <uv/unix.h> #include <uv/unix.h>
#include <uv.h> #include <uv.h>
#include <uthash/utlist.h> #include <uthash/utlist.h>
#include <cjson/cJSON.h>
#include "pppoe_session.h" #include "pppoe_session.h"
#include "netif/rawif.h"
#include "netif/ppp/ppp.h" #include "netif/ppp/ppp.h"
#include "netif/ppp/pppoe.h" #include "netif/ppp/pppoe.h"
#include "netif/pppoeif.h" #include "netif/pppoeif.h"
@ -18,6 +16,7 @@
#include "msg_queue.h" #include "msg_queue.h"
#include "vxlan_pkg.h" #include "vxlan_pkg.h"
#include "netif/pcapif.h" #include "netif/pcapif.h"
#include "s2j/cJSON.h"
typedef struct PPPOE_CACHE { typedef struct PPPOE_CACHE {
PPPPOE_SESSION_DATA pSessionData; PPPPOE_SESSION_DATA pSessionData;
@ -134,9 +133,8 @@ static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) {
} }
_Noreturn void sessionCalcCb(void *UNUSED(pArg)) { _Noreturn void sessionCalcCb(void *UNUSED(pArg)) {
PUSER_INFO_CONTEXT pUserList = get_all_user_by_id();
do { do {
PUSER_INFO_CONTEXT pUserList = get_all_user_by_id();
PUSER_INFO_CONTEXT pUser, pTmp; PUSER_INFO_CONTEXT pUser, pTmp;
uv_rwlock_rdlock(get_user_lock()); uv_rwlock_rdlock(get_user_lock());

View File

@ -2,6 +2,7 @@
// Created by xajhuang on 2022/5/11. // Created by xajhuang on 2022/5/11.
// //
#include <misc.h> #include <misc.h>
#include <zlog.h>
#include "user_info.h" #include "user_info.h"
#include "user_errno.h" #include "user_errno.h"
@ -19,7 +20,7 @@ static USER_PARAMS g_userInfo[] = {
void user_info_init() { void user_info_init() {
uv_rwlock_init(&g_userLock); uv_rwlock_init(&g_userLock);
user_info_add(0, &g_userInfo[0]); //user_info_add(0, &g_userInfo[0]);
//user_info_add(1, &g_userInfo[1]); //user_info_add(1, &g_userInfo[1]);
//user_info_add(2, &g_userInfo[2]); //user_info_add(2, &g_userInfo[2]);
//user_info_add(3, &g_userInfo[3]); //user_info_add(3, &g_userInfo[3]);
@ -64,6 +65,13 @@ int user_info_add(unsigned int userid, PUSER_PARAMS pInfo) {
HASH_ADD(hh_id, g_pUserByIdList, userid, sizeof(unsigned int), pList); HASH_ADD(hh_id, g_pUserByIdList, userid, sizeof(unsigned int), pList);
HASH_ADD(hh_vxlan, g_pUserByTagsList, vxlan, sizeof(VXLAN_TAG), pList); HASH_ADD(hh_vxlan, g_pUserByTagsList, vxlan, sizeof(VXLAN_TAG), pList);
uv_rwlock_wrunlock(&g_userLock); uv_rwlock_wrunlock(&g_userLock);
dzlog_debug("Add user: id = %u, vni = %u, q1 = %u, q2 = %u ppp_user = %s\n",
userid,
pInfo->vni,
pInfo->q1,
pInfo->q2,
pInfo->pppoe_user);
} }
return ERR_SUCCESS; return ERR_SUCCESS;

View File

@ -5,6 +5,7 @@
#include <zlog.h> #include <zlog.h>
#include <zmq.h> #include <zmq.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "task_manager.h" #include "task_manager.h"
#include "user_errno.h" #include "user_errno.h"
#include "config.h" #include "config.h"
@ -13,15 +14,35 @@
static void *g_pContext = NULL; static void *g_pContext = NULL;
static void *g_pResponse = NULL; static void *g_pResponse = NULL;
static const char *g_pSendMsg = NULL;
static int mq_data_send_msg(const char *pMsg) {
zmq_msg_t msg;
if (pMsg) {
unsigned int size = strlen(pMsg) + 1;
printf("Send: %s\n", pMsg);
zmq_msg_init_size(&msg, size);
memset(zmq_msg_data(&msg), 0, size);
memcpy(zmq_msg_data(&msg), pMsg, size);
if (zmq_msg_send(&msg, g_pResponse, ZMQ_DONTWAIT) == -1) {
perror("zmq_msg_send");
}
zmq_msg_close(&msg);
}
return ERR_SUCCESS;
}
_Noreturn static void mqServerCb(void *UNUSED(pArg)) { _Noreturn static void mqServerCb(void *UNUSED(pArg)) {
while (TRUE) { while (TRUE) {
zmq_msg_t msg; zmq_msg_t msg;
zmq_msg_init(&msg); zmq_msg_init(&msg);
if (zmq_msg_recv(&msg, g_pResponse, 0) != -1) { if (zmq_msg_recv(&msg, g_pResponse, ZMQ_DONTWAIT) != -1) {
printf("Data channel receive(%zu): %s\n", zmq_msg_size(&msg), (const char *)zmq_msg_data(&msg)); printf("Data channel receive(%zu): %s\n", zmq_msg_size(&msg), (const char *)zmq_msg_data(&msg));
zmq_msg_close(&msg); zmq_msg_close(&msg);
mq_data_send_msg("xajhuang");
#if 0 #if 0
zmq_msg_close(&msg); zmq_msg_close(&msg);
@ -37,8 +58,21 @@ _Noreturn static void mqServerCb(void *UNUSED(pArg)) {
} }
} }
_Noreturn static void mqsendServerCb(void *UNUSED(pArg)) {
while (TRUE) {
if(g_pSendMsg) {
printf("+++++\n");
mq_data_send_msg(g_pSendMsg);
printf("-----\n");
}
uv_sleep(10000);
}
}
static int data_mq_init(void) { static int data_mq_init(void) {
static uv_thread_t uvThread; static uv_thread_t uvThread;
const char *mq_name = "ipc:///tmp/msg_fifo1";
char buf[1024]; char buf[1024];
@ -55,19 +89,20 @@ static int data_mq_init(void) {
return -ERR_MQ_CREATE_REP; return -ERR_MQ_CREATE_REP;
} }
memset(buf, 0, 1024); //memset(buf, 0, 1024);
sprintf(buf, "ipc:///tmp/msg_fifo0"); //sprintf(buf, "ipc:///tmp/msg_fifo1");
printf("Start message data channel server: ipc:///tmp/msg_fifo0\n"); printf("Start message data channel server: %s\n", mq_name);
if (zmq_bind(g_pResponse, mq_name) != 0) {
if (zmq_bind(g_pResponse, buf) != 0) { perror("zmq_bind");
zmq_close(g_pResponse); zmq_close(g_pResponse);
zmq_ctx_destroy(g_pContext); zmq_ctx_destroy(g_pContext);
return -ERR_MQ_CONN_SERVER; return -ERR_MQ_CONN_SERVER;
} }
uv_thread_create(&uvThread, mqServerCb, NULL); uv_thread_create(&uvThread, mqServerCb, NULL);
uv_thread_create(&uvThread, mqsendServerCb, NULL);
return ERR_SUCCESS; return ERR_SUCCESS;
} }
@ -75,7 +110,16 @@ static int data_mq_init(void) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
uv_setup_args(argc, argv); uv_setup_args(argc, argv);
data_mq_init(); if (data_mq_init() != ERR_SUCCESS) {
printf("MQ init error\n");
return -1;
}
if (argc > 1) {
if (strlen(argv[1]) > 0) {
g_pSendMsg = strdup(argv[1]);
}
}
task_manager_run(); task_manager_run();
return 0; return 0;