MIME_read_status
mime_streamreader_function(void *userdata, unsigned char *dest, int *size)
{
  int readed = 0;
  http_input_stream_t *in = (http_input_stream_t *) userdata;

  if (!http_input_stream_is_ready(in))
    return MIME_READ_EOF;

  readed = http_input_stream_read(in, dest, *size);
  /* 
     log_info1("http_input_stream_read() returned 0"); */
  if (readed == -1)
  {
    log_error4("[%d] %s():%s ", herror_code(in->err), herror_func(in->err),
               herror_message(in->err));
  }

  *size = readed;
  if (*size != -1)
  {
    return MIME_READ_OK;
  }
  return MIME_READ_ERROR;
}
Esempio n. 2
0
unsigned char *
httpd_get_postdata(httpd_conn_t * conn, struct hrequest_t * req, long *received, long max)
{
  char *content_length_str;
  long content_length = 0;
  unsigned char *postdata = NULL;

  if (req->method == HTTP_REQUEST_POST)
  {

    content_length_str =
      hpairnode_get_ignore_case(req->header, HEADER_CONTENT_LENGTH);

    if (content_length_str != NULL)
      content_length = atol(content_length_str);

  }
  else
  {
    log_warn("Not a POST method");
    return NULL;
  }

  if (content_length > max && max != -1)
    return NULL;

  if (content_length == 0)
  {
    *received = 0;
    if (!(postdata = (char *) malloc(1)))
    {

      log_error("malloc failed (%s)", strerror(errno));
      return NULL;
    }
    postdata[0] = '\0';
    return postdata;
  }
  if (!(postdata = (unsigned char *) malloc(content_length + 1)))
  {
    log_error("malloc failed (%)", strerror(errno));
    return NULL;
  }
  if (http_input_stream_read(req->in, postdata, (int) content_length) > 0)
  {
    *received = content_length;
    postdata[content_length] = '\0';
    return postdata;
  }
  free(postdata);
  return NULL;
}
Esempio n. 3
0
static int
_soap_env_xml_io_read(void *ctx, char *buffer, int len)
{
  int readed;

  http_input_stream_t *in = (http_input_stream_t *) ctx;
  if (!http_input_stream_is_ready(in))
    return 0;

  readed = http_input_stream_read(in, (byte_t *)buffer, len);
  if (readed == -1)
    return 0;
  return readed;
}
Esempio n. 4
0
static void
post_service(httpd_conn_t *conn, struct hrequest_t *req)
{
  if (req->method == HTTP_REQUEST_POST)
  {
    unsigned char buffer[1024];
    long len, total;

    httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE);
    http_output_stream_write_string(conn->out,
      "<html>"
        "<head>"
	  "<title>POST service</title>"
        "</head>"
        "<body>"
          "<h1>You posted</h1>"
          "<pre>");

    if (req->content_type && req->content_type->type)
    {
      len = sprintf(buffer, "<p>Content-Type: %s</p>", req->content_type->type);
      http_output_stream_write(conn->out, buffer, len);
    }

    while (http_input_stream_is_ready(req->in))
    {
	    len = http_input_stream_read(req->in, buffer, 1024);
	    http_output_stream_write(conn->out, buffer, len);
	    total += len;
    }

    http_output_stream_write_string(conn->out,
          "</pre>");

    len = sprintf(buffer, "<p>Received %li bytes</p>", total);
    http_output_stream_write(conn->out, buffer, len);

    http_output_stream_write_string(conn->out,
        "</body>"
      "</html>");
  }
  else
  {
    httpd_send_not_implemented(conn, "post_service");
  }
}
Esempio n. 5
0
static int
_soap_env_xml_io_read_gbk(void *ctx, char *buffer, int len)
{
  int readed;

  http_input_stream_t *in = (http_input_stream_t *) ctx;
  if (!http_input_stream_is_ready(in))
    return 0;

  readed = http_input_stream_read(in, (byte_t *)buffer, len);
  if (readed == -1)
    return 0;

  
  buffer[readed] = '\0';
  strncpy(buffer, conv_charset(buffer, "GBK", "UTF-8"), len);

  return readed;
}
Esempio n. 6
0
static
void show_response(hresponse_t *res)
{
  hpair_t *pair;
  char buffer[MAX_BUFFER_SIZE+1];
  int len;

  if (res == NULL) 
  {
    fprintf(stderr, "Response is NULL\n");
    return;
  }
  
  fprintf(stdout, "Version: '%d'\n", res->version);
  fprintf(stdout, "Status: %d\n", res->errcode);
  fprintf(stdout, "Desc: '%s'\n", res->desc);

  for (pair = res->header; pair; pair = pair->next)
  {
    fprintf(stdout, "%s: %s\n", pair->key, pair->value);
  }

  if (res->in == NULL)
  {
    fprintf(stderr, "No input stream!\n");
    return;
  }
  
  while (http_input_stream_is_ready(res->in))
  {
    len = http_input_stream_read(res->in, buffer, MAX_BUFFER_SIZE);
    fwrite(buffer, len, 1, stdout);
  }

  return;
}