2022-05-10 06:43:27 +00:00
|
|
|
//
|
|
|
|
// Created by xajhu on 2021/6/29 0029.
|
|
|
|
//
|
|
|
|
#include <uv.h>
|
2022-10-28 08:46:55 +00:00
|
|
|
#include <stdlib.h>
|
2022-11-07 06:22:12 +00:00
|
|
|
#include <unistd.h>
|
2023-03-15 06:19:49 +00:00
|
|
|
#include <string.h>
|
2022-05-10 06:43:27 +00:00
|
|
|
#include "cmdline.h"
|
|
|
|
#include "task_manager.h"
|
|
|
|
#include "init.h"
|
2023-03-15 06:13:11 +00:00
|
|
|
#include "inet_misc.h"
|
2023-01-30 06:12:33 +00:00
|
|
|
#include "config.h"
|
2023-02-06 07:10:02 +00:00
|
|
|
#include "zlog_module.h"
|
2022-12-14 02:16:10 +00:00
|
|
|
|
|
|
|
#include "prj_config.h"
|
2022-12-15 08:26:39 +00:00
|
|
|
#include "user_errno.h"
|
2022-12-14 02:16:10 +00:00
|
|
|
|
2022-12-23 02:57:16 +00:00
|
|
|
#ifdef LWIP_ON
|
2022-05-10 06:43:27 +00:00
|
|
|
#include "user_info.h"
|
|
|
|
#include "lwip/tcpip.h"
|
2022-09-28 02:48:02 +00:00
|
|
|
#endif
|
2022-10-28 07:37:01 +00:00
|
|
|
|
2022-12-03 08:46:52 +00:00
|
|
|
#include "proto.h"
|
2022-10-28 07:37:01 +00:00
|
|
|
|
|
|
|
#ifdef OPENDHCPDDNS_ON
|
|
|
|
#include "dual_server/dualsvr.h"
|
|
|
|
#endif
|
2022-05-10 06:43:27 +00:00
|
|
|
|
2022-12-23 02:57:16 +00:00
|
|
|
#ifdef LWIP_ON
|
2022-05-10 06:43:27 +00:00
|
|
|
static void test_init(void *arg) { /* remove compiler warning */
|
|
|
|
sys_sem_t *init_sem;
|
|
|
|
|
|
|
|
init_sem = (sys_sem_t *)arg;
|
|
|
|
|
|
|
|
srand((unsigned int)time(0));
|
|
|
|
|
|
|
|
sys_sem_signal(init_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lwip_init_env() {
|
|
|
|
err_t err;
|
|
|
|
sys_sem_t init_sem;
|
|
|
|
|
2022-10-28 07:37:01 +00:00
|
|
|
err = sys_sem_new(&init_sem, 0);
|
2022-05-10 06:43:27 +00:00
|
|
|
LWIP_UNUSED_ARG(err);
|
|
|
|
tcpip_init(test_init, &init_sem);
|
|
|
|
sys_sem_wait(&init_sem);
|
|
|
|
sys_sem_free(&init_sem);
|
|
|
|
}
|
2022-09-19 01:53:11 +00:00
|
|
|
#endif
|
2022-05-27 07:49:45 +00:00
|
|
|
|
2023-01-30 02:43:20 +00:00
|
|
|
cJSON *create_app_process_status(int isStart) {
|
|
|
|
cJSON *pRspMsg = cJSON_CreateObject();
|
2023-02-16 11:31:19 +00:00
|
|
|
#ifdef USERVNI_ON
|
2023-01-30 02:43:20 +00:00
|
|
|
cJSON_AddNumberToObject(pRspMsg, "vni", cfg_get_user_vni_id());
|
2023-02-07 02:43:11 +00:00
|
|
|
#endif
|
2023-01-30 02:43:20 +00:00
|
|
|
cJSON_AddStringToObject(pRspMsg, "process", isStart ? "setup" : "exit");
|
|
|
|
return pRspMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void on_http_response_cb(void *pData,
|
|
|
|
unsigned int size,
|
|
|
|
const char *pReqUrl,
|
|
|
|
const char *pDlPath,
|
|
|
|
const char *pTaskUuid,
|
|
|
|
int iFinished,
|
|
|
|
void *pUserData) {
|
|
|
|
if (iFinished == 0) {
|
2023-02-06 08:04:11 +00:00
|
|
|
LOG_MOD(debug, ZLOG_MOD_MAIN, "Request(%s): [%s] Response: [%u] OK:\n", pTaskUuid, pReqUrl, size);
|
2023-01-30 02:43:20 +00:00
|
|
|
} else if (iFinished == 1) {
|
2023-02-06 08:04:11 +00:00
|
|
|
LOG_MOD(error, ZLOG_MOD_MAIN, "Request(%s): [%s] Response: [%u] Error\n", pTaskUuid, pReqUrl, size);
|
2023-01-30 02:43:20 +00:00
|
|
|
} else {
|
2023-02-06 08:04:11 +00:00
|
|
|
LOG_MOD(error, ZLOG_MOD_MAIN, "Download Error Code: %d\n", iFinished);
|
2023-01-30 02:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(pUserData);
|
|
|
|
}
|
|
|
|
|
2022-05-10 06:43:27 +00:00
|
|
|
int main(int argc, char **argv) {
|
2023-03-15 06:19:49 +00:00
|
|
|
int ret;
|
|
|
|
const char *pRspUrl;
|
|
|
|
|
2022-10-28 07:37:01 +00:00
|
|
|
#ifdef OPENDHCPDDNS_ON
|
|
|
|
return dual_server_main(argc, argv);
|
2022-11-16 02:36:28 +00:00
|
|
|
#else
|
2022-05-10 06:43:27 +00:00
|
|
|
uv_setup_args(argc, argv);
|
|
|
|
|
2022-12-14 02:16:10 +00:00
|
|
|
printf("Application %s version %s\n", VCPE_PROJECT_NAME, VCPE_PROJECT_VER);
|
|
|
|
|
2022-05-10 06:43:27 +00:00
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
|
2022-10-28 08:46:55 +00:00
|
|
|
ret = menu_run(argc, argv);
|
|
|
|
|
2022-12-06 03:08:29 +00:00
|
|
|
if (ret == ERR_MENU_EXIT) {
|
2022-10-28 08:46:55 +00:00
|
|
|
user_uninit();
|
|
|
|
exit(0);
|
2022-11-23 02:41:05 +00:00
|
|
|
} else if (ret != ERR_SUCCESS) {
|
2022-10-28 08:46:55 +00:00
|
|
|
printf("Application setup error(%d), please used --help to show usage, exited!!!\n", ret);
|
|
|
|
user_uninit();
|
|
|
|
exit(0);
|
|
|
|
}
|
2022-05-10 06:43:27 +00:00
|
|
|
|
2022-12-23 02:57:16 +00:00
|
|
|
#ifdef LWIP_ON
|
2022-05-27 07:49:45 +00:00
|
|
|
lwip_init_env();
|
2022-05-10 06:43:27 +00:00
|
|
|
user_info_init();
|
2022-09-19 01:53:11 +00:00
|
|
|
pppoe_session_init();
|
|
|
|
#endif
|
2022-05-10 06:43:27 +00:00
|
|
|
|
2023-03-15 06:19:49 +00:00
|
|
|
pRspUrl = config_get_agent_moniter_report_url();
|
|
|
|
|
|
|
|
if (pRspUrl && strlen(pRspUrl) > 0) {
|
|
|
|
const char *pStrSetup = proto_create_new(create_app_process_status(1), 200);
|
|
|
|
inet_http_post_async(config_get_agent_moniter_report_url(), pStrSetup, on_http_response_cb, (void *)pStrSetup);
|
|
|
|
}
|
2022-11-07 06:22:12 +00:00
|
|
|
|
2023-03-15 01:36:16 +00:00
|
|
|
task_manager_run();
|
2023-03-15 06:13:11 +00:00
|
|
|
|
2023-03-15 06:19:49 +00:00
|
|
|
if (pRspUrl && strlen(pRspUrl) > 0) {
|
|
|
|
const char *pStrExit = proto_create_new(create_app_process_status(0), 200);
|
|
|
|
inet_http_post_async(config_get_agent_moniter_report_url(), pStrExit, on_http_response_cb, (void *)pStrExit);
|
|
|
|
}
|
2023-01-30 02:43:20 +00:00
|
|
|
|
2022-12-06 03:08:29 +00:00
|
|
|
while (!is_system_cleanup()) {
|
2022-11-07 06:22:12 +00:00
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
2022-05-10 06:43:27 +00:00
|
|
|
user_uninit();
|
2022-11-23 02:41:05 +00:00
|
|
|
|
|
|
|
return ret;
|
2022-09-19 01:53:11 +00:00
|
|
|
#endif
|
2022-05-10 06:43:27 +00:00
|
|
|
}
|