From 0ee53aa32535f7d564a0d8cb0c1606d336f639f8 Mon Sep 17 00:00:00 2001 From: ChenLing Date: Tue, 2 Jul 2019 15:04:25 +0800 Subject: [PATCH] =?UTF-8?q?ADD=20aaa-12=20=E5=A2=9E=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=AE=A1=E7=90=86=E2=80=94=E6=9C=AC=E5=9C=B0Portal?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=85=8D=E7=BD=AE=20RCA=EF=BC=9A=20?= =?UTF-8?q?SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9Achenling=20?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config-server/include/localportal.h | 42 ++++++ .../localportal_config/localportal.c | 133 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 Platform/user/configm/config-server/include/localportal.h create mode 100644 Platform/user/configm/config-server/localportal_config/localportal.c diff --git a/Platform/user/configm/config-server/include/localportal.h b/Platform/user/configm/config-server/include/localportal.h new file mode 100644 index 000000000..0bf66bef5 --- /dev/null +++ b/Platform/user/configm/config-server/include/localportal.h @@ -0,0 +1,42 @@ +#ifndef LOCALPORTAL_H_ +#define LOCALPORTAL_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../../../common/rpc/rpc_common.h" + + +/*配置消息 */ +typedef struct { + uint32_t ip; + int port; +}localportal_configure_t; + +/*全局变量初始化 失败为1 成功为0*/ +int Init(localportal_configure_t *localportal); + + +/*检查IP地址是否有效,端口号是否被占用 */ +int _valid_ipv4_port(const char *str, int port); + + +/*判断配置本地Portal服务器的IP地址是否有效,端口号是否被占用 */ +ret_code portalserver_config_chk(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + + +/*系统管理模块将数据内容(IP地址、端口号)发送给web server */ +int portalserver_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len); + +#endif \ No newline at end of file diff --git a/Platform/user/configm/config-server/localportal_config/localportal.c b/Platform/user/configm/config-server/localportal_config/localportal.c new file mode 100644 index 000000000..02bc3fc33 --- /dev/null +++ b/Platform/user/configm/config-server/localportal_config/localportal.c @@ -0,0 +1,133 @@ +#include "../../../../common/rpc/rpc.h" +#include "../include/parsefile.h" +#include "../include/configm.h" +#include "../../../netlink_uapi/libnetlinku.h" +#include "../include/localportal.h" +#include +#include "../../../../../Common/s2j/s2j.h" +#include "../../../../../Common/commuapinl.h" + +/*全局变量,存放本地Portal服务器的IP地址和端口号 */ +localportal_configure_t *localportal; + +/*全局变量初始化 失败为1 成功为0*/ +int Init(localportal_configure_t *localportal) +{ + localportal = (localportal_configure_t *)malloc(sizeof * localportal); + if (NULL == localportal) + { + return 1; + } + + return 0; +} + + +/*检查IP地址是否有效,端口号是否被占用 */ +int _valid_ipv4_port(const char *str, int port) +{ + int ret; + int fd; + int i; + volatile int local_errno; + struct sockaddr_in addr; + fd = socket(AF_INET,SOCK_STREAM,0); //初始化socket + + if(fd ==-1) //检查是否正常初始化socket + { + return -1; + } + + errno = 0; + local_errno = errno; + + ret = inet_pton(AF_INET, str ,&addr.sin_addr); + printf("the value of ret is:%d\n",ret); + if(ret > 0) + { + fprintf(stderr, "\"%s\" is a vaild IPv4 address\n", str); + + 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); + + if( i < 0) + { + printf("port %d has been used. \n", port); + close(fd); + return -1; + } + + printf("port %d is ok. \n", port); + close(fd); + return 0; + } + + else if (ret < 0) + { + fprintf(stderr, "EAFNOSUPPORT: %s\n", strerror(local_errno)); + return -1; + } + else + { + fprintf(stderr, "\"%s\" is not a vaild IPv4 address\n", str); + return -1; + } +} + + +/*判断配置本地Portal服务器的IP地址是否有效,端口号是否被占用 */ +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; + + if(input_len < sizeof(localportal_configure_t) ) + { + ret = RET_INPUTERR; + } + + char str[32]; + inet_ntop(AF_INET, (void *)&struct_portal->ip, str, 32); + char *ip_addr = str; + if( (_valid_ipv4_port(ip_addr, struct_portal->port)) < 0 ) + { + ret = RET_ERR; + } + + ASSERT_RET(ret); + + return RET_OK; +} + + +/*系统管理模块将数据内容(IP地址、端口号)发送给web server */ +int portalserver_config_proc(uint source, uint config_type, + pointer input, int input_len, + pointer output, int *output_len) +{ + ret_code ret = RET_OK; + int code; + localportal_configure_t *struct_portal; + struct_portal = (localportal_configure_t *)input; + + 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", + struct_portal->ip, struct_portal->port); + + /*将配置信息发送到web server */ + + /*把本地Portal server的配置信息存入全局变量 */ + localportal = struct_portal; + + return 0; +} + +