2019-11-19 07:39:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
2019-11-21 02:53:27 +00:00
|
|
|
#include "ztp_config.h"
|
2019-11-19 07:39:21 +00:00
|
|
|
#include "restful.h"
|
|
|
|
#include "json_interface.h"
|
|
|
|
#include "err_code.h"
|
|
|
|
|
2019-11-21 02:53:27 +00:00
|
|
|
#define ZTP_ESN ("ace08484843")
|
|
|
|
#define ZTP_VERSION ("0.1")
|
2019-11-19 07:39:21 +00:00
|
|
|
|
2019-11-21 03:23:04 +00:00
|
|
|
void __onPost(void *pData, unsigned int size, const char *pReqUrl,
|
|
|
|
const char *pDlPath, const char *pTaskUuid, int iFinished, void *pUserData)
|
2019-11-19 07:39:21 +00:00
|
|
|
{
|
2019-12-02 07:30:51 +00:00
|
|
|
int ret = ERR_OK;
|
|
|
|
PAUTH_ZTH_RSP pZTPRsp;
|
|
|
|
|
2019-11-20 07:12:15 +00:00
|
|
|
UNUSED(size);
|
|
|
|
UNUSED(pReqUrl);
|
|
|
|
UNUSED(pDlPath);
|
|
|
|
UNUSED(pTaskUuid);
|
|
|
|
UNUSED(iFinished);
|
|
|
|
UNUSED(pUserData);
|
|
|
|
|
2019-12-02 01:55:46 +00:00
|
|
|
LOG_EX(LOG_Info, "Post URL: [%s]\n", pReqUrl);
|
|
|
|
|
|
|
|
if(pUserData && strlen(pUserData) > 0) {
|
|
|
|
LOG_EX(LOG_Info, "Post Data: [%s]\n", pUserData);
|
|
|
|
}
|
|
|
|
LOG_EX(LOG_Info, "Post Result: [%s]\n", (char *)pData);
|
2019-12-02 07:30:51 +00:00
|
|
|
|
|
|
|
ret = Json2Struct(pData, &pZTPRsp, JE_AUTH_ZTP, FALSE);
|
|
|
|
|
|
|
|
if(ret == ERR_OK && pZTPRsp) {
|
|
|
|
if(strcasecmp(pZTPRsp->status, "SUCCESS") == 0) {
|
|
|
|
LOG_EX(LOG_Debug, "Request OK\n");
|
|
|
|
} else {
|
|
|
|
LOG_EX(LOG_Error, "Request Error\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG_EX(LOG_Error, "Decode JSON error: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pZTPRsp) {
|
|
|
|
if(pZTPRsp->status) {
|
|
|
|
free(pZTPRsp->status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pZTPRsp->code) {
|
|
|
|
free(pZTPRsp->code);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pZTPRsp->ip) {
|
|
|
|
free(pZTPRsp->ip);
|
|
|
|
}
|
|
|
|
free(pZTPRsp);
|
|
|
|
}
|
2019-11-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 03:23:04 +00:00
|
|
|
int main(int argc, char **argv)
|
2019-11-19 07:39:21 +00:00
|
|
|
{
|
|
|
|
int ret = ERR_OK;
|
2019-11-21 03:23:04 +00:00
|
|
|
const char *pJson;
|
2019-11-19 07:39:21 +00:00
|
|
|
AUTH_ZTH_REQ ztpReq;
|
|
|
|
|
|
|
|
IHW_InitLOG("ZTP", NULL, TRUE);
|
2019-11-21 02:53:27 +00:00
|
|
|
APP_BUILD_INFO("ZTP", ZTP_VERSION);
|
2019-11-19 07:39:21 +00:00
|
|
|
|
|
|
|
init_configure(DEVICE_ZTP_PATH);
|
|
|
|
|
|
|
|
memset(&ztpReq, 0, sizeof(AUTH_ZTH_REQ));
|
2019-12-02 07:30:51 +00:00
|
|
|
ztpReq.pESN = "tt21";//ZTP_ESN;
|
2019-11-19 07:39:21 +00:00
|
|
|
|
|
|
|
pJson = Struct2Json(&ztpReq, JE_AUTH_ZTP, FALSE, &ret);
|
|
|
|
|
|
|
|
if(pJson && ret == ERR_OK) {
|
2019-12-02 07:30:51 +00:00
|
|
|
//http_post_request_async("https://xajhuang.com:3006/post", pJson, __onPost);
|
|
|
|
http_post_request_async("http://172.28.73.43:8088/device/esn", pJson, __onPost);
|
2019-11-19 07:39:21 +00:00
|
|
|
} else {
|
|
|
|
LOG_EX(LOG_Error, "Create JSON error: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pJson) {
|
2019-11-21 03:23:04 +00:00
|
|
|
free((void *)pJson);
|
2019-11-19 07:39:21 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 07:12:15 +00:00
|
|
|
load_dev_config(ZTP_ESN);
|
|
|
|
|
2019-11-21 03:19:07 +00:00
|
|
|
#ifdef MONITOR_ZTP_CFG_FILE
|
2019-11-21 10:42:55 +00:00
|
|
|
|
|
|
|
while(ret == ERR_OK) {
|
2019-11-21 03:19:07 +00:00
|
|
|
usleep(1000);
|
|
|
|
}
|
2019-11-21 10:42:55 +00:00
|
|
|
|
2019-11-21 03:19:07 +00:00
|
|
|
#endif
|
2019-11-19 07:39:21 +00:00
|
|
|
|
|
|
|
IHW_WaitFinishLogout();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|