diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | libcsoap/soap-client.c | 4 | ||||
-rw-r--r-- | libcsoap/soap-env.c | 20 | ||||
-rw-r--r-- | libcsoap/soap-env.h | 4 | ||||
-rw-r--r-- | libcsoap/soap-xml.c | 8 | ||||
-rw-r--r-- | libcsoap/soap-xml.h | 6 | ||||
-rw-r--r-- | nanohttp/nanohttp-common.c | 23 | ||||
-rw-r--r-- | nanohttp/nanohttp-server.c | 39 | ||||
-rw-r--r-- | nanohttp/nanohttp-socket.c | 23 |
9 files changed, 84 insertions, 45 deletions
diff --git a/configure.ac b/configure.ac index 7a313ff..0eb4a3d 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl -------------------------------- dnl Initialization macros. dnl -------------------------------- -AC_INIT(libcsoap/csoap.h) +AC_INIT(libcsoap/soap-xml.h) AM_CONFIG_HEADER(config.h) dnl ----------------------------------------------- diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c index f9e964f..39b001d 100644 --- a/libcsoap/soap-client.c +++ b/libcsoap/soap-client.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-client.c,v 1.1 2004/02/03 08:10:05 snowdrop Exp $ + * $Id: soap-client.c,v 1.2 2004/02/03 08:59:22 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -46,7 +46,7 @@ soap_client_invoke(SoapEnv *call, const char *url, const char *soap_action) /* Create buffer */ buffer = xmlBufferCreate(); - xmlNodeDump(buffer, call->root->doc,call->root, 1 ,2); + xmlNodeDump(buffer, call->root->doc,call->root, 1 ,0); content = (char*)xmlBufferContent(buffer); /* Transport via HTTP */ diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c index f7c1449..265295b 100644 --- a/libcsoap/soap-env.c +++ b/libcsoap/soap-env.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-env.c,v 1.1 2004/02/03 08:10:05 snowdrop Exp $ + * $Id: soap-env.c,v 1.2 2004/02/03 08:59:22 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -280,6 +280,24 @@ soap_env_get_body(SoapEnv* env) xmlNodePtr +soap_env_get_method(SoapEnv* env) +{ + + xmlNodePtr body; + + body = soap_env_get_body(env); + if (body == NULL) { + log_verbose1("body is NULL"); + return NULL; + } + + /* mehtod is the first child */ + return soap_xml_get_children(body); + +} + + +xmlNodePtr _soap_env_get_body(SoapEnv* env) { xmlNodePtr node, body; diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h index af969f3..e89f7b4 100644 --- a/libcsoap/soap-env.h +++ b/libcsoap/soap-env.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-env.h,v 1.1 2004/02/03 08:10:05 snowdrop Exp $ + * $Id: soap-env.h,v 1.2 2004/02/03 08:59:22 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -62,6 +62,8 @@ soap_env_pop_item(SoapEnv* env); xmlNodePtr soap_env_get_body(SoapEnv* env); xmlNodePtr +soap_env_get_method(SoapEnv* env); +xmlNodePtr soap_env_get_fault(SoapEnv* env); xmlNodePtr soap_env_get_header(SoapEnv* env); diff --git a/libcsoap/soap-xml.c b/libcsoap/soap-xml.c index 1fd23a1..cbedddd 100644 --- a/libcsoap/soap-xml.c +++ b/libcsoap/soap-xml.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-xml.c,v 1.2 2004/02/03 08:07:36 snowdrop Exp $ + * $Id: soap-xml.c,v 1.3 2004/02/03 08:59:22 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -78,7 +78,7 @@ soap_xpath_eval(xmlDocPtr doc, const char *xpath) int soap_xpath_foreach(xmlDocPtr doc, const char *xpath, - soap_xmlnode_callback cb) + soap_xmlnode_callback cb, void *userdata) { int i = 0; xmlNodeSetPtr nodeset; @@ -92,7 +92,7 @@ soap_xpath_foreach(xmlDocPtr doc, const char *xpath, if (!nodeset) return 0; for (i=0;i < nodeset->nodeNr; i++) { - if (!cb(nodeset->nodeTab[i])) + if (!cb(nodeset->nodeTab[i], userdata)) break; } @@ -119,7 +119,7 @@ void soap_xml_doc_print(xmlDocPtr doc) buffer = xmlBufferCreate(); - xmlNodeDump(buffer, doc, root, 1 ,1); + xmlNodeDump(buffer, doc, root, 1 ,0); puts( (const char*)xmlBufferContent(buffer)); xmlBufferFree(buffer); diff --git a/libcsoap/soap-xml.h b/libcsoap/soap-xml.h index e4ce1ef..7976a42 100644 --- a/libcsoap/soap-xml.h +++ b/libcsoap/soap-xml.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-xml.h,v 1.2 2004/02/03 08:07:36 snowdrop Exp $ + * $Id: soap-xml.h,v 1.3 2004/02/03 08:59:22 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -28,7 +28,7 @@ #include <nanohttp/nanohttp-common.h> -typedef int (*soap_xmlnode_callback)(xmlNodePtr); +typedef int (*soap_xmlnode_callback)(xmlNodePtr, void*); xmlNodePtr soap_xml_get_children(xmlNodePtr param); @@ -39,7 +39,7 @@ soap_xpath_eval(xmlDocPtr doc, const char *xpath); int soap_xpath_foreach(xmlDocPtr doc, const char *xpath, - soap_xmlnode_callback cb); + soap_xmlnode_callback cb, void* userdata); void soap_xml_doc_print(xmlDocPtr doc); diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c index 55a9f7f..1d00d42 100644 --- a/nanohttp/nanohttp-common.c +++ b/nanohttp/nanohttp-common.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-common.c,v 1.7 2004/01/21 12:28:20 snowdrop Exp $ + * $Id: nanohttp-common.c,v 1.8 2004/02/03 08:59:23 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -255,6 +255,17 @@ void hpairnode_free(hpair_t *pair) } +void hpairnode_free_deep(hpair_t *pair) +{ + hpair_t *tmp; + + while (pair != NULL) { + tmp = pair->next; + hpairnode_free(pair); + pair=tmp; + } +} + char *hpairnode_get_ignore_case(hpair_t *pair, const char* key) { if (key == NULL) { @@ -565,7 +576,15 @@ hrequest_t *hrequest_new_from_buffer(char *data) void hrequest_free(hrequest_t *req) { - log_warn1("hrequest_free() not implemented!"); + if (req == NULL) return; + + free(req->method); + free(req->path); + free(req->spec); + + hpairnode_free_deep(req->header); + hpairnode_free_deep(req->query); + } /* response stuff */ diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c index b3bd1dc..d3a96e3 100644 --- a/nanohttp/nanohttp-server.c +++ b/nanohttp/nanohttp-server.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-server.c,v 1.3 2004/01/30 16:37:50 snowdrop Exp $ + * $Id: nanohttp-server.c,v 1.4 2004/02/03 08:59:23 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -57,7 +57,7 @@ int httpd_init(int argc, char *argv[]) /* write argument information */ log_verbose1("Arguments:"); for (i=0;i<argc;i++) - log_verbose3("argv[%i] = '%s'\n", i, SAVE_STR(argv[i])); + log_verbose3("argv[%i] = '%s'", i, SAVE_STR(argv[i])); /* initialize from arguments */ for (i=0;i<argc;i++) { @@ -66,7 +66,7 @@ int httpd_init(int argc, char *argv[]) } } - log_debug2("socket bind to port '%d'\n", _httpd_port); + log_verbose2("socket bind to port '%d'", _httpd_port); /* init built-in services */ /* @@ -87,7 +87,7 @@ int httpd_init(int argc, char *argv[]) int httpd_register(const char* ctx, httpd_service func) { hservice_t* service; - log_debug3("register service:t(%p):%s", service, SAVE_STR(ctx)); + log_verbose3("register service:t(%p):%s", service, SAVE_STR(ctx)); service = (hservice_t*)malloc(sizeof(hservice_t)); service->next = NULL; @@ -167,12 +167,14 @@ int httpd_send_header(httpd_conn_t *res, strcat(header, "\r\n"); /* set content-type */ + /* if (res->content_type[0] == '\0') { strcat(header, "Content-Type: text/html\r\n"); } else { sprintf(buffer, "Content-Type: %s\r\n", res->content_type); strcat(header, buffer); } + */ /* set server name */ strcat(header, "Server: Nano HTTPD library\r\n"); @@ -216,18 +218,18 @@ static void httpd_request_print(hrequest_t *req) { hpair_t *pair; - printf("++++++ Request +++++++++\n"); - printf(" Method : '%s'\n", req->method); - printf(" Path : '%s'\n", req->path); - printf(" Spec : '%s'\n", req->spec); - printf(" Parsed query string :\n"); + log_verbose1("++++++ Request +++++++++"); + log_verbose2(" Method : '%s'", req->method); + log_verbose2(" Path : '%s'", req->path); + log_verbose2(" Spec : '%s'", req->spec); + log_verbose1(" Parsed query string :"); pair = req->query; while (pair != NULL) { - printf(" %s = '%s'\n", pair->key, pair->value); + log_verbose3(" %s = '%s'", pair->key, pair->value); pair = pair->next; } - printf("++++++++++++++++++++++++\n"); + log_verbose1("++++++++++++++++++++++++"); } @@ -255,7 +257,7 @@ static void* httpd_session_main(void *data) len = 0; - log_debug1("starting httpd_session_main()\n"); + log_verbose1("starting httpd_session_main()"); while (len < 4064) { /*printf("receiving ...\n");*/ @@ -271,7 +273,7 @@ static void* httpd_session_main(void *data) } } - printf("=== HEADER ===\n%s\n============\n", header); + /* log_verbose2("=== HEADER ===\n%s\n============\n", header);*/ /* call the service */ req = hrequest_new_from_buffer(header); httpd_request_print(req); @@ -283,7 +285,7 @@ static void* httpd_session_main(void *data) service = httpd_find_service(req->path); if (service != NULL) { - log_verbose2("service '%s' found\n", req->path); + log_verbose2("service '%s' found", req->path); if (service->func != NULL) { service->func(rconn, req); } else { @@ -321,7 +323,7 @@ int httpd_run() fd_set fds; /*struct timeval timeout;*/ - log_debug1("starting run routine\n"); + log_verbose1("starting run routine"); /* timeout.tv_sec = 1; timeout.tv_usec = 0; @@ -329,12 +331,12 @@ int httpd_run() /* listen to port */ err = hsocket_listen(_httpd_socket,15); if (err != HSOCKET_OK) { - log_error2("httpd_run(): '%d'\n", err); + log_error2("httpd_run(): '%d'", err); return err; } - log_debug2("listening to port '%d'\n", _httpd_port); + log_verbose2("listening to port '%d'", _httpd_port); /* fcntl(_httpd_socket, F_SETFL, O_NONBLOCK);*/ @@ -361,7 +363,7 @@ int httpd_run() err = pthread_create(&tid, NULL, httpd_session_main, conn); if (err) { - printf("Error creating thread: ('%d')\n", err); + log_error2("Error creating thread: ('%d')", err); } } @@ -411,6 +413,7 @@ char *httpd_get_postdata(httpd_conn_t *conn, hrequest_t *req, long *received, lo if (hsocket_read(conn->sock, postdata, (int)content_length, 1) == HSOCKET_OK) { *received = content_length; + postdata[content_length] = '\0'; return postdata; } diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c index e828992..a555a7f 100644 --- a/nanohttp/nanohttp-socket.c +++ b/nanohttp/nanohttp-socket.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-socket.c,v 1.7 2004/01/21 12:28:20 snowdrop Exp $ + * $Id: nanohttp-socket.c,v 1.8 2004/02/03 08:59:23 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -132,7 +132,7 @@ int hsocket_bind(hsocket_t *dsock, int port) /* create socket */ sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { - log_error2("Can not create socket: '%s'\n", strerror(errno)); + log_error2("Can not create socket: '%s'", strerror(errno)); return HSOCKET_CAN_NOT_CREATE; } @@ -144,7 +144,7 @@ int hsocket_bind(hsocket_t *dsock, int port) if (bind(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1) { - log_error2("Can not bind: '%s'\n", strerror(errno)); + log_error2("Can not bind: '%s'", strerror(errno)); return HSOCKET_CAN_NOT_BIND; } @@ -158,7 +158,7 @@ int hsocket_bind(hsocket_t *dsock, int port) int hsocket_listen(hsocket_t sock, int n) { if (listen(sock, n) == -1) { - log_error2("Can not listen: '%s'\n", strerror(errno)); + log_error2("Can not listen: '%s'", strerror(errno)); return HSOCKET_CAN_NOT_LISTEN; } return HSOCKET_OK; @@ -182,7 +182,7 @@ int hsocket_accept(hsocket_t sock, hsocket_t *dest) return HSOCKET_CAN_NOT_ACCEPT; } - log_debug3("accept new socket (%d) from '%s'\n", sockfd, + log_verbose3("accept new socket (%d) from '%s'", sockfd, SAVE_STR(((char*)inet_ntoa(addr.sin_addr))) ); *dest = sockfd; @@ -279,7 +279,7 @@ int hsocket_recv(hsocket_t sock, char** buffer, int *totalSize) bufSize = HSOCKET_MAX_BUFSIZE; if (size == -1) { - log_error1("Error reading from socket\n"); + log_error1("Error reading from socket"); return HSOCKET_CAN_NOT_RECEIVE; } @@ -289,22 +289,19 @@ int hsocket_recv(hsocket_t sock, char** buffer, int *totalSize) *totalSize += size; if (*buffer) { - log_debug2("reallocation %d bytes",*totalSize+fsize+1); + log_verbose2("reallocation %d bytes",*totalSize+fsize+1); *buffer = (char*)realloc((char*)*buffer, (*totalSize)+fsize+HSOCKET_MAX_BUFSIZE); strcat(*buffer, tmp); } else { - log_debug1("Allocating"); *buffer = (char*)realloc(NULL, *totalSize+1); strcpy(*buffer, tmp); } - log_debug1("Assigning"); (*buffer)[*totalSize+fsize] = '\0'; chunk++; } while (size > 0); - log_debug1("Returning"); return HSOCKET_OK; } @@ -324,7 +321,7 @@ int hsocket_recv_cb(hsocket_t sock, size = recv(sock, tmp, HSOCKET_MAX_BUFSIZE, 0); if (size == -1) { - log_error1("Error reading from socket\n"); + log_error1("Error reading from socket"); return HSOCKET_CAN_NOT_RECEIVE; } @@ -354,7 +351,7 @@ int hbufsocket_read(hbufsocket_t *bufsock, char *buffer, int size) if (bufsock->bufsize - bufsock->cur >= size) { - log_debug1("no need to read from socket"); + log_verbose1("no need to read from socket"); strncpy(buffer, &(bufsock->buffer[bufsock->cur]), size); bufsock->cur += size; return HSOCKET_OK; @@ -362,7 +359,7 @@ int hbufsocket_read(hbufsocket_t *bufsock, char *buffer, int size) } else { tmpsize = bufsock->bufsize - bufsock->cur; - log_debug2("tmpsize = %d", tmpsize); + log_verbose2("tmpsize = %d", tmpsize); if (tmpsize > 0) strncpy(buffer, &(bufsock->buffer[bufsock->cur]), tmpsize); |