Beispiel #1
0
    char* form(struct soap *soap)
    {
        char *s = NULL;
        /* It is unlikely chunked and/or compressed POST forms are sent by browsers, but we need to handle them */
        if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK
#ifdef WITH_ZLIB
                || soap->zlib_in != SOAP_ZLIB_NONE
#endif
           )
        {
            soap_wchar c = EOF;
            soap->labidx = 0;
            if (soap_append_lab(soap, "?", 1))
                return NULL;
            do
            {
                register size_t k;
                if (soap_append_lab(soap, NULL, 0))
                    return NULL;
                s = soap->labbuf + soap->labidx;
                k = soap->lablen - soap->labidx;
                soap->labidx = soap->lablen;
                while (k--)
                {
                    if ((c = soap_getchar(soap)) == (int)EOF)
                        break;
                    *s++ = c;
                }
            }
            while (c != (int)EOF);
            *s = '\0';
            s = soap->labbuf;
        }
        else
        {
            if (soap->length)
            {
                s = (char*)soap_malloc(soap, soap->length + 2);
                if (s)
                {
                    char *t = s;
                    size_t i;
                    *t++ = '?';
                    for (i = soap->length; i; i--)
                    {
                        soap_wchar c;
                        if ((c = soap_getchar(soap)) == (int)EOF)
                        {
                            soap->error = SOAP_EOF;
                            return NULL;
                        }
                        *t++ = c;
                    }
                    *t = '\0';
                }
            }
        }
        soap_end_recv(soap);
        return s;
    }
Beispiel #2
0
int soap_http_body(struct soap *soap, char **buf, size_t *len)
{ char *s = *buf = NULL;
  *len = 0;
  /* It is unlikely chunked and/or compressed POST messages are sent by browsers, but we need to handle them */
  if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK
#ifdef WITH_ZLIB
   || soap->zlib_in != SOAP_ZLIB_NONE
#endif
   )
  { register size_t k;
    soap_wchar c = EOF;
    soap->labidx = 0;
    do
    { if (soap_append_lab(soap, NULL, 0))
        return soap->error;
      s = soap->labbuf + soap->labidx;
      k = soap->lablen - soap->labidx;
      soap->labidx = soap->lablen;
      while (k--)
      { if ((c = soap_getchar(soap)) == (int)EOF)
	  break;
        *s++ = c;
      }
    } while (c != (int)EOF);
    *len = soap->lablen - k - 1;
    *buf = (char*)soap_malloc(soap, *len + 1);
    memcpy(*buf, soap->labbuf, *len + 1);
  }
  else
  { if (soap->length)
    { s = (char*)soap_malloc(soap, soap->length + 1);
      if (s)
      { char *t = s;
        size_t i;
        for (i = soap->length; i; i--)
        { soap_wchar c;
	  if ((c = soap_getchar(soap)) == (int)EOF)
	    return soap->error = SOAP_EOF;
	  *t++ = c;
	}
        *t = '\0';
      }
    }
    *buf = s;
    *len = soap->length;
  }
  return soap_end_recv(soap);
}
int main(int argc, char **argv)
{ struct soap soap;
  if (argc < 2)
  { fprintf(stderr, "Usage: httpgettest URL\n");
    exit(0);
  }
  soap_init(&soap);
  soap_register_plugin(&soap, http_get); // register plugin
  if (soap_get_connect(&soap, argv[1], NULL)
   || soap_begin_recv(&soap))
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  if (soap.http_content)
    printf("Content type = %s\n", soap.http_content);
  printf("Content length = %ld\n", soap.length);
  if ((soap.mode & SOAP_IO) == SOAP_IO_CHUNK
#ifdef WITH_ZLIB
      || soap.zlib_in != SOAP_ZLIB_NONE
#endif
     )
  { soap_wchar c;
    // This loop handles chunked/compressed transfers
    for (;;)
    { if ((c = soap_getchar(&soap)) == (int)EOF)
        break;
      putchar((int)c);
    }
  }
  else
  { // This loop handles HTTP transfers (with HTTP content length set)
    if (soap.length)
    { size_t i;
      for (i = soap.length; i; i--)
      { soap_wchar c;
        if ((c = soap_getchar(&soap)) == (int)EOF)
        { soap.error = SOAP_EOF;
          break;
        }
        putchar((int)c);
      }
    }
  }
  soap_end_recv(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return 0;
}
Beispiel #4
0
SOAP_FMAC2
soap_in_xsd__anyType(struct soap *soap, const char *tag, struct soap_dom_element *node, const char *type)
{ register struct soap_attribute *tp;
  register struct soap_dom_attribute **att;
  register struct soap_nlist *np;
  register char *s;
  if (soap_peek_element(soap))
    return NULL;
  if (!node)
    if (!(node = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element))))
    { soap->error = SOAP_EOM;
      return NULL;
    }
  node->next = NULL;
  node->prnt = NULL;
  node->elts = NULL;
  node->atts = NULL;
  node->nstr = NULL;
  node->name = NULL;
  node->data = NULL;
  node->wide = NULL;
  node->node = NULL;
  node->type = 0;
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node %s\n", soap->tag));
  np = soap->nlist;
  if (!(s = strchr(soap->tag, ':')))
  { while (np && *np->id) /* find default namespace, if present */
      np = np->next;
    s = soap->tag;
  }
  else
  { while (np && (strncmp(np->id, soap->tag, s - soap->tag) || np->id[s - soap->tag]))
      np = np->next;
    s++;
    if (!np)
    { soap->error = SOAP_NAMESPACE;
      return NULL;
    }
  }
  if (np)
  { if (np->index >= 0)
      node->nstr = soap->namespaces[np->index].ns;
    else if (np->ns)
      node->nstr = soap_strdup(soap, np->ns);
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node namespace='%s'\n", node->nstr?node->nstr:""));
  }
  node->name = soap_strdup(soap, soap->tag);
  if ((soap->mode & SOAP_DOM_NODE) || (!(soap->mode & SOAP_DOM_TREE) && *soap->id))
  { if ((node->node = soap_getelement(soap, &node->type)))
    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node contains type %d from xsi:type\n", node->type));
      return node;
    }
    if (soap->error == SOAP_TAG_MISMATCH)
      soap->error = SOAP_OK;
    else
      return NULL;
  }
  att = &node->atts;
  for (tp = soap->attributes; tp; tp = tp->next)
    if (tp->visible)
    { np = soap->nlist;
      if (!(s = strchr(tp->name, ':')))
      { while (np && *np->id) /* find default namespace, if present */
          np = np->next;
        s = tp->name;
      }
      else
      { while (np && (strncmp(np->id, tp->name, s - tp->name) || np->id[s - tp->name]))
          np = np->next;
        s++;
        if (!np)
        { soap->error = SOAP_NAMESPACE;
          return NULL;
        }
      }
      DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node attribute='%s'\n", tp->name));
      *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
      if (!*att)
      { soap->error = SOAP_EOM;
        return NULL;
      }
      (*att)->next = NULL;
      (*att)->nstr = NULL;
      if (np)
      { if (np->index >= 0)
          (*att)->nstr = soap->namespaces[np->index].ns;
        else if (np->ns)
	  (*att)->nstr = soap_strdup(soap, np->ns);
        DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM attribute namespace='%s'\n", (*att)->nstr?(*att)->nstr:""));
      }
      (*att)->name = soap_strdup(soap, s);
      if (tp->visible == 2)
        (*att)->data = soap_strdup(soap, tp->value);
      else
        (*att)->data = NULL;
      (*att)->wide = NULL;
      att = &(*att)->next;
      tp->visible = 0;
    }
  soap_element_begin_in(soap, NULL, 1);
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' accepted\n", node->name));
  if (soap->body)
  { wchar c;
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has content\n", node->name));
    do c = soap_getchar(soap);
    while (c > 0 && c <= 32);
    if (c == EOF)
    { soap->error = SOAP_EOF;
      return NULL;
    }
    soap_unget(soap, c);
    if (c == '<')
    { struct soap_dom_element **elt;
      DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has subelements\n", node->name));
      elt = &node->elts;
      for (;;)
      { if (!(*elt = soap_in_xsd__anyType(soap, NULL, NULL, NULL)))
        { if (soap->error == SOAP_NO_TAG)
            soap->error = SOAP_OK;
          else
            return NULL;
          break;
        }
	(*elt)->prnt = node;
        elt = &(*elt)->next;
      }
    }
    else
    { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s' has cdata\n", node->name));
      if ((soap->mode & SOAP_C_UTFSTRING) || (soap->mode & SOAP_C_MBSTRING))
      { if (!(node->data = soap_string_in(soap, 1, -1, -1)))
          return NULL;
      }
      else if (!(node->wide = soap_wstring_in(soap, 1, -1, -1)))
        return NULL;
    }
    if (soap_element_end_in(soap, node->name))
      return NULL;
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", node->name));
  }
  return node;
}