static void pextsElementDecl(void *ctx, const xmlChar *name, int type, xmlElementContentPtr content) { struct mapping *cmap; DBG_FUNC_ENTER(); if (CB_ABSENT(elementDeclSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); push_int(type); cmap = tree2mapping(content); if (cmap) push_mapping(cmap); else push_int(0); push_svalue(&THIS->user_data); CB_CALL(elementDeclSAX, 5); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsFatalError(void *ctx, const char *msg, ...) { char *vmsg; va_list ap; DBG_FUNC_ENTER(); if (CB_ABSENT(fatalErrorSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); /* I'm being lazy here :> */ vmsg = NULL; va_start(ap, msg); if (vasprintf(&vmsg, msg, ap) < -1) push_int(0); else { push_text(vmsg); free(vmsg); } push_svalue(&THIS->user_data); CB_CALL(fatalErrorSAX, 3); pop_stack(); DBG_FUNC_LEAVE(); }
/* TODO: this one needs more thought... */ static xmlEntityPtr pextsGetEntity(void *ctx, const xmlChar *name) { DBG_FUNC_ENTER(); if (CB_ABSENT(getEntitySAX)) { DBG_FUNC_LEAVE(); return NULL; } DBG_FUNC_LEAVE(); return xmlGetPredefinedEntity(name); return NULL; }
/* TODO: this one needs more thought... */ static xmlEntityPtr pextsGetParameterEntity(void *ctx, const xmlChar *name) { DBG_FUNC_ENTER(); if (CB_ABSENT(getParameterEntitySAX)) { DBG_FUNC_LEAVE(); return NULL; } THIS->ctxt = (xmlParserCtxtPtr)ctx; DBG_FUNC_LEAVE(); return NULL; }
static void pextsEndDocument(void *ctx) { DBG_FUNC_ENTER(); if (CB_ABSENT(endDocumentSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); push_svalue(&THIS->user_data); CB_CALL(endDocumentSAX, 2); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsComment(void *ctx, const xmlChar *value) { DBG_FUNC_ENTER(); if (CB_ABSENT(commentSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(value); push_svalue(&THIS->user_data); CB_CALL(commentSAX, 3); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsProcessingInstruction(void *ctx, const xmlChar *target, const xmlChar *data) { DBG_FUNC_ENTER(); if (CB_ABSENT(processingInstructionSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(target); safe_push_text(data); push_svalue(&THIS->user_data); CB_CALL(processingInstructionSAX, 4); pop_stack(); DBG_FUNC_LEAVE(); }
static int pextsHasExternalSubset(void *ctx) { struct svalue sv; DBG_FUNC_ENTER(); if (CB_ABSENT(hasExternalSubsetSAX)) { DBG_FUNC_LEAVE(); return 0; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); push_svalue(&THIS->user_data); CB_CALL(hasExternalSubsetSAX, 2); stack_pop_to(&sv); DBG_FUNC_LEAVE(); return sv.u.integer; }
static void pextsExternalSubset(void *ctx, const xmlChar *name, const xmlChar *externalId, const xmlChar *systemId) { DBG_FUNC_ENTER(); if (CB_ABSENT(externalSubsetSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); safe_push_text(externalId); safe_push_text(systemId); push_svalue(&THIS->user_data); CB_CALL(externalSubsetSAX, 5); pop_stack(); DBG_FUNC_LEAVE(); }
static int pextsIsStandalone(void *ctx) { struct svalue sv; DBG_FUNC_ENTER(); if (CB_ABSENT(isStandaloneSAX)) { DBG_FUNC_LEAVE(); return 1; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); push_svalue(&THIS->user_data); CB_CALL(isStandaloneSAX, 2); stack_pop_to(&sv); DBG_FUNC_LEAVE(); return sv.u.integer; }
static void pextsAttributeDecl(void *ctx, const xmlChar *elem, const xmlChar *fullname, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree) { int nenum; DBG_FUNC_ENTER(); if (CB_ABSENT(attributeDeclSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(elem); safe_push_text(fullname); push_int(type); push_int(def); safe_push_text(defaultValue); push_svalue(&THIS->user_data); if (tree) { xmlEnumerationPtr tmp = tree; struct array *arr; nenum = 0; while (tree) { safe_push_text(tmp->name); tmp = tmp->next; nenum++; } arr = aggregate_array(nenum); push_array(arr); } else push_int(0); CB_CALL(attributeDeclSAX, 8); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsCdataBlock(void *ctx, const xmlChar *value, int len) { DBG_FUNC_ENTER(); if (CB_ABSENT(cdataBlockSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); if (value) push_string(make_shared_binary_string((const char*)value, (size_t) len)); else push_int(0); push_svalue(&THIS->user_data); CB_CALL(cdataBlockSAX, 3); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsIgnorableWhitespace(void *ctx, const xmlChar *ch, int len) { DBG_FUNC_ENTER(); if (CB_ABSENT(ignorableWhitespaceSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); if (ch && len) push_string(make_shared_binary_string((const char*)ch, (size_t) len)); else push_int(0); push_svalue(&THIS->user_data); CB_CALL(ignorableWhitespaceSAX, 3); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsNotationDecl(void *ctx, const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId) { DBG_FUNC_ENTER(); if (CB_ABSENT(notationDeclSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); safe_push_text(publicId); safe_push_text(systemId); push_svalue(&THIS->user_data); CB_CALL(notationDeclSAX, 5); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsEntityDecl(void *ctx, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) { DBG_FUNC_ENTER(); if (CB_ABSENT(entityDeclSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); push_int(type); safe_push_text(publicId); safe_push_text(systemId); safe_push_text(content); push_svalue(&THIS->user_data); CB_CALL(entityDeclSAX, 7); pop_stack(); DBG_FUNC_LEAVE(); }
static void pextsStartElement(void *ctx, const xmlChar *name, const xmlChar **atts) { int npairs; const xmlChar **tmp; DBG_FUNC_ENTER(); if (CB_ABSENT(startElementSAX)) { DBG_FUNC_LEAVE(); return; } THIS->ctxt = (xmlParserCtxtPtr)ctx; push_object(this_object()); safe_push_text(name); if (atts) { npairs = 0; tmp = atts; while (tmp && *tmp) { safe_push_text(*tmp); tmp++; safe_push_text(*tmp); tmp++; npairs += 2; } f_aggregate_mapping(npairs); } else { push_int(0); } push_svalue(&THIS->user_data); CB_CALL(startElementSAX, 4); pop_stack(); DBG_FUNC_LEAVE(); }
void response_split_task(void * arg) { client_info_t * client = arg; DBG_FUNC_ENTER(); DBG_VERBOSE("%s: client: %p\n", __FUNCTION__, client); /* variables for handling response split */ char temp[1024]; uint32_t temp_len = 0; read_stages_t stage = HEADER_LEN_READ; uint32_t payload_offset = 0; response_t * resp = NULL; uint32_t rem_size = 0; txn_buf_t * cur_buf = NULL; while (1) { if (cur_buf != NULL) { DBG_ALLOC("%s: FREE cur_buf->buf: %p cur_buf: %p\n", __FUNCTION__, cur_buf->buf, cur_buf); free(cur_buf->buf); free(cur_buf); cur_buf = NULL; } cur_buf = (txn_buf_t *)queue_pop(client->buf_q); DBG_VERBOSE("%s: buf: %p len: %ld offset: %ld\n", __FUNCTION__, cur_buf->buf, cur_buf->len, cur_buf->offset); /* write a response split using fixed len */ rem_size = cur_buf->len - cur_buf->offset; DBG_VERBOSE("rem_size: %u\n", rem_size); while ((temp_len > 0) && (rem_size > 0)) { switch(stage) { case HEADER_LEN_READ: { uint32_t hdr_len = 0; if ((rem_size + temp_len) < HEADER_SIZE) { memcpy(temp + temp_len, cur_buf->buf + cur_buf->offset, rem_size); temp_len += rem_size; rem_size = 0; } else { resp = malloc(sizeof(response_t)); assert(resp != NULL); DBG_ALLOC("%s: ALLOC request: %p\n", __FUNCTION__, resp); resp->buf = NULL; if (temp_len < HEADER_SIZE) { memcpy((uint8_t *)&hdr_len, temp, temp_len); memcpy(((uint8_t *)&hdr_len) + temp_len, cur_buf->buf + cur_buf->offset, HEADER_SIZE - temp_len); DBG_VERBOSE("HEADER length: %u\n", hdr_len); temp_len = 0; rem_size -= HEADER_SIZE + temp_len; } else { memcpy((uint8_t *)&hdr_len, temp, HEADER_SIZE); temp_len -= HEADER_SIZE; } resp->header_len = hdr_len; stage = HEADER_READ; } break; } case HEADER_READ: { if ((rem_size + temp_len) < resp->header_len) { memcpy(temp + temp_len, cur_buf->buf + cur_buf->offset, rem_size); temp_len += rem_size; rem_size = 0; } else { if (temp_len < resp->header_len) { memcpy((uint8_t *)&resp->hdr, temp, temp_len); memcpy(((uint8_t *)&resp->hdr) + temp_len, cur_buf->buf + cur_buf->offset, resp->header_len - temp_len); temp_len = 0; rem_size -= (resp->header_len - temp_len); } else { memcpy((uint8_t *)&resp->hdr, temp, resp->header_len); DBG_VERBOSE("REQUEST id: %u\n", resp->hdr.id); temp_len -= resp->header_len; } stage = PAYLOAD_READ; resp->buf = malloc(resp->hdr.len); assert(resp->buf != NULL); } break; } case PAYLOAD_READ: { if (temp_len < resp->hdr.len) { memcpy(resp->buf, temp, temp_len); temp_len = 0; } break; } default: DBG_ERR("INVALID case needs to be find out"); assert(0); break; } } while (rem_size > 0) { switch(stage) { case HEADER_LEN_READ: if (rem_size < HEADER_SIZE){ memcpy(temp, cur_buf->buf + cur_buf->offset, rem_size); temp_len = rem_size; cur_buf->offset += rem_size; rem_size = 0; } else { resp = malloc(sizeof(response_t)); assert(resp != NULL); DBG_PRINT("Allocated resp: %p\n", resp); resp->buf = NULL; read_uint32_t((uint8_t *)cur_buf->buf + cur_buf->offset, HEADER_SIZE, &resp->header_len); cur_buf->offset += HEADER_SIZE; rem_size -= HEADER_SIZE; DBG_VERBOSE("HEADER: %u\n", resp->header_len); stage = HEADER_READ; } break; case HEADER_READ: if (rem_size < resp->header_len) { memcpy(temp, cur_buf->buf + cur_buf->offset, rem_size); temp_len = rem_size; cur_buf->offset += rem_size; rem_size = 0; } else { read_pkt_hdr((uint8_t *)cur_buf->buf + cur_buf->offset, resp->header_len, &resp->hdr); DBG_VERBOSE("HEADER: %x %x %x %x\n", resp->hdr.magic, resp->hdr.len, resp->hdr.id, resp->hdr.future); rem_size -= resp->header_len; resp->buf = malloc(resp->hdr.len); assert(resp->buf != NULL); DBG_ALLOC("ALLOC resp->buf: %p\n", resp->buf); cur_buf->offset += resp->header_len; stage = PAYLOAD_READ; } break; case PAYLOAD_READ: { size_t len_to_read = resp->hdr.len - payload_offset; if (rem_size < len_to_read) { memcpy(resp->buf + payload_offset, cur_buf->buf + cur_buf->offset, rem_size); payload_offset += rem_size; cur_buf->offset += rem_size; rem_size = 0; } else { memcpy(resp->buf + payload_offset, cur_buf->buf + cur_buf->offset, len_to_read); payload_offset = 0; rem_size -= len_to_read; cur_buf->offset += len_to_read; /* request is done, lets push it into the queue */ DBG_VERBOSE("GOT THE RESPONSE for ID: %u\n", resp->hdr.id); queue_push(client->res_q, (void *)resp); resp = NULL; stage = HEADER_LEN_READ; } } break; default: DBG_ERR("Invalid stage\n"); assert(0); } } } DBG_FUNC_EXIT(); }