//************************************************************************** // Function: printhtml // Scope: global // Purpose: prints in standard output an html // Return: - //************************************************************************** void printhtml(std::string& sDir, int iLanguage) { printHead(iLanguage); printTitle(sDir, iLanguage); printTitleAuthor(iLanguage); std::cout << "</tr>" << std::endl; for (int n = 0; n < vBooks.size(); n++) { // printing std::string sNewFileName=""; replaceName(vBooks[n].sFile, sNewFileName); std::cout << "<tr>" << std::endl << "<td>" << "<A HREF=\"" << "books" << '/' << sDir << '/' << sNewFileName << "\">" << vBooks[n].sFileType << "</A>" << "</td>" << "<td align=" << '"' << "right" << '"' << '>'; std::cout << vBooks[n].st_size/1024; std::cout << "</td>" << "<td>" << vBooks[n].sBook << "</td>" << "<td>" << vBooks[n].sAuthors << "</td>" << std::endl << "</tr>" << std::endl; } std::cout << "</table>" << std::endl; printFoot(); }
int MqttHal_Message_Process(const struct mosquitto_message *message) { char topicType[32]; JSONode *json; char nodeContent[MAX_JSON_NODE_SIZE]; senhub_info_t *pshinfo; int ret = 0; printf("[%s][%s] message=%s\n",__FILE__, __func__, message->payload); if((json = JSON_Parser(message->payload)) == NULL) { printf("json parse err!\n"); return -1; } sscanf(message->topic, "/%*[^/]/%*[^/]/%*[^/]/%s", topicType); ADV_TRACE("Topic type: %s \n", topicType); //printf("Topic type: %s \n", topicType); if(strcmp(topicType, WA_PUB_ACTION_TOPIC) == 0) { //printf("\033[33m #Action Topic# \033[0m\n"); //JSON_Print(json); // Check Publish response about SenHub memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_STATUS_CODE, nodeContent, sizeof(nodeContent)); if(strcmp(nodeContent, "NULL") != 0 /* && session id*/) { //printf("publish response: SenHub\n"); ret = atoi(nodeContent); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_SESSION_ID, nodeContent, sizeof(nodeContent)); //printf("status code:%d, sessionID:%s/%s\n", g_pubResp, g_sessionID, nodeContent); if(strcmp(nodeContent, g_sessionID) == 0) { g_pubResp = ret; } JSON_Destory(&json); return 0; } // Check Publish response about general memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_RESULT_STR, nodeContent, sizeof(nodeContent)); if(strcmp(nodeContent, "SUCCESS") == 0) { //printf("publish response: general\n"); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_SESSION_ID, nodeContent, sizeof(nodeContent)); if(strcmp(nodeContent, g_sessionID) == 0) { g_pubResp = SET_SUCCESS_CODE; } JSON_Destory(&json); return 0; } // Check Publish Data about IoTGW memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_IOTGW_INFO_SPEC, nodeContent, sizeof(nodeContent)); if(strcmp(nodeContent, "NULL") != 0) { //printf("device type: IoTGW\n"); JSON_Destory(&json); return 0; } // Check Publish Data about SensorHub memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_SENHUB_INFO_SPEC, nodeContent, sizeof(nodeContent)); if(strcmp(nodeContent, "NULL") != 0) { // CmdID=2001 //printf("device type: SenHub\n"); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_AGENT_ID, nodeContent, sizeof(nodeContent)); //printf("AgentId : %s\n",nodeContent); pshinfo = (senhub_info_t *)senhub_list_find_by_mac(g_SensorHubList, nodeContent); if(NULL == pshinfo) { JSON_Destory(&json); return -2; } memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_INFO_SPEC, nodeContent, sizeof(nodeContent)); if(pshinfo->jsonNode != NULL) { JSON_Destory(&pshinfo->jsonNode); } replaceName(nodeContent, pshinfo->hostName); pshinfo->jsonNode = JSON_Parser(nodeContent); pshinfo->state = Mote_Report_CMD2001; SensorHub_InfoSpec(pshinfo); } } else if(strcmp(topicType, WA_PUB_DEVINFO_TOPIC) == 0) { //printf("\033[33m #Devinfo Topic# \033[0m\n"); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_IOTGW_DATA, nodeContent, sizeof(nodeContent)); //JSON_Print(json); if(strcmp(nodeContent, "NULL") != 0) { //printf("device type: IoTGW\n"); JSON_Destory(&json); return 0; } memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_SENHUB_DATA, nodeContent, sizeof(nodeContent)); if(strcmp(nodeContent, "NULL") != 0) { // CmdID=2002 //printf("device type: SenHub\n"); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_AGENT_ID, nodeContent, sizeof(nodeContent)); //printf("AgentId : %s\n",nodeContent); pshinfo = (senhub_info_t *)senhub_list_find_by_mac(g_SensorHubList, nodeContent); if(NULL == pshinfo) { JSON_Destory(&json); return -3; } //printf("found id =%d\n", pshinfo->id); #if 0 if(pshinfo->state == Mote_Report_CMD2000) { //printf("%s: !!! id=%d state=%d, no report 2001 xxxxxxxxxxxxxx\n", __func__, pshinfo->id, pshinfo->state); g_doUpdateInterface = 1; SensorHub_DisConn(pshinfo); g_SensorHubList = SENHUB_LIST_RM(g_SensorHubList, pshinfo->id, &pshinfo); free(pshinfo); } else #endif { memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DATA, nodeContent, sizeof(nodeContent)); if(pshinfo->jsonNode != NULL) { JSON_Destory(&pshinfo->jsonNode); } pshinfo->jsonNode = JSON_Parser(nodeContent); pshinfo->state = Mote_Report_CMD2002; SensorHub_Data(pshinfo); } } } else if(strcmp(topicType, WA_PUB_CONNECT_TOPIC) == 0) { //printf("\033[33m #Connect Topic# \033[0m\n"); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DEVICE_TYPE, nodeContent, sizeof(nodeContent)); //printf("device type : %s\n",nodeContent); //JSON_Print(json); if(strcmp(nodeContent, "IoTGW") == 0) { char macAddr[MAX_MACADDRESS_LEN]; memset(macAddr, 0, MAX_MACADDRESS_LEN); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DEVICE_MAC, nodeContent, sizeof(nodeContent)); sprintf(macAddr, "0017%s", nodeContent); //printf("%s: mac=%s -> %s\n", __func__, nodeContent, macAddr); pshinfo = (senhub_info_t *)senhub_list_find_by_mac(g_SensorHubList, macAddr); if(NULL != pshinfo) { g_doUpdateInterface = 1; SensorHub_DisConn(pshinfo); } else { pshinfo = malloc(sizeof(senhub_info_t)); memset(pshinfo, 0, sizeof(senhub_info_t)); strcpy(pshinfo->macAddress, macAddr); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DEVICE_HOSTNAME, nodeContent, sizeof(nodeContent)); //printf("hostname: %s\n", nodeContent); strcpy(pshinfo->hostName, nodeContent); pshinfo->jsonNode = NULL; pshinfo->id = senhub_list_newId(g_SensorHubList); //printf("%s: list add id=%d\n", __func__, pshinfo->id); g_SensorHubList = SENHUB_LIST_ADD(g_SensorHubList, pshinfo); } } else if(strcmp(nodeContent, "SenHub") == 0) { g_doUpdateInterface = 1; // CmdID=2000 memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DEVICE_MAC, nodeContent, sizeof(nodeContent)); //printf("%s: mac=%s\n", __func__, nodeContent); pshinfo = (senhub_info_t *)senhub_list_find_by_mac(g_SensorHubList, nodeContent); if(pshinfo) { memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DEVICE_PRODUCTNAME, nodeContent, sizeof(nodeContent)); //printf("productName: %s\n", nodeContent); strcpy(pshinfo->productName, nodeContent); pshinfo->state = Mote_Report_CMD2000; SensorHub_Register(pshinfo); } } } else if(strcmp(topicType, WA_PUB_WILL_TOPIC) == 0) { // CmdID=2003 //ADV_TRACE("%s: Receive messages from will topic!!\n", __func__); char macAddr[MAX_MACADDRESS_LEN]; //JSON_Print(json); memset(nodeContent, 0, MAX_JSON_NODE_SIZE); JSON_Get(json, OBJ_DEVICE_MAC, nodeContent, sizeof(nodeContent)); memset(macAddr, 0, MAX_MACADDRESS_LEN); sprintf(macAddr, "0017%s" , nodeContent); //printf("%s: mac=%s!!\n", __func__, macAddr); pshinfo = (senhub_info_t *)senhub_list_find_by_mac(g_SensorHubList, macAddr); if(NULL != pshinfo) { g_doUpdateInterface = 1; SensorHub_DisConn(pshinfo); //printf("%s: id=%d!!\n", __func__, pshinfo->id); g_SensorHubList = SENHUB_LIST_RM(g_SensorHubList, pshinfo->id, &pshinfo); free(pshinfo); } } // CmdID=1000 if(g_doUpdateInterface) { GatewayIntf_Update(); g_doUpdateInterface = 0; } JSON_Destory(&json); return 0; }