From 35c6cc47fb988fec3da7cd5fcbbb3b5e6aeef67c Mon Sep 17 00:00:00 2001 From: ChenLing Date: Mon, 8 Jul 2019 15:59:28 +0800 Subject: [PATCH] =?UTF-8?q?Mod=20=20aaa-12=20=E4=BF=AE=E6=94=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=AE=A1=E7=90=86-=E6=9C=AC=E5=9C=B0Portal=E9=85=8D?= =?UTF-8?q?=E7=BD=AEinput=E6=A0=BC=E5=BC=8F=EF=BC=8C=E8=BF=9B=E8=A1=8Cjson?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=92=8C=E7=BB=93=E6=9E=84=E4=BD=93=E7=9A=84?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=BA=EF=BC=9Achenling=20=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E4=BA=BA=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../localportal_config/localportal.c | 78 +++++++++++++++---- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/Platform/user/configm/config-server/localportal_config/localportal.c b/Platform/user/configm/config-server/localportal_config/localportal.c index abb08d055..aab5c40da 100644 --- a/Platform/user/configm/config-server/localportal_config/localportal.c +++ b/Platform/user/configm/config-server/localportal_config/localportal.c @@ -31,9 +31,9 @@ int _valid_ipv4_port(const char *str, int port) int i; volatile int local_errno; struct sockaddr_in addr; - fd = socket(AF_INET,SOCK_STREAM,0); //初始化socket + fd = socket(AF_INET,SOCK_STREAM,0); /*初始化*/ - if(fd ==-1) //检查是否正常初始化socket + if(fd ==-1) /*检查是否正常初始化socket */ { return -1; } @@ -47,8 +47,8 @@ int _valid_ipv4_port(const char *str, int port) { fprintf(stderr, "\"%s\" is a vaild IPv4 address\n", str); - addr.sin_family = AF_INET; //地址结构的协议簇 - addr.sin_port=htons(port); //地址结构的端口地址,网络字节序 + addr.sin_family = AF_INET; /*地址结构的协议簇 */ + addr.sin_port=htons(port); /*地址结构的端口地址,网络字节序 */ printf("the value of str:%s\n", str); i = (bind(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr))); printf("the value of i:%d\n", i); @@ -79,14 +79,32 @@ int _valid_ipv4_port(const char *str, int port) /*判断配置本地Portal服务器的IP地址是否有效,端口号是否被占用 */ +/*input格式 "{\"type\":0, \"ip\":1027824, \"port\":1010}"*/ ret_code portalserver_config_chk(uint source, uint *config_type, pointer input, int *input_len, pointer output, int *output_len) { ret_code ret = RET_OK; - localportal_configure_t *struct_portal; - struct_portal = (localportal_configure_t *)input; + cJSON *cjson, *res; + /*JSON字符串到JSON格式 */ + cjson = cJSON_Parse(input); + if(!cjson) + { + ret = RET_INPUTERR; + ASSERT_RET(ret); + return ret; + } + + /*创建freeauth_configure_t结构体对象 */ + s2j_create_struct_obj(struct_portal, localportal_configure_t); + + /*反序列化数据到freeauth_configure_t结构体对象 */ + s2j_struct_get_basic_element(struct_portal, cjson, int, ip); + s2j_struct_get_basic_element(struct_portal, cjson, int, port); + rpc_log_info("localport configure: ip: %d port: %d\n", + struct_portal->ip,struct_portal->port); + if(*input_len < sizeof(localportal_configure_t) ) { ret = RET_INPUTERR; @@ -112,23 +130,57 @@ ret_code portalserver_config_proc(uint source, uint config_type, pointer output, int *output_len) { ret_code ret = RET_OK; - int code; - localportal_configure_t *struct_portal; - struct_portal = (localportal_configure_t *)input; + cJSON *cjson, *res; + char * ret_char = NULL; + int * ret_int = NULL; + + /*JSON字符串到JSON格式 */ + cjson = cJSON_Parse(input); + if(!cjson) + { + ret = RET_INPUTERR; + ASSERT_RET(ret); + return ret; + } + + /*创建freeauth_configure_t结构体对象 */ + s2j_create_struct_obj(struct_portal, localportal_configure_t); + + /*反序列化数据到freeauth_configure_t结构体对象 */ + s2j_struct_get_basic_element(struct_portal, cjson, int, ip); + s2j_struct_get_basic_element(struct_portal, cjson, int, port); char str[32]; inet_ntop(AF_INET, (void *)&struct_portal->ip, str, 32); char *ip_addr = str; rpc_log_info("portalserver configure: ip: %s port: %d\n", - ip_addr, struct_portal->port); + ip_addr, struct_portal->port); - /*将配置信息发送到web server */ + /*将配置信息发送到web server,发送结果int类型表示,0表示发送成功,-1表示发送失败 */ + int r; + + /*创建json对象 */ + res = cJSON_CreateObject(); + if(!res) + { + ret = RET_ERR; + ASSERT_RET(ret); + return ret; + } + + cJSON_AddNumberToObject(res, "result", r); + + /*将json对象转换成json字符串 */ + ret_char = cJSON_PrintUnformatted(res); + ret_int = (int*)ret_char; + memcpy(output, ret_int, sizeof(ret_int)+1); + + free(ret_char); + cJSON_Delete(res); /*把本地Portal server的配置信息存入全局变量 */ localportal = struct_portal; - return RET_OK; } -