📄 stdsoap2.cpp
字号:
do { register soap_wchar c = soap_get(soap); if (c == '=' || c < 0) { unsigned char *p; switch (j) { case 2: *s++ = (char)((m >> 4) & 0xFF); i++; break; case 3: *s++ = (char)((m >> 10) & 0xFF); *s++ = (char)((m >> 2) & 0xFF); i += 2; } if (n) *n = (int)(soap->lablen - k + i); p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i); if (p) memcpy(p, soap->labbuf, soap->lablen - k + i); if (c >= 0) { while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT) ; } soap_unget(soap, c); return p; } c -= '+'; if (c >= 0 && c <= 79) { int b = soap_base64i[c]; if (b >= 64) { soap->error = SOAP_TYPE; return NULL; } m = (m << 6) + b; j++; } else if (!soap_blank(c)) { soap->error = SOAP_TYPE; return NULL; } } while (j < 4); *s++ = (char)((m >> 16) & 0xFF); *s++ = (char)((m >> 8) & 0xFF); *s++ = (char)(m & 0xFF); } }#else if (soap_new_block(soap)) return NULL; for (;;) { register int i; register char *s = (char*)soap_push_block(soap, 3 * SOAP_BLKLEN); /* must be multiple of 3 */ if (!s) { soap_end_block(soap); return NULL; } for (i = 0; i < SOAP_BLKLEN; i++) { register unsigned long m = 0; register int j = 0; do { register soap_wchar c = soap_get(soap); if (c == '=' || c < 0) { unsigned char *p; i *= 3; switch (j) { case 2: *s++ = (char)((m >> 4) & 0xFF); i++; break; case 3: *s++ = (char)((m >> 10) & 0xFF); *s++ = (char)((m >> 2) & 0xFF); i += 2; } if (n) *n = (int)soap_size_block(soap, i); p = (unsigned char*)soap_save_block(soap, NULL, 0); if (c >= 0) { while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT) ; } soap_unget(soap, c); return p; } c -= '+'; if (c >= 0 && c <= 79) { int b = soap_base64i[c]; if (b >= 64) { soap->error = SOAP_TYPE; return NULL; } m = (m << 6) + b; j++; } else if (!soap_blank(c)) { soap->error = SOAP_TYPE; return NULL; } } while (j < 4); *s++ = (char)((m >> 16) & 0xFF); *s++ = (char)((m >> 8) & 0xFF); *s++ = (char)(m & 0xFF); } }#endif}#endif/******************************************************************************/#ifndef WITH_LEANER#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options){ /* Check MTOM xop:Include element (within hex/base64Binary) */ /* TODO: this code to be obsoleted with new import/xop.h conventions */ int body = soap->body; /* should save type too? */ if (!soap_peek_element(soap)) { if (!soap_element_begin_in(soap, "xop:Include", 0, NULL) && *soap->href) { if (soap_dime_forward(soap, ptr, size, id, type, options)) return soap->error; } if (soap->body && soap_element_end_in(soap, NULL)) return soap->error; } soap->body = body; return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef WITH_LEANER#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options){ struct soap_xlist *xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); *ptr = NULL; *size = 0; *id = soap_strdup(soap, soap->href); *type = NULL; *options = NULL; if (!xp) return soap->error = SOAP_EOM; xp->next = soap->xlist; xp->ptr = ptr; xp->size = size; xp->id = *id; xp->type = type; xp->options = options; soap->xlist = xp; return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1char *SOAP_FMAC2soap_strdup(struct soap *soap, const char *s){ char *t = NULL; if (s && (t = (char*)soap_malloc(soap, strlen(s) + 1))) strcpy(t, s); return t;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_new_block(struct soap *soap){ struct soap_blist *p; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New block sequence (prev=%p)\n", soap->blist)); if (!(p = (struct soap_blist*)SOAP_MALLOC(soap, sizeof(struct soap_blist)))) return SOAP_EOM; p->next = soap->blist; p->ptr = NULL; p->size = 0; soap->blist = p; return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1void*SOAP_FMAC2soap_push_block(struct soap *soap, size_t n){ char *p; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push block of %u bytes (%u bytes total)\n", (unsigned int)n, (unsigned int)soap->blist->size + (unsigned int)n)); if (!(p = (char*)SOAP_MALLOC(soap, n + sizeof(char*) + sizeof(size_t)))) { soap->error = SOAP_EOM; return NULL; } *(char**)p = soap->blist->ptr; *(size_t*)(p + sizeof(char*)) = n; soap->blist->ptr = p; soap->blist->size += n; return p + sizeof(char*) + sizeof(size_t);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1voidSOAP_FMAC2soap_pop_block(struct soap *soap){ char *p; if (!soap->blist->ptr) return; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop block\n")); p = soap->blist->ptr; soap->blist->size -= *(size_t*)(p + sizeof(char*)); soap->blist->ptr = *(char**)p; SOAP_FREE(soap, p);}#endif/******************************************************************************/#ifndef WITH_NOIDREF#ifndef PALM_1static voidsoap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2){ int i; register struct soap_ilist *ip; register struct soap_flist *fp;#ifndef WITH_LEANER register struct soap_xlist *xp;#endif register void *p, **q; for (i = 0; i < SOAP_IDHASH; i++) { for (ip = soap->iht[i]; ip; ip = ip->next) { if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", ip->id, ip->ptr, (char*)ip->ptr + (p1-p2))); ip->ptr = (char*)ip->ptr + (p1-p2); } for (q = &ip->link; q; q = (void**)p) { p = *q; if (p && (char*)p >= start && (char*)p < end) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Link update id='%s' %p\n", ip->id, p)); *q = (char*)p + (p1-p2); } } for (q = &ip->copy; q; q = (void**)p) { p = *q; if (p && (char*)p >= start && (char*)p < end) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy chain update id='%s' %p\n", ip->id, p)); *q = (char*)p + (p1-p2); } } for (fp = ip->flist; fp; fp = fp->next) { if ((char*)fp->ptr >= start && (char*)fp->ptr < end) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy list update id='%s' %p\n", ip->id, fp)); fp->ptr = (char*)fp->ptr + (p1-p2); } } } }#ifndef WITH_LEANER for (xp = soap->xlist; xp; xp = xp->next) { if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:"", xp->ptr, (char*)xp->ptr + (p1-p2))); xp->ptr = (unsigned char**)((char*)xp->ptr + (p1-p2)); xp->size = (int*)((char*)xp->size + (p1-p2)); xp->type = (char**)((char*)xp->type + (p1-p2)); xp->options = (char**)((char*)xp->options + (p1-p2)); } }#endif}#endif#endif/******************************************************************************/#ifndef WITH_NOIDREF#ifndef PALM_1static intsoap_has_copies(struct soap *soap, register const char *start, register const char *end){ register int i; register struct soap_ilist *ip; register struct soap_flist *fp; register const char *p; for (i = 0; i < SOAP_IDHASH; i++) { for (ip = soap->iht[i]; ip; ip = ip->next) { for (p = (const char*)ip->copy; p; p = *(const char**)p) if (p >= start && p < end) return SOAP_ERR; for (fp = ip->flist; fp; fp = fp->next) if ((const char*)fp->ptr >= start && (const char*)fp->ptr < end) return SOAP_ERR; } } return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef WITH_NOIDREF#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_resolve(struct soap *soap){ register int i; register struct soap_ilist *ip; register struct soap_flist *fp; short flag; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data\n")); for (i = 0; i < SOAP_IDHASH; i++) { for (ip = soap->iht[i]; ip; ip = ip->next) { if (ip->ptr) { register void *p, **q, *r; q = (void**)ip->link; ip->link = NULL; r = ip->ptr; DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing link chain to resolve id='%s'\n", ip->id)); while (q) { p = *q; *q = r; DBGLOG(TEST,SOAP_MESSAGE(fdebug, "... link %p -> %p\n", q, r)); q = (void**)p; } } else if (*ip->id == '#') { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Missing data for id='%s'\n", ip->id)); strcpy(soap->id, ip->id + 1); return soap->error = SOAP_MISSING_ID; } } } do { flag = 0; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution phase\n")); for (i = 0; i < SOAP_IDHASH; i++) { for (ip = soap->iht[i]; ip; ip = ip->next) { if (ip->ptr && !soap_has_copies(soap, (const char*)ip->ptr, (const char*)ip->ptr + ip->size)) { if (ip->copy) { register void *p, **q = (void**)ip->copy; DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing copy chain to resolve id='%s'\n", ip->id)); ip->copy = NULL; do { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... copy %p -> %p (%u bytes)\n", ip->ptr, q, (unsigned int)ip->size)); p = *q; memcpy(q, ip->ptr, ip->size); q = (void**)p; } while (q); flag = 1; } for (fp = ip->flist; fp; fp = ip->flist) { register unsigned int k = fp->level; register void *p = ip->ptr; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data type=%d location=%p level=%u,%u id='%s'\n", ip->type, p, ip->level, fp->level, ip->id)); while (ip->level < k) { register void **q = (void**)soap_malloc(soap, sizeof(void*)); if (!q) return soap->error; *q = p; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level, new location=%p holds=%p...\n", q, *q)); p = (void*)q; k--; } if (fp->fcopy) fp->fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size); else soap_fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size); ip->flist = fp->next; SOAP_FREE(soap, fp); flag = 1; } } } } } while (flag);#ifdef SOAP_DEBUG for (i = 0; i < SOAP_IDHASH; i++) { for (ip = soap->iht[i]; ip; ip = ip->next) { if (ip->copy || ip->flist) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution error: forwarded data for id='%s' could not be propagated, please report this problem to the developers\n", ip->id)); } } }#endif DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution done\n")); return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1size_tSOAP_FMAC2soap_size_block(struct soap *soap, size_t n){ if (soap->blist->ptr) { soap->blist->size -= *(size_t*)(soap->blist->ptr + sizeof(char*)) - n; *(size_t*)(soap->blist->ptr + sizeof(char*)) = n; } return soap->blist->size;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1char*SOAP_FMAC2soap_first_block(struct soap *soap){ char *p, *q, *r; p = soap->blist->ptr; if (!p) return NULL; DBGLOG(TEST, SOAP_MESSAGE(fdebug, "First block\n")); r = NULL; do { q = *(char**)p; *(char**)p = r; r = p; p = q; } while (p); soap->blist->ptr = r; return r + sizeof(char*) + sizeof(size_t);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1char*SOAP_FMAC2soap_next_block(struct soap *soap){ char *p; p = soap->blist->ptr; if (p) { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Next block\n")); soap->blist->ptr = *(char**)p; SOAP_FREE(soap, p); if (soap->blist->ptr) return soap->blist->ptr +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -