static int TagRead(FILE *stream, SOAP_TAG *tag, int avail) { int rc; char *cp; memset(tag, 0, sizeof(*tag)); avail = avail > SOAP_MAX_TAG_SIZE ? SOAP_MAX_TAG_SIZE : avail; rc = ReadUntilChars(stream, ">", NULL, tag->soap_buff, avail); if (rc > 0) { cp = tag->soap_buff; if (*cp == '/') { cp++; tag->soap_ttf = SOAPTYPE_ETAG; } tag->soap_name._name = cp; while (*cp && *cp != ' ') { if (*cp == ':') { *cp++ = '\0'; tag->soap_name._namespace = tag->soap_name._name; tag->soap_name._name = cp; } else { cp++; } } if (tag->soap_ttf == 0) { int ac; for (ac = 0; *cp && ac < SOAP_MAX_TAG_ATTRIBUTES; ac++) { *cp = '\0'; while (*++cp == ' '); if (*cp == '/' && *(cp + 1) == '\0') { tag->soap_ttf = SOAPTYPE_EOTAG; break; } tag->soap_attr[ac].attr_name._name = cp; while (*cp && *cp != '=') { if (*cp == ':') { *cp++ = '\0'; tag->soap_attr[ac].attr_name._namespace = tag->soap_attr[ac].attr_name._name; tag->soap_attr[ac].attr_name._name = cp; } else { cp++; } } if (*cp) { uint_fast8_t quoted = *++cp == '"'; cp += quoted; tag->soap_attr[ac].attr_value = cp; while (*cp) { if (quoted) { if (*cp == '"') { break; } } else if (*cp == ' ') { break; } cp++; } if (*cp) { *cp++ = '\0'; } } } } } return rc; }
CStrAny Parse::ReadUntilWhitespace(CStrAny &s) { return ReadUntilChars(s, g_sWhitespace); }
static int ReadResultBody(FILE *stream, int avail, SOAP_PROCEDURE *proc) { SOAP_ARG *arg = NULL; SOAP_TAG *tag; int bufsiz; int got; int in_body = 0; tag = malloc(sizeof(*tag)); if (avail < 16 || tag == NULL) { return -1; } while (avail) { /* Read all characters up to the next tag, but honor limits. */ bufsiz = avail > SOAP_MAX_TAG_SIZE ? SOAP_MAX_TAG_SIZE : avail; got = ReadUntilChars(stream, "<", NULL, tag->soap_buff, bufsiz); avail -= got; if (got <= 0 || avail <= 4) { break; } tag->soap_buff[got] = '\0'; /* If we are inside an argument, then this is the value. */ if (arg) { arg->arg_val = strdup(tag->soap_buff); } /* Now read the tag. */ got = TagRead(stream, tag, avail); avail -= got; if (got <= 0) { break; } /* Check for envelope tag. */ if (strcmp(tag->soap_name._name, "Envelope") == 0) { if (tag->soap_ttf) { /* Closing tag, update state. */ in_body = 0; } } /* Check for body tag. */ else if (strcmp(tag->soap_name._name, "Body") == 0) { /* Update state according to opening or closing tags. */ in_body = tag->soap_ttf == 0; } /* Check for other tags only if we are inside a body. */ else if (in_body) { /* Following tags in a body contain arguments. */ if (tag->soap_ttf == 0) { /* Opening tag. */ for (arg = proc->proc_argo; arg; arg = arg->arg_next) { if (strcasecmp(tag->soap_name._name, arg->arg_name) == 0) { break; } } } else { arg = NULL; } } } return 0; }
CStrAny Parse::ReadToNewLine(CStrAny &s) { return ReadUntilChars(s, CStrAny(ST_WHOLE, "\r\n")); }