From df58dad240fe368c261263e248d3520d3e0be1a3 Mon Sep 17 00:00:00 2001 From: m0gg Date: Thu, 30 Nov 2006 14:23:58 +0000 Subject: Code cleanup --- examples/nanohttp/http_client.c | 214 +++++++++++++++++++--------------------- 1 file changed, 104 insertions(+), 110 deletions(-) (limited to 'examples/nanohttp/http_client.c') diff --git a/examples/nanohttp/http_client.c b/examples/nanohttp/http_client.c index e320cb9..7c1b2f0 100644 --- a/examples/nanohttp/http_client.c +++ b/examples/nanohttp/http_client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: http_client.c,v 1.6 2006/11/25 15:06:57 m0gg Exp $ +* $Id: http_client.c,v 1.7 2006/11/30 14:23:59 m0gg Exp $ * * CSOAP Project: A http client/server library in C (example) * Copyright (C) 2003-2004 Ferhat Ayaz @@ -25,13 +25,7 @@ #include #include -#include -#include -#include -#include -#include #include -#include #define MAX_BUFFER_SIZE 1024 @@ -42,109 +36,109 @@ static int show_content = 1; static char *username = NULL; static char *password = NULL; -static void show_response(hresponse_t *res) { - - unsigned char buffer[MAX_BUFFER_SIZE+1]; - int read; - - if (!res) { - - printf("hresponse_t is NULL!"); - return; - } - - if (res->errcode != 200 || show_http_status_code) - printf("HTTP Status: %d \"%s\"\n", res->errcode, res->desc); - - if (show_headers) { - - hpair_t *pair; - printf("HTTP Headers:\n"); - for (pair = res->header; pair; pair=pair->next) - printf(" %s: %s\n", pair->key, pair->value); - } - - if (!res->in) { - - log_warn1("No input stream!"); - return; - } - - while (http_input_stream_is_ready(res->in)) { - - read = http_input_stream_read(res->in, buffer, MAX_BUFFER_SIZE); - - if (show_content) - fwrite(buffer, read, 1, stdout); - } - return; +static void show_response(hresponse_t *res) +{ + unsigned char buffer[MAX_BUFFER_SIZE+1]; + int read; + + if (!res) + { + fprintf(stderr, "hresponse_t is NULL!"); + return; + } + + if (res->errcode != 200 || show_http_status_code) + printf("HTTP Status: %d \"%s\"\n", res->errcode, res->desc); + + if (show_headers) + { + hpair_t *pair; + printf("HTTP Headers:\n"); + for (pair = res->header; pair; pair=pair->next) + printf(" %s: %s\n", pair->key, pair->value); + } + + if (!res->in) + { + fprintf(stderr, "No input stream!"); + return; + } + + while (http_input_stream_is_ready(res->in)) + { + read = http_input_stream_read(res->in, buffer, MAX_BUFFER_SIZE); + + if (show_content) + fwrite(buffer, read, 1, stdout); + } + return; } -int main(int argc, char **argv) { - - httpc_conn_t *conn; /* Client connection object */ - hresponse_t *res; /* Response object **/ - herror_t status; - int i; - - /* check usage */ - if (argc < 2) { - - fprintf(stderr, "usage: %s [-headers] [-status] [-noout] [-username name] [-password secret] \n", argv[0]); - exit(1); - } - - /* XXX: this is not safe... */ - for (i=0; i\n", argv[0]); + exit(1); + } + + /* XXX: this is not safe... */ + for (i=0; i