ztp/ztp_main.c

63 lines
1.3 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <unistd.h>
#include "log.h"
#include "ztp_config.h"
#include "restful.h"
#include "json_interface.h"
#include "err_code.h"
#define ZTP_ESN ("ace08484843")
#define ZTP_VERSION ("0.1")
void __onPost(void* pData, unsigned int size, const char* pReqUrl,
const char* pDlPath, const char* pTaskUuid, int iFinished, void* pUserData)
{
UNUSED(size);
UNUSED(pReqUrl);
UNUSED(pDlPath);
UNUSED(pTaskUuid);
UNUSED(iFinished);
UNUSED(pUserData);
LOG_EX(LOG_Info, "Post Result: %s\n", (char*)pData);
}
int main(int argc, char** argv)
{
int ret = ERR_OK;
const char* pJson;
AUTH_ZTH_REQ ztpReq;
IHW_InitLOG("ZTP", NULL, TRUE);
APP_BUILD_INFO("ZTP", ZTP_VERSION);
init_configure(DEVICE_ZTP_PATH);
memset(&ztpReq, 0, sizeof(AUTH_ZTH_REQ));
ztpReq.pESN = ZTP_ESN;
pJson = Struct2Json(&ztpReq, JE_AUTH_ZTP, FALSE, &ret);
if(pJson && ret == ERR_OK) {
http_post_request("https://xajhuang.com:3006/post", pJson, __onPost);
} else {
LOG_EX(LOG_Error, "Create JSON error: %d\n", ret);
}
if(pJson) {
free((void*)pJson);
}
load_dev_config(ZTP_ESN);
#ifdef MONITOR_ZTP_CFG_FILE
while(ret == ERR_OK){
usleep(1000);
}
#endif
IHW_WaitFinishLogout();
return 0;
}