📄 stdsoap2.c
字号:
#ifndef PALM_1SOAP_FMAC1const char*SOAP_FMAC2soap_str_code(const struct soap_code_map *map, LONG64 code){ while (map->code != code && map->string) map++; return map->string;}#endif/******************************************************************************/#ifndef PALM_1static wcharsoap_char(struct soap *soap){ char tmp[8]; register int i; register wchar c; register char *s = tmp; for (i = 0; i < 7; i++) { c = soap_get1(soap); if (c == ';' || c == EOF) break; *s++ = (char)c; } *s = '\0'; if (*tmp == '#') { if (tmp[1] == 'x' || tmp[1] == 'X') return strtol(tmp + 2, NULL, 16); return atol(tmp + 1); } if (!strcmp(tmp, "lt")) return '<'; if (!strcmp(tmp, "gt")) return '>'; if (!strcmp(tmp, "amp")) return '&'; if (!strcmp(tmp, "quot")) return '"'; if (!strcmp(tmp, "apos")) return '\'';#ifndef WITH_LEAN return soap_int_code(html_entity_codes, tmp, 127);#else return 127; /* use this to represent unknown code */#endif}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1wcharSOAP_FMAC2soap_get(struct soap *soap){ register wchar c; if ((c = soap->ahead)) soap->ahead = 0; else c = soap_get1(soap); for (;;) { if (soap->cdata) { if (c == ']') { c = soap_get1(soap); if (c == ']') { soap->cdata = 0; soap_get1(soap); /* skip > */ c = soap_get1(soap); } else { soap_revget1(soap); return ']'; } } else return c; } switch (c) { case '<': do c = soap_get1(soap); while (blank(c)); if (c == '!' || c == '%') { if (c == '!') { c = soap_get1(soap); if (c == '[') { do c = soap_get1(soap); while (c != EOF && c != '['); if (c == EOF) break; soap->cdata = 1; c = soap_get1(soap); continue; } if (c == '-' && (c = soap_get1(soap)) == '-') { do { c = soap_get1(soap); if (c == '-' && (c = soap_get1(soap)) == '-') break; } while (c != EOF); } } while (c != EOF && c != '>') c = soap_get1(soap); if (c == EOF) break; c = soap_get1(soap); continue; } if (c == '/') return TT; soap_revget1(soap); return LT; case '>': return GT; case '"': return QT; case '\'': return AP; case '&': return soap_char(soap) | 0x80000000; } break; } return c;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1wcharSOAP_FMAC2soap_advance(struct soap *soap){ register wchar c; while (((c = soap_get(soap)) != EOF) && c != LT && c != TT) ; return c;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1wcharSOAP_FMAC2soap_skip(struct soap *soap){ register wchar c; do c = soap_get(soap); while (blank(c)); return c;}#endif/******************************************************************************/#ifndef WITH_LEANER#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_move(struct soap *soap, long n){ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n)); for (; n > 0; n--) if (soap_getchar(soap) == EOF) return SOAP_EOF; return SOAP_OK;}#endif#endif/******************************************************************************/#ifndef WITH_LEANER#ifndef PALM_1SOAP_FMAC1size_tSOAP_FMAC2soap_tell(struct soap *soap){ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);}#endif#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_pututf8(struct soap *soap, register unsigned long c){ char tmp[16]; if (c > 0 && c < 0x80) { *tmp = (char)c; return soap_send_raw(soap, tmp, 1); }#ifndef WITH_LEAN if (soap->mode & SOAP_XML_CANONICAL) { register char *t = tmp; if (c < 0x0800) *t++ = (char)(0xC0 | ((c >> 6) & 0x1F)); else { if (c < 0x010000) *t++ = (char)(0xE0 | ((c >> 12) & 0x0F)); else { if (c < 0x200000) *t++ = (char)(0xF0 | ((c >> 18) & 0x07)); else { if (c < 0x04000000) *t++ = (char)(0xF8 | ((c >> 24) & 0x03)); else { *t++ = (char)(0xFC | ((c >> 30) & 0x01)); *t++ = (char)(0x80 | ((c >> 24) & 0x3F)); } *t++ = (char)(0x80 | ((c >> 18) & 0x3F)); } *t++ = (char)(0x80 | ((c >> 12) & 0x3F)); } *t++ = (char)(0x80 | ((c >> 6) & 0x3F)); } *t++ = (char)(0x80 | (c & 0x3F)); *t = '\0'; } else#endif sprintf(tmp, "&#%lu;", c); return soap_send(soap, tmp);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1wcharSOAP_FMAC2soap_getutf8(struct soap *soap){ register wchar c, c1, c2, c3, c4; c = soap_get(soap); if (c < 0x80) return c; c1 = soap_get(soap); if (c1 < 0x80) { soap_unget(soap, c1); return c; } c1 &= 0x3F; if (c < 0xE0) return ((wchar)(c & 0x1F) << 6) | c1; c2 = (wchar)soap_get1(soap) & 0x3F; if (c < 0xF0) return ((wchar)(c & 0x0F) << 12) | (c1 << 6) | c2; c3 = (wchar)soap_get1(soap) & 0x3F; if (c < 0xF8) return ((wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3; c4 = (wchar)soap_get1(soap) & 0x3F; if (c < 0xFC) return ((wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4; return ((wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (wchar)(soap_get1(soap) & 0x3F);}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_puthex(struct soap *soap, const unsigned char *s, size_t n){ /* TODO: serialize to DOM (as an option) using new soap_s2hex() */ char d[2]; register size_t i; for (i = 0; i < n; i++) { register int m = *s++; d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0')); m &= 0x0F; d[1] = (char)(m + (m > 9 ? '7' : '0')); if (soap_send_raw(soap, d, 2)) return soap->error; } return SOAP_OK;}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1unsigned char*SOAP_FMAC2soap_gethex(struct soap *soap, size_t *n){ if (soap_new_block(soap)) return NULL; for (;;) { register int i; register char *s = (char*)soap_push_block(soap, SOAP_BLKLEN); if (!s) { soap_end_block(soap); if (n) *n = 0; return NULL; } for (i = 0; i < SOAP_BLKLEN; i++) { register char d1, d2; register wchar c = soap_get(soap); if (isxdigit(c)) { d1 = (char)c; c = soap_get(soap); if (isxdigit(c)) d2 = (char)c; else { soap_end_block(soap); soap->error = SOAP_TYPE_MISMATCH; if (n) *n = 0; return NULL; } } else { unsigned char *p; soap_unget(soap, c); if (n) *n = soap_size_block(soap, i); p = (unsigned char*)soap_save_block(soap, NULL); return p; } *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'); } }}#endif/******************************************************************************/#ifndef PALM_1SOAP_FMAC1intSOAP_FMAC2soap_putbase64(struct soap *soap, const unsigned char *s, size_t n){ register size_t i; register unsigned long m; char d[4];#ifdef WITH_DOM if ((soap->mode & SOAP_XML_DOM) && soap->dom) { soap->dom->data = (char*)soap_malloc(soap, (n + 2) / 3 * 4 + 1); return soap_s2base64(soap, s, soap->dom->data, n); }#endif if (!s) return SOAP_OK; for (; n > 2; n -= 3, s += 3) { m = ((unsigned long)((unsigned char*)s)[0] << 16) | ((unsigned long)((unsigned char*)s)[1] << 8) | (unsigned long)((unsigned char*)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) { 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, size_t *n, int malloc_flag){ 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); if (n) *n = 0; return NULL; } for (i = 0; i < SOAP_BLKLEN; i++) { register unsigned long m = 0; register int j = 0; while (j < 4) { register 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 = soap_size_block(soap, i); p = (unsigned char*)soap_save_block(soap, NULL); if (c >= 0) c = soap_advance(soap); soap_unget(soap, c); return p; } c -= '+'; if (c >= 0 && c <= 79) { m = (m << 6) + soap_base64i[c]; j++; } } *s++ = (char)((m >> 16) & 0xFF); *s++ = (char)((m >> 8) & 0xFF); *s++ = (char)(m & 0xFF); } }}#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(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -