int exportDatabase( const char * filename, struct database_t * databaseList, int * databaseListTotal, struct userAttr_t * userAttr ){ int subscript; char longStr[100000]; char message[500]; xmlNodePtr node; xmlNodePtr content; xmlNodePtr sonNode; xmlNodePtr grandsonNode; // create the doc and root node xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" ); xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST "databaseList" ); xitoa( longStr, *databaseListTotal); xmlNewProp( root_node, BAD_CAST "databaseListTotal", BAD_CAST longStr ); if ( userAttr->userStatus == NULL ) xmlNewProp( root_node, BAD_CAST "userStatus", BAD_CAST "disable" ); else xmlNewProp( root_node, BAD_CAST "userStatus", BAD_CAST userAttr->userStatus ); if ( userAttr->mobileNumber != NULL ) xmlNewProp( root_node, BAD_CAST "userStatus", BAD_CAST userAttr->mobileNumber ); // set the root node xmlDocSetRootElement( doc, root_node ); // if ( *xmlItemListAlarmTotal > *xmlItemListTotal ) *xmlItemListAlarmTotal = *xmlItemListTotal; for (subscript=1; subscript <= *databaseListTotal; subscript++){ node = xmlNewNode( NULL, BAD_CAST "item" ); xmlAddChild( root_node, node ); // xitoa( longStr, subscript ); // xmlNewProp( node, BAD_CAST "subscript", BAD_CAST longStr ); sonNode = xmlNewNode( NULL, BAD_CAST "url" ); content = xmlNewCDataBlock( NULL, BAD_CAST databaseList[subscript].url, strlen(databaseList[subscript].url) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); sonNode = xmlNewNode( NULL, BAD_CAST "urlstatus" ); content = xmlNewCDataBlock( NULL, BAD_CAST databaseList[subscript].urlstatus, strlen(databaseList[subscript].urlstatus) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); sonNode = xmlNewNode( NULL, BAD_CAST "filenamePrefix" ); content = xmlNewCDataBlock( NULL, BAD_CAST databaseList[subscript].filenamePrefix, strlen(databaseList[subscript].filenamePrefix) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } int nRel = xmlSaveFormatFileEnc( filename, doc, "UTF-8", 1); /*if (nRel != -1) printf(" created, %d bytes.\n", nRel);*/ xmlFreeDoc(doc); if (nRel != -1) return 1; else return 0; }
void httpHeaderPutInt(HttpHeader * hdr, http_hdr_type id, int number) { assert_eid(id); assert(Headers[id].type == ftInt); /* must be of an appropriate type */ assert(number >= 0); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(id, NULL, xitoa(number))); }
std::string CoolingFan::getPartInformation() const { char speed[5]; xitoa(m_fanSpeed, speed, 10); std::string partInformation("Cooling Fan: " + m_name + ", Speed: " + speed + " RPM"); return partInformation; }
std::string HardDiscDrive::getPartInformation() const { std::string partInformation = this->HardDrive::getPartInformation(); char spinSpeed[5]; xitoa(m_spinSpeed, spinSpeed, 10); partInformation += ", " + std::string(spinSpeed) + " RPM"; return partInformation; }
int exportXmlItemFileForAlarm( const char * filename, struct xmlItemAlarm_t * xmlItemAlarmList, int * xmlItemListAlarmTotal ) { int subscript; char longStr[100000]; char message[500]; xmlNodePtr node; xmlNodePtr content; xmlNodePtr sonNode; xmlNodePtr grandsonNode; // create the doc and root node xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" ); xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST "xmlItemListAlarm" ); xitoa( longStr, *xmlItemListAlarmTotal); xmlNewProp( root_node, BAD_CAST "xmlItemListAlarmTotal", BAD_CAST longStr ); // set the root node xmlDocSetRootElement( doc, root_node ); // if ( *xmlItemListAlarmTotal > *xmlItemListTotal ) *xmlItemListAlarmTotal = *xmlItemListTotal; for (subscript=1; subscript <= *xmlItemListAlarmTotal; subscript++) { node = xmlNewNode( NULL, BAD_CAST "item" ); xmlAddChild( root_node, node ); // xitoa( longStr, subscript ); // xmlNewProp( node, BAD_CAST "subscript", BAD_CAST longStr ); sonNode = xmlNewNode( NULL, BAD_CAST "message" ); // content = xmlNewCDataBlock( NULL, BAD_CAST longStr, strlen(longStr) ); // printf( "%s",longStr ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlItemAlarmList[subscript].message, strlen(xmlItemAlarmList[subscript].message) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } int nRel = xmlSaveFormatFileEnc( filename, doc, "UTF-8", 1); /*if (nRel != -1) printf(" created, %d bytes.\n", nRel);*/ xmlFreeDoc(doc); if (nRel != -1) return 1; else return 0; }
/* * Given a pid, return the read end of a pipe returning the output from the * trace program (strace or dtruss). */ int trace_open(pid_t pid) { int pipefd[2], pipe_r, pipe_w; int trace_pid; char *cpid; cpid = xitoa((int)pid); if (pipe(pipefd) == -1) err(1, "trace_open:pipe()"); pipe_r = pipefd[0]; pipe_w = pipefd[1]; trace_pid = fork(); if (trace_pid == -1) { err(1, "trace_open:fork()"); } else if (trace_pid == 0) { if (dup2(pipe_w, STDERR_FILENO) == -1) err(1, "trace_open:dup2(pipe_w, stderr)"); if (close(pipe_r) == -1) err(1, "trace_open:close(pipe_r)"); if (use_dtruss) { trace_spawn_dtruss(cpid); } else { trace_spawn_strace(cpid); } } if (close(pipe_w) == -1) err(1, "trace_open:close(pipe_w)"); return pipe_r; }
int exportXmlItemFile( const char * filename, struct xmlItem_t * xmlItemList, int * xmlItemListTotal ){ int subscript; int attrSubscript; char longStr[100000]; xmlNodePtr node; xmlNodePtr content; xmlNodePtr sonNode; xmlNodePtr grandsonNode; // create the doc and root node xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" ); xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST "xmlItemList" ); xitoa( longStr, *xmlItemListTotal ); xmlNewProp( root_node, BAD_CAST "xmlItemListTotal", BAD_CAST longStr ); // set the root node xmlDocSetRootElement( doc, root_node ); if ( *xmlItemListTotal > MAX_ITEMLIST_SAVE ) *xmlItemListTotal = MAX_ITEMLIST_SAVE; for (subscript=1; subscript <= *xmlItemListTotal; subscript++){ node = xmlNewNode( NULL, BAD_CAST "item" ); xmlAddChild( root_node, node ); // xitoa( longStr, subscript ); // xmlNewProp( node, BAD_CAST "subscript", BAD_CAST longStr ); if ( xmlItemList[subscript].text[FRSS_ITEM_TITLE] != NULL ){ sonNode = xmlNewNode( NULL, BAD_CAST "title" ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlItemList[subscript].text[FRSS_ITEM_TITLE], strlen(xmlItemList[subscript].text[FRSS_ITEM_TITLE]) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } if ( xmlItemList[subscript].text[FRSS_ITEM_TIME] != NULL ){ sonNode = xmlNewNode( NULL, BAD_CAST "time" ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlItemList[subscript].text[FRSS_ITEM_TIME], strlen(xmlItemList[subscript].text[FRSS_ITEM_TIME]) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } if ( xmlItemList[subscript].text[FRSS_ITEM_CONTENT] != NULL ){ sonNode = xmlNewNode( NULL, BAD_CAST "content" ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlItemList[subscript].text[FRSS_ITEM_CONTENT], strlen(xmlItemList[subscript].text[FRSS_ITEM_CONTENT]) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } if ( xmlItemList[subscript].richText[FRSS_ITEM_CONTENT] != NULL ){ sonNode = xmlNewNode( NULL, BAD_CAST "content:encoded" ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlItemList[subscript].richText[FRSS_ITEM_CONTENT], strlen(xmlItemList[subscript].richText[FRSS_ITEM_CONTENT]) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } if ( xmlItemList[subscript].text[FRSS_ITEM_GUID] != NULL ){ sonNode = xmlNewNode( NULL, BAD_CAST "guid" ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlItemList[subscript].text[FRSS_ITEM_GUID], strlen(xmlItemList[subscript].text[FRSS_ITEM_GUID]) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } } int nRel = xmlSaveFormatFileEnc( filename, doc, "UTF-8", 1); /*if (nRel != -1) printf(" created, %d bytes.\n", nRel);*/ xmlFreeDoc(doc); if (nRel != -1) return 1; else return 0; }
int exportRuleFile( const char * filename, struct xmlDesc_t * xmlDesc ){ int subscript; int subscriptCount; int attrSubscript; char longStr[100000]; char * str; xmlNodePtr node; xmlNodePtr content; xmlNodePtr sonNode; xmlNodePtr grandsonNode; int strType; char title; char attrTitle[100]; char attrValue[100]; int attrTotal; int parent; int tail; // create the doc and root node xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" ); xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST "xmlItemDesc" ); xmlNewProp( root_node, BAD_CAST "flag", BAD_CAST "standard"); // set the root node xmlDocSetRootElement( doc, root_node ); for (subscriptCount=1; subscriptCount <= 4; subscriptCount++){ if (subscriptCount == 1) subscript = XML_ITEM_REGION; else if (subscriptCount == 2 ) subscript = XML_ITEM_TITLE; else if (subscriptCount == 3 ) subscript = XML_ITEM_TIME; else if (subscriptCount == 4 ) subscript = XML_ITEM_CONTENT; if ( xmlDesc[subscript].title == NULL && xmlDesc[subscript].attrTotal <= 0 ) continue; if ( subscript == XML_ITEM_REGION ) node = xmlNewNode( NULL, BAD_CAST "region" ); else if ( subscript == XML_ITEM_TITLE) node = xmlNewNode( NULL, BAD_CAST "title" ); else if ( subscript == XML_ITEM_TIME ) node = xmlNewNode( NULL, BAD_CAST "time" ); else if ( subscript == XML_ITEM_CONTENT ) node = xmlNewNode( NULL, BAD_CAST "content" ); xmlAddChild( root_node, node ); // xitoa( longStr, subscript ); // xmlNewProp( node, BAD_CAST "subscript", BAD_CAST longStr ); // xitoa( longStr, itemList[subscript].type ); // sonNode = xmlNewNode( NULL, BAD_CAST "type" ); // content = xmlNewText( BAD_CAST longStr ); // xmlAddChild( sonNode, content ); // xmlAddChild( node, sonNode ); if ( xmlDesc[subscript].title != NULL ){ sonNode = xmlNewNode( NULL, BAD_CAST "title" ); // strcpy( longStr, itemList[subscript].title ); // pushCDATA( longStr ); content = xmlNewCDataBlock( NULL, BAD_CAST xmlDesc[subscript].title, strlen(xmlDesc[subscript].title) ); // content = xmlNewText( BAD_CAST itemList[subscript].attrValue[attrSubscript]); // str= (char *)xmlNodeGetContent( content); // printf("%d:%d[%s]%s\n",subscript, strlen(xmlDesc[subscript].title), xmlDesc[subscript].title,str); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } if ( xmlDesc[subscript].attrTotal > 0){ sonNode = xmlNewNode( NULL, BAD_CAST "attr" ); xitoa( longStr, xmlDesc[subscript].attrTotal ); xmlNewProp( sonNode, BAD_CAST "attrTotal", BAD_CAST longStr); xmlAddChild( node, sonNode ); for ( attrSubscript=0; attrSubscript < xmlDesc[subscript].attrTotal; attrSubscript++){ xitoa( longStr, attrSubscript ); grandsonNode = xmlNewNode( NULL, BAD_CAST "attrTitle"); xmlNewProp( grandsonNode, BAD_CAST "attrSubscript", BAD_CAST longStr ); content = xmlNewText( BAD_CAST xmlDesc[subscript].attrTitle[attrSubscript]); xmlAddChild( grandsonNode, content ); xmlAddChild( sonNode, grandsonNode ); grandsonNode = xmlNewNode( NULL, BAD_CAST "attrValue"); xmlNewProp( grandsonNode, BAD_CAST "attrSubscript", BAD_CAST longStr ); content = xmlNewText( BAD_CAST xmlDesc[subscript].attrValue[attrSubscript]); xmlAddChild( grandsonNode, content ); xmlAddChild( sonNode, grandsonNode ); } } } int nRel = xmlSaveFormatFileEnc( filename, doc, "UTF-8", 1); /*if (nRel != -1) printf(" created, %d bytes.\n", nRel);*/ xmlFreeDoc(doc); if (nRel != -1) return 1; else return 0; }
int exportXmlDom( const char * filename, struct itemnode_t * itemList, int * itemListTotal){ int subscript; int attrSubscript; char longStr[100000]; xmlNodePtr node; xmlNodePtr content; xmlNodePtr sonNode; xmlNodePtr grandsonNode; int strType; char title; char attrTitle[100]; char attrValue[100]; int attrTotal; int parent; int tail; // create the doc and root node xmlDocPtr doc = xmlNewDoc( BAD_CAST "1.0" ); xmlNodePtr root_node = xmlNewNode( NULL, BAD_CAST "xmlDomList" ); xitoa( longStr, *itemListTotal); xmlNewProp( root_node, BAD_CAST "itemListTotal", BAD_CAST longStr ); // set the root node xmlDocSetRootElement( doc, root_node ); for (subscript=1; subscript <= *itemListTotal; subscript++){ node = xmlNewNode( NULL, BAD_CAST "item" ); xmlAddChild( root_node, node ); xitoa( longStr, subscript ); xmlNewProp( node, BAD_CAST "subscript", BAD_CAST longStr ); xitoa( longStr, itemList[subscript].type ); sonNode = xmlNewNode( NULL, BAD_CAST "type" ); content = xmlNewText( BAD_CAST longStr ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); sonNode = xmlNewNode( NULL, BAD_CAST "title" ); // strcpy( longStr, itemList[subscript].title ); // pushCDATA( longStr ); content = xmlNewCDataBlock( NULL, BAD_CAST itemList[subscript].title, strlen(itemList[subscript].title) ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); sonNode = xmlNewNode( NULL, BAD_CAST "attr" ); xitoa( longStr, itemList[subscript].attrTotal ); xmlNewProp( sonNode, BAD_CAST "attrTotal", BAD_CAST longStr); xmlAddChild( node, sonNode ); for ( attrSubscript=0; attrSubscript < itemList[subscript].attrTotal; attrSubscript++){ xitoa( longStr, attrSubscript ); grandsonNode = xmlNewNode( NULL, BAD_CAST "attrTitle"); xmlNewProp( grandsonNode, BAD_CAST "attrSubscript", BAD_CAST longStr ); content = xmlNewText( BAD_CAST itemList[subscript].attrTitle[attrSubscript]); xmlAddChild( grandsonNode, content ); xmlAddChild( sonNode, grandsonNode ); grandsonNode = xmlNewNode( NULL, BAD_CAST "attrValue"); xmlNewProp( grandsonNode, BAD_CAST "attrSubscript", BAD_CAST longStr ); content = xmlNewText( BAD_CAST itemList[subscript].attrValue[attrSubscript]); xmlAddChild( grandsonNode, content ); xmlAddChild( sonNode, grandsonNode ); } xitoa( longStr, itemList[subscript].parent ); sonNode = xmlNewNode( NULL, BAD_CAST "parent" ); content = xmlNewText( BAD_CAST longStr ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); xitoa( longStr, itemList[subscript].tail ); sonNode = xmlNewNode( NULL, BAD_CAST "tail" ); content = xmlNewText( BAD_CAST longStr ); xmlAddChild( sonNode, content ); xmlAddChild( node, sonNode ); } int nRel = xmlSaveFormatFileEnc( filename, doc, "UTF-8", 1); /*if (nRel != -1) printf(" created, %d bytes.\n", nRel);*/ xmlFreeDoc(doc); if (nRel != -1) return 1; else return 0; }