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; }
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; }
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"); } }
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; }
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; }