static void parseAnnotation (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) { parsePoem(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) { parseCite(doc, cur, fb); } cur = cur->next; } return; }
static void parseCite (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) { parsePoem(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p") ) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"text-author")) { content = xmlNodeGetContent(cur->children); if (content) { bufferAppend("\t", 1, fb); bufferAppend(content, xmlStrlen(content), fb); bufferAppend("\n", 1, fb); } xmlFree(content); } cur = cur->next; } return; }
static void parseTitle (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { int start; bufferAppend("\n", 1, fb); start = fb->utf8_current_index; cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 0, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } cur = cur->next; } addMark(start, fb->utf8_current_index-1, BOOKMARK_TYPE, NULL, fb); bufferAppend("\n", 1, fb); return; }
static void parsePoem (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) { parseTitle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) { parseEpigraph(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"stanza")) { bufferAppend("\n", 1, fb); parseStanza(doc, cur, fb); } cur = cur->next; } bufferAppend("\n", 1, fb); return; }
// Write some bytes to the specified channel, asynchronously. // DLLEXPORT(FLStatus) flWriteChannelAsync( struct FLContext *handle, uint8 chan, size_t count, const uint8 *data, const char **error) { FLStatus retVal = FL_SUCCESS, fStatus; uint8 command[3]; USBStatus uStatus; CHECK_STATUS( count == 0, FL_PROTOCOL_ERR, cleanup, "flWriteChannelAsync(): Zero-length writes are illegal!"); CHECK_STATUS( !handle->isCommCapable, FL_PROTOCOL_ERR, cleanup, "flWriteChannelAsync(): This device does not support CommFPGA"); command[0] = chan & 0x7F; command[1] = 0x00; command[2] = 0x00; while ( count >= 0x10000 ) { fStatus = bufferAppend(handle, command, 3, error); CHECK_STATUS(fStatus, fStatus, cleanup, "flWriteChannelAsync()"); fStatus = bufferAppend(handle, data, 0x10000, error); CHECK_STATUS(fStatus, fStatus, cleanup, "flWriteChannelAsync()"); count -= 0x10000; data += 0x10000; } if ( count ) { flWriteWord((uint16)count, command+1); fStatus = bufferAppend(handle, command, 3, error); CHECK_STATUS(fStatus, fStatus, cleanup, "flWriteChannelAsync()"); fStatus = bufferAppend(handle, data, count, error); CHECK_STATUS(fStatus, fStatus, cleanup, "flWriteChannelAsync()"); } cleanup: return retVal; }
static void parseStyle (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; xmlChar *prop; int start = fb->utf8_current_index; prop = xmlGetProp(cur, (const xmlChar *)"name"); cur = cur->children; while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) bufferAppend(content, xmlStrlen(content), fb); xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) { parseStyle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, STRONG_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"a")) { parseLink(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) { parseImage(doc, cur, fb); } cur = cur->next; } if (prop && (!xmlStrcmp(prop, (const xmlChar *)"italic"))) { addMark(start, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); xmlFree(prop); } return; }
static void parseBinary (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; xmlChar *prop; if(fb->num_binaries == BUF_SIZE-1) return; /* initialize new binary buffer */ fb->binaries[fb->num_binaries] = (FB2Binary *) malloc(sizeof(FB2Binary)); fb->binaries[fb->num_binaries]->buffer = (char *) malloc(BUF_SIZE); fb->binaries[fb->num_binaries]->buffer_size = BUF_SIZE; fb->binaries[fb->num_binaries+1] = NULL; fb->binaries[fb->num_binaries]->current_index = 0; fb->binaries[fb->num_binaries]->id[0] = '\0'; fb->binaries[fb->num_binaries]->content_type[0] = '\0'; /* id */ prop = xmlGetProp(cur, (const xmlChar *)"id"); if (prop) strncpy(fb->binaries[fb->num_binaries]->id, prop, BUF_SIZE); xmlFree(prop); /* content-type */ prop = xmlGetProp(cur, (const xmlChar *)"content-type"); if (prop) strncpy(fb->binaries[fb->num_binaries]->content_type, prop, BUF_SIZE); xmlFree(prop); cur = cur->children; while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) { bufferAppend(content, xmlStrlen(content), fb); } xmlFree(content); } cur = cur->next; } bufferAppend("\0", 1, fb); fb->num_binaries++; return; }
u32 wsc_supplicant_SerializeHeader(u16 type, u16 len, bufferObj *outBuf) { /* serializes the type and length.*/ u8 temp[sizeof(u32)]; /* Copy the Type */ /*convert a u_short from host to TCP/IP network byte order (which is big-endian).*/ *(u16 *)temp = htons(type); bufferAppend(outBuf, sizeof(u16), temp); /* Copy the Length */ /* convert a u_short from host to TCP/IP network byte order (which is big-endian).*/ *(u16 *)temp = htons(len); bufferAppend(outBuf, sizeof(u16), temp); return OK; }
static u32 wsc_supplicant_BuildProbeRequest(TWscSupplicant* pWscSupplicant, bufferObj *probeReqBuf) { u8 RequestType = 0; /* 0 - Enrollee, Info only, 1 - Enrollee, open 802.1X */ u16 AssociationState = 0; /* 0 - Not Associated */ u16 ConfigurationError = 0; /* 0 - No Error */ /* u8 version */ wsc_supplicant_SerializeField(WSC_ID_VERSION, probeReqBuf, SIZE_VERSION, &(pWscSupplicant->version)); /* u8 RequestType */ wsc_supplicant_SerializeField(WSC_ID_REQ_TYPE, probeReqBuf, SIZE_REQ_TYPE, &RequestType); /* u16 configMethods */ wsc_supplicant_SerializeField(WSC_ID_CONFIG_METHODS, probeReqBuf, SIZE_CONFIG_METHODS, (u8 *)&(pWscSupplicant->configMethods)); /* u8 *uuid ;16B=128 bits */ wsc_supplicant_SerializeField(WSC_ID_UUID_E, probeReqBuf, SIZE_UUID, pWscSupplicant->uuidE); /* sc_device_type_t primaryDeviceType; 8B */ wsc_supplicant_SerializeHeader(WSC_ID_PRIM_DEV_TYPE, SIZE_PRIM_DEV_TYPE, probeReqBuf); bufferAppend(probeReqBuf, SIZE_PRIM_DEV_CAT_ID, (u8 *)&(pWscSupplicant->primaryDeviceType.category_id)); bufferAppend(probeReqBuf, SIZE_PRIM_DEV_OUI, (u8 *)&(pWscSupplicant->primaryDeviceType.oui)); bufferAppend(probeReqBuf, SIZE_PRIM_DEV_SUB_CAT_ID, (u8 *)&(pWscSupplicant->primaryDeviceType.sub_category_id)); /* u8 rfBand */ wsc_supplicant_SerializeField(WSC_ID_RF_BAND, probeReqBuf, SIZE_RF_BAND, &(pWscSupplicant->rfBand)); /* u16 assocState */ wsc_supplicant_SerializeField(WSC_ID_ASSOC_STATE, probeReqBuf, SIZE_ASSOC_STATE, (u8 *)&AssociationState); /* u16 configError */ wsc_supplicant_SerializeField(WSC_ID_CONFIG_ERROR, probeReqBuf, SIZE_CONFIG_ERROR, (u8 *)&ConfigurationError); /* u16 devicePasswordId */ wsc_supplicant_SerializeField(WSC_ID_DEVICE_PWD_ID, probeReqBuf, SIZE_DEVICE_PWD_ID, (u8 *)&(pWscSupplicant->devicePasswordId)); wpa_printf(MSG_INFO,"wsc_supplicant: wsc_supplicant_BuildProbeRequest: built %d byte message", bufferLength(probeReqBuf)); return OK; }
// Read bytes asynchronously from the specified channel (1 <= count <= 0x10000). // DLLEXPORT(FLStatus) flReadChannelAsyncSubmit( struct FLContext *handle, uint8 chan, uint32 count, uint8 *buffer, const char **error) { FLStatus retVal = FL_SUCCESS, fStatus; uint8 command[3]; USBStatus uStatus; size_t queueDepth; const uint16 count16 = (count == 0x10000) ? 0x0000 : (uint16)count; CHECK_STATUS( !handle->isCommCapable, FL_PROTOCOL_ERR, cleanup, "flReadChannelAsyncSubmit(): This device does not support CommFPGA"); CHECK_STATUS( count == 0, FL_PROTOCOL_ERR, cleanup, "flReadChannelAsyncSubmit(): Zero-length reads are illegal!"); CHECK_STATUS( count > 0x10000, FL_PROTOCOL_ERR, cleanup, "flReadChannelAsyncSubmit(): Transfer length exceeds 0x10000"); // Write command command[0] = chan | 0x80; flWriteWord(count16, command+1); fStatus = bufferAppend(handle, command, 3, error); CHECK_STATUS(fStatus, fStatus, cleanup, "flReadChannelAsyncSubmit()"); // Flush outstanding async writes fStatus = flFlushAsyncWrites(handle, error); CHECK_STATUS(fStatus, fStatus, cleanup, "flReadChannelAsyncSubmit()"); // Maybe do a few awaits, to keep things balanced queueDepth = usbNumOutstandingRequests(handle->device); while ( queueDepth > 2 && !handle->completionReport.flags.isRead ) { uStatus = usbBulkAwaitCompletion( handle->device, &handle->completionReport, error ); CHECK_STATUS(uStatus, FL_USB_ERR, cleanup, "flReadChannelAsyncSubmit()"); queueDepth--; } // Then request the data uStatus = usbBulkReadAsync( handle->device, handle->commInEP, // endpoint to read buffer, // pointer to buffer, or null count, // number of data bytes 5000, // max timeout: 49 days error ); CHECK_STATUS(uStatus, FL_USB_ERR, cleanup, "flReadChannelAsyncSubmit()"); cleanup: return retVal; }
static void parseBody (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *prop; prop = xmlGetProp(cur, (const xmlChar *)"name"); if (prop) { int start = fb->utf8_current_index; bufferAppend("\n\n", 2, fb); bufferAppend(prop, xmlStrlen(prop), fb); bufferAppend("\n\n", 2, fb); addMark(start, fb->utf8_current_index, BOOKMARK_TYPE, NULL, fb); xmlFree(prop); } cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"section")) { parseSection(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) { parseTitle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) { parseImage(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) { parseEpigraph(doc, cur, fb); } cur = cur->next; } return; }
static void parseSection (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { FB2Mark *mark; mark = getLink(cur, fb); cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) { parseTitle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"section")) { parseSection(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) { parsePoem(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) { parseCite(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) { parseEpigraph(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"subtitle")) { int start = fb->utf8_current_index; parseP(doc, cur, 0, fb); addMark(start, fb->utf8_current_index, BOOKMARK_TYPE, NULL, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) { parseImage(doc, cur, fb); } cur = cur->next; } if (mark) mark->link_end = fb->text_current_index; return; }
static void parseImage (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *prop; prop = xmlGetProp(cur, (const xmlChar *)"href"); if (prop) { bufferAppend("\n\n", 2, fb); addMark(fb->utf8_current_index-1, fb->utf8_current_index, IMAGE_TYPE, prop, fb); } xmlFree(prop); return; }
u32 wsc_supplicant_SerializeField(u16 type, bufferObj *outBuf, u16 len, u8 *data) { u8 *pos; if((NULL == data) || (0 == len)) { wpa_printf(MSG_ERROR,"wsc_supplicant: wsc_supplicant_SerializeField: serialize error - invalid empty parameter"); return NOK; } /* Copy the Type & Length */ wsc_supplicant_SerializeHeader(type, len, outBuf); /* Copy the Value */ pos = bufferAppend(outBuf, len, data); /* The data has already been stored.*/ /* Now convert it to network byte order as appropriate */ if(len == sizeof(u32)) { u32 Temp32; memcpy(&Temp32, pos, 4); Temp32 = htonl(Temp32); memcpy(pos, &Temp32, 4); } else if(len == sizeof(u16)) { u16 Temp16; memcpy(&Temp16, pos, 2); Temp16 = htons(Temp16); memcpy(pos, &Temp16, 2); } return OK; }
void durotanOnRead(uv_stream_t* client, ssize_t size, const uv_buf_t* buf) { if(size == UV_EOF) { printf("durotan: client disconnected\n"); uv_close((uv_handle_t*) client, durotanOnClose); goto free; } if(size < 0) ERROR("durotan read", size); printf("%s", (char*) buf->base); char* buffer = client->data; char* message; char* m; // Append chunk onto buffer bufferAppend(buffer, buf->base, BUFFER_SIZE - strlen(buffer)); // Read a line, bailing out if it isn't a complete line message = m = bufferGetMessage(buffer, BUFFER_SIZE); if(message == NULL) goto free; // Figure out what kind of message it is int header = bufferGetMessageHeader(&message); // Figure out how many pieces there are int elementCount; switch(header) { case MSG_ITEM: elementCount = 3; break; } // Parse the pieces char** elements = malloc(elementCount * sizeof(char*)); int parsed = bufferSplitMessage(message, elements, elementCount); if(parsed < elementCount) { fprintf(stderr, "durotan received message %d with only %d pieces\n", header, parsed); goto free; } // Handle message switch(header) { case MSG_ITEM: { char* realm = elements[0]; char* faction = elements[1]; int item = atoi(elements[2]); int keyLen = strlen(realm) + 1 + strlen(faction) + 1 + strlen(elements[2]) + 1; itemQuery* query = malloc(sizeof(itemQuery)); query->key = malloc(keyLen * sizeof(char)); snprintf(query->key, keyLen, "%s,%s,%d", realm, faction, item); query->realm = strdup(realm); query->faction = strdup(faction); query->item = item; query->client = client; // Look up the key in redis redisQuery(query, durotanOnRedis); break; } } free(m); free: free(buf->base); }
static void parseTitleInfo (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"genre")) { content = xmlNodeGetContent(cur->children); if(content) { /* add genre */ int i; for (i=0; i<BUF_SIZE-1; i++) { if (fb->genres[i] == NULL) { fb->genres[i] = content; fb->genres[i+1] = NULL; fb->num_genres++; break; } } } } else if (!xmlStrcmp(cur->name, (const xmlChar *)"book-title")) { content = xmlNodeGetContent(cur->children); if (content) strncpy(fb->name, content, BUF_SIZE); xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"author")) { parseAuthor(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"annotation")) { parseAnnotation(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"coverpage")) { xmlNodePtr c; c = cur->children; while (c) { if (!xmlStrcmp(c->name, (const xmlChar *)"image")) { xmlChar *cover_href; cover_href = xmlGetProp(c, (const xmlChar *)"href"); strncpy(fb->cover_href, cover_href, BUF_SIZE); xmlFree (cover_href); break; } c = c->next; } /* content = xmlNodeGetContent(cur->children); if (content) strncpy(fb->cover_href, content, BUF_SIZE); */ //if (cover_href) /*xmlFree(content);*/ } cur = cur->next; } return; }
static void parseP (xmlDocPtr doc, xmlNodePtr cur, int add_tab, FB2Content *fb) { xmlChar *content; FB2Mark *mark; mark = getLink(cur, fb); cur = cur->children; if (add_tab) bufferAppend("\t", 1, fb); while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) { /* int len; len = removeSpaces(content, xmlStrlen(content)); bufferAppend(content, len, fb); */ bufferAppend(content, xmlStrlen(content), fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) { parseStyle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) { content = xmlNodeGetContent(cur->children); if (content) { int start = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(start, fb->utf8_current_index, STRONG_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) { content = xmlNodeGetContent(cur->children); if (content) { int start = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(start, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"a")) { parseLink(doc, cur, fb); } cur = cur->next; } bufferAppend("\n", 1, fb); if (mark) mark->link_end = fb->text_current_index; return; }
static void parseLink (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *content; xmlChar *href_prop, *note_prop; int start = fb->utf8_current_index; /* id */ href_prop = xmlGetProp(cur, (const xmlChar *)"href"); /* type="note" */ note_prop = xmlGetProp(cur, (const xmlChar *)"type"); if (note_prop && (!xmlStrcmp(note_prop, (const xmlChar *)"note"))) bufferAppend("[", 1, fb); cur = cur->children; /*bufferAppend("[", 1, fb);*/ while (cur != NULL) { if (xmlNodeIsText(cur)) { content = xmlNodeGetContent(cur); if (content) bufferAppend(content, xmlStrlen(content), fb); xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"style")) { parseStyle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"strong")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, STRONG_TYPE, NULL, fb); } xmlFree(content); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"emphasis")) { content = xmlNodeGetContent(cur->children); if (content) { int st = fb->utf8_current_index; bufferAppend(content, xmlStrlen(content), fb); addMark(st, fb->utf8_current_index, EMPHASIS_TYPE, NULL, fb); } xmlFree(content); } cur = cur->next; } if (href_prop) { if (note_prop && (!xmlStrcmp(note_prop, (const xmlChar *)"note"))) { bufferAppend("]", 1, fb); addMark(start, fb->utf8_current_index, NOTE_TYPE, href_prop, fb); xmlFree(note_prop); } else { addMark(start, fb->utf8_current_index, LINK_TYPE, href_prop, fb); } xmlFree(href_prop); } return; }
FB2Content * parseFile(char *filename) { xmlDocPtr doc; xmlNodePtr cur; FB2Content *fb; doc = xmlParseFile(filename); if (doc == NULL ) { fprintf(stderr, "Document not parsed successfully. \n"); return NULL; } cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr, "empty document\n"); xmlFreeDoc(doc); return NULL; } if (xmlStrcmp(cur->name, (const xmlChar *) "FictionBook")) { fprintf(stderr, "document of the wrong type, root node != FictionBook\n"); xmlFreeDoc(doc); return NULL; } fb = (FB2Content *) malloc(sizeof(FB2Content)); /* initialize buffers */ fb->text = (char *) malloc(BUF_SIZE); fb->text_buffer_size = BUF_SIZE; fb->text_current_index = 0; fb->utf8_current_index = 0; fb->description = (char *) malloc(BUF_SIZE); fb->description_buffer_size = BUF_SIZE; fb->description_current_index = 0; *fb->author = '\0'; *fb->name = '\0'; *fb->cover_href = '\0'; fb->genres[0] = NULL; fb->num_genres = 0; fb->marks[0] = NULL; fb->num_marks = 0; fb->binaries[0] = NULL; fb->num_binaries = 0; //fb->links[0] = NULL; //fb->num_links = 0; cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"description")) { fb->current_buffer = DESCRIPTION_BUFFER; parseDescription(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"body")) { fb->current_buffer = TEXT_BUFFER; parseBody(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"binary")) { fb->current_buffer = BINARY_BUFFER; parseBinary(doc, cur, fb); } cur = cur->next; } xmlFreeDoc(doc); fb->current_buffer = DESCRIPTION_BUFFER; bufferAppend("\0", 1, fb); fb->current_buffer = TEXT_BUFFER; bufferAppend("\0", 1, fb); return fb; }