📄 stdsoap2.cpp
字号:
} }#endif}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_putbase64(struct soap *soap, const unsigned char *s, int n){ register int i; register unsigned long m; char d[4]; if (!s) return SOAP_OK;#ifdef WITH_DOM if ((soap->mode & SOAP_XML_DOM) && soap->dom) { if (!(soap->dom->data = soap_s2base64(soap, s, NULL, n))) return soap->error; return SOAP_OK; }#endif for (; n > 2; n -= 3, s += 3) { m = s[0]; m = (m << 8) | s[1]; m = (m << 8) | s[2]; for (i = 4; i > 0; m >>= 6) d[--i] = soap_base64o[m & 0x3F]; if (soap_send_raw(soap, d, 4)) return soap->error; } if (n > 0) { m = 0; for (i = 0; i < n; i++) m = (m << 8) | *s++; for (; i < 3; i++) m <<= 8; for (i++; i > 0; m >>= 6) d[--i] = soap_base64o[m & 0x3F]; for (i = 3; i > n; i--) d[i] = '='; if (soap_send_raw(soap, d, 4)) return soap->error; } return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1unsigned char*SOAP_FMAC2soap_getbase64(struct soap *soap, int *n, int malloc_flag){ #ifdef WITH_DOM if ((soap->mode & SOAP_XML_DOM) && soap->dom) { soap->dom->data = soap_string_in(soap, 0, -1, -1); return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n); }#endif#ifdef WITH_FAST soap->labidx = 0; for (;;) { register size_t i, k; register char *s; if (soap_append_lab(soap, NULL, 2)) return NULL; s = soap->labbuf + soap->labidx; k = soap->lablen - soap->labidx; soap->labidx = 3 * (soap->lablen / 3); if (!s) return NULL; if (k > 2) { for (i = 0; i < k - 2; i += 3) { register unsigned long m = 0; register int j = 0; 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 + i - k); p = (unsigned char*)soap_malloc(soap, soap->lablen + i - k); if (p) memcpy(p, soap->labbuf, soap->lablen + i - k); 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) { register 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; *ptr = NULL; *size = 0; *type = NULL; *options = NULL; *id = soap_strdup(soap, soap->href); if (!*id) return SOAP_OK; xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); 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 = NULL; register struct soap_flist *fp = NULL;#ifndef WITH_LEANER register struct soap_xlist *xp = NULL;#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 = NULL; register struct soap_flist *fp = NULL; 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 = NULL; register struct soap_flist *fp = NULL; 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, "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -