diff options
author | snowdrop | 2006-01-10 11:21:55 +0000 |
---|---|---|
committer | snowdrop | 2006-01-10 11:21:55 +0000 |
commit | c24e5b5135d745098ea6e5c4664a88ada6b99225 (patch) | |
tree | 5a699cafd54fe64e08c10f2a2912f1d800cc0a6b /libcsoap | |
parent | 56841f81e5c0082ec7c36e44737d07f60fada535 (diff) | |
download | csoap-c24e5b5135d745098ea6e5c4664a88ada6b99225.tar.gz csoap-c24e5b5135d745098ea6e5c4664a88ada6b99225.tar.bz2 |
indent with 'indent -nut -bli0 -fca' command
Diffstat (limited to 'libcsoap')
-rw-r--r-- | libcsoap/soap-client.c | 353 | ||||
-rw-r--r-- | libcsoap/soap-client.h | 17 | ||||
-rwxr-xr-x | libcsoap/soap-ctx.c | 152 | ||||
-rwxr-xr-x | libcsoap/soap-ctx.h | 19 | ||||
-rw-r--r-- | libcsoap/soap-env.c | 191 | ||||
-rw-r--r-- | libcsoap/soap-env.h | 87 | ||||
-rw-r--r-- | libcsoap/soap-fault.c | 96 | ||||
-rw-r--r-- | libcsoap/soap-fault.h | 14 | ||||
-rw-r--r-- | libcsoap/soap-router.c | 118 | ||||
-rw-r--r-- | libcsoap/soap-router.h | 20 | ||||
-rw-r--r-- | libcsoap/soap-server.c | 589 | ||||
-rw-r--r-- | libcsoap/soap-server.h | 12 | ||||
-rw-r--r-- | libcsoap/soap-service.c | 94 | ||||
-rw-r--r-- | libcsoap/soap-service.h | 20 | ||||
-rw-r--r-- | libcsoap/soap-xml.c | 162 | ||||
-rw-r--r-- | libcsoap/soap-xml.h | 19 |
16 files changed, 1034 insertions, 929 deletions
diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c index 5c3aeac..d1599bd 100644 --- a/libcsoap/soap-client.c +++ b/libcsoap/soap-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-client.c,v 1.19 2005/12/19 14:18:26 snowdrop Exp $ +* $Id: soap-client.c,v 1.20 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -27,236 +27,255 @@ /*--------------------------------- */ static int _block_socket = 0; -static herror_t _soap_client_build_result(hresponse_t *res, SoapEnv **out); +static herror_t _soap_client_build_result (hresponse_t * res, SoapEnv ** out); /*--------------------------------- */ -void soap_client_block_socket(int block) +void +soap_client_block_socket (int block) { - _block_socket = block; + _block_socket = block; } -int soap_client_get_blockmode() +int +soap_client_get_blockmode () { - return _block_socket; + return _block_socket; } -herror_t soap_client_init_args(int argc, char *argv[]) - +herror_t +soap_client_init_args (int argc, char *argv[]) { - return httpc_init(argc, argv); + return httpc_init (argc, argv); } -void soap_client_destroy() +void +soap_client_destroy () { - httpc_destroy(); + httpc_destroy (); } -static -long _file_get_size(const char* filename) +static long +_file_get_size (const char *filename) { - FILE *f = fopen(filename, "r"); + FILE *f = fopen (filename, "r"); long size; - if (!f) return -1; + if (!f) + return -1; - fseek(f, 0, SEEK_END); - size=ftell(f); - fclose(f); + fseek (f, 0, SEEK_END); + size = ftell (f); + fclose (f); return size; } herror_t -soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const char *soap_action) +soap_client_invoke (SoapCtx * call, SoapCtx ** response, const char *url, + const char *soap_action) { /* Status */ herror_t status; - /* Result document */ - SoapEnv* res_env; + /* Result document */ + SoapEnv *res_env; - /* Buffer variables*/ - xmlBufferPtr buffer; - char *content; - char tmp[15]; + /* Buffer variables */ + xmlBufferPtr buffer; + char *content; + char tmp[15]; - /* Transport variables */ - httpc_conn_t *conn; - hresponse_t *res; + /* Transport variables */ + httpc_conn_t *conn; + hresponse_t *res; - /* multipart/related start id*/ - char start_id[150]; - static int counter=1; - part_t *part; + /* multipart/related start id */ + char start_id[150]; + static int counter = 1; + part_t *part; - /* for copy attachments */ + /* for copy attachments */ char href[MAX_HREF_SIZE]; - - /* Create buffer */ - buffer = xmlBufferCreate(); - xmlNodeDump(buffer, call->env->root->doc,call->env->root, 1 ,0); - content = (char*)xmlBufferContent(buffer); - - /* Transport via HTTP */ - conn = httpc_new(); - if(!conn){ - return herror_new("soap_client_invoke", SOAP_ERROR_CLIENT_INIT, "Unable to create SOAP client!" ); - } - conn->block = soap_client_get_blockmode(); - - /* Set soap action */ - if (soap_action != NULL) { - httpc_set_header(conn, "SoapAction", soap_action); - } - - /* check for attachments */ - if (!call->attachments) - { - /* content-type is always 'text/xml' */ - httpc_set_header(conn, HEADER_CONTENT_TYPE, "text/xml"); - - sprintf(tmp, "%d", (int)strlen(content)); - httpc_set_header(conn, HEADER_CONTENT_LENGTH, tmp); - status = httpc_post_begin(conn, url); - - if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; + + /* Create buffer */ + buffer = xmlBufferCreate (); + xmlNodeDump (buffer, call->env->root->doc, call->env->root, 1, 0); + content = (char *) xmlBufferContent (buffer); + + /* Transport via HTTP */ + conn = httpc_new (); + if (!conn) + { + return herror_new ("soap_client_invoke", SOAP_ERROR_CLIENT_INIT, + "Unable to create SOAP client!"); + } + conn->block = soap_client_get_blockmode (); + + /* Set soap action */ + if (soap_action != NULL) + { + httpc_set_header (conn, "SoapAction", soap_action); + } + + /* check for attachments */ + if (!call->attachments) + { + /* content-type is always 'text/xml' */ + httpc_set_header (conn, HEADER_CONTENT_TYPE, "text/xml"); + + sprintf (tmp, "%d", (int) strlen (content)); + httpc_set_header (conn, HEADER_CONTENT_LENGTH, tmp); + status = httpc_post_begin (conn, url); + + if (status != H_OK) + { + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; } - - status = http_output_stream_write_string(conn->out, content); - if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; + + status = http_output_stream_write_string (conn->out, content); + if (status != H_OK) + { + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; } - - status = httpc_post_end(conn, &res); - if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; + + status = httpc_post_end (conn, &res); + if (status != H_OK) + { + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; } - } - else - { - + } + else + { + /* Use chunked transport */ - httpc_set_header(conn, HEADER_TRANSFER_ENCODING, TRANSFER_ENCODING_CHUNKED); - - sprintf(start_id, "289247829121218%d", counter++); - status = httpc_mime_begin(conn, url, start_id, "", "text/xml"); - if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; - } - - status = httpc_mime_next(conn, start_id, "text/xml", "binary"); - if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; - } + httpc_set_header (conn, HEADER_TRANSFER_ENCODING, + TRANSFER_ENCODING_CHUNKED); - status = http_output_stream_write(conn->out, content, strlen(content)); - if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; + sprintf (start_id, "289247829121218%d", counter++); + status = httpc_mime_begin (conn, url, start_id, "", "text/xml"); + if (status != H_OK) + { + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; } - - for (part=call->attachments->parts; part; part=part->next) + status = httpc_mime_next (conn, start_id, "text/xml", "binary"); + if (status != H_OK) { - status = httpc_mime_send_file(conn, part->id, - part->content_type, part->transfer_encoding, part->filename); - if (status != H_OK) { - log_error2("Send file failed. Status:%d", status); - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; - } + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; } - status = httpc_mime_end(conn, &res); + status = http_output_stream_write (conn->out, content, strlen (content)); if (status != H_OK) { - httpc_close_free(conn); - xmlBufferFree(buffer); - return status; + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; } - } - /* Free buffer */ - xmlBufferFree(buffer); - /* Build result */ - status = _soap_client_build_result(res, &res_env); - if (status != H_OK) { - hresponse_free(res); - httpc_close_free(conn); - return status; - } + for (part = call->attachments->parts; part; part = part->next) + { + status = httpc_mime_send_file (conn, part->id, + part->content_type, + part->transfer_encoding, part->filename); + if (status != H_OK) + { + log_error2 ("Send file failed. Status:%d", status); + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; + } + } - /* Create Context */ - *response = soap_ctx_new(res_env); + status = httpc_mime_end (conn, &res); + if (status != H_OK) + { + httpc_close_free (conn); + xmlBufferFree (buffer); + return status; + } + } + + /* Free buffer */ + xmlBufferFree (buffer); + + /* Build result */ + status = _soap_client_build_result (res, &res_env); + if (status != H_OK) + { + hresponse_free (res); + httpc_close_free (conn); + return status; + } + + /* Create Context */ + *response = soap_ctx_new (res_env); /* soap_ctx_add_files(*response, res->attachments);*/ - if (res->attachments!=NULL) { - part = res->attachments->parts; - while (part) { - soap_ctx_add_file(*response, part->filename, part->content_type, href); - part->deleteOnExit = 0; - part = part->next; - } - part = (*response)->attachments->parts; - while (part) { - part->deleteOnExit = 1; - part = part->next; - } - } - - - hresponse_free(res); - httpc_close_free(conn); - return H_OK; + if (res->attachments != NULL) + { + part = res->attachments->parts; + while (part) + { + soap_ctx_add_file (*response, part->filename, part->content_type, href); + part->deleteOnExit = 0; + part = part->next; + } + part = (*response)->attachments->parts; + while (part) + { + part->deleteOnExit = 1; + part = part->next; + } + } + + + hresponse_free (res); + httpc_close_free (conn); + return H_OK; } -static -herror_t - _soap_client_build_result(hresponse_t *res, SoapEnv** env) +static herror_t +_soap_client_build_result (hresponse_t * res, SoapEnv ** env) { - herror_t err; + herror_t err; - log_verbose2("Building result (%p)", res); + log_verbose2 ("Building result (%p)", res); - if (res == NULL) - return herror_new("_soap_client_build_result", - GENERAL_INVALID_PARAM, "hresponse_t is NULL"); + if (res == NULL) + return herror_new ("_soap_client_build_result", + GENERAL_INVALID_PARAM, "hresponse_t is NULL"); - if (res->in == NULL) - return herror_new("_soap_client_build_result", - GENERAL_INVALID_PARAM, "Empty response from server"); + if (res->in == NULL) + return herror_new ("_soap_client_build_result", + GENERAL_INVALID_PARAM, "Empty response from server"); - if (res->errcode != 200) - return herror_new("_soap_client_build_result", - GENERAL_INVALID_PARAM, "HTTP code is not 200 OK"); + if (res->errcode != 200) + return herror_new ("_soap_client_build_result", + GENERAL_INVALID_PARAM, "HTTP code is not 200 OK"); - err = soap_env_new_from_stream(res->in, env); + err = soap_env_new_from_stream (res->in, env); - if (err != H_OK) { - return err; - } + if (err != H_OK) + { + return err; + } - return H_OK; + return H_OK; } - - diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h index b99d2aa..0795a29 100644 --- a/libcsoap/soap-client.h +++ b/libcsoap/soap-client.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-client.h,v 1.10 2005/12/19 14:06:16 snowdrop Exp $ + * $Id: soap-client.h,v 1.11 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -32,13 +32,13 @@ /** Initializes the client side soap engine */ -herror_t soap_client_init_args(int argc, char *argv[]); +herror_t soap_client_init_args (int argc, char *argv[]); /** Destroy the soap client module */ -void soap_client_destroy(); +void soap_client_destroy (); /** @@ -53,9 +53,8 @@ void soap_client_destroy(); @returns H_OK if success */ -herror_t soap_client_invoke(SoapCtx *ctx, SoapCtx** response, - const char *url, - const char *soap_action); +herror_t soap_client_invoke (SoapCtx * ctx, SoapCtx ** response, + const char *url, const char *soap_action); @@ -67,9 +66,7 @@ herror_t soap_client_invoke(SoapCtx *ctx, SoapCtx** response, @param block 1 to creat blocked sockets, 0 to create non blocking sockets. */ -void soap_client_block_socket(int block); -int soap_client_get_blockmode(); +void soap_client_block_socket (int block); +int soap_client_get_blockmode (); #endif - - diff --git a/libcsoap/soap-ctx.c b/libcsoap/soap-ctx.c index 291a161..b2d1db2 100755 --- a/libcsoap/soap-ctx.c +++ b/libcsoap/soap-ctx.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-ctx.c,v 1.5 2005/05/27 19:28:15 snowdrop Exp $ + * $Id: soap-ctx.c,v 1.6 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003-2004 Ferhat Ayaz @@ -25,112 +25,128 @@ #include <string.h> -SoapCtx* soap_ctx_new(SoapEnv *env) /* should only be used internally */ +SoapCtx * +soap_ctx_new (SoapEnv * env) /* should only be used internally */ { - SoapCtx* ctx = (SoapCtx*)malloc(sizeof(SoapCtx)); + SoapCtx *ctx = (SoapCtx *) malloc (sizeof (SoapCtx)); ctx->env = env; ctx->attachments = NULL; - + return ctx; } -void soap_ctx_add_files(SoapCtx* ctx, attachments_t *attachments) +void +soap_ctx_add_files (SoapCtx * ctx, attachments_t * attachments) { part_t *part; char href[MAX_HREF_SIZE]; - - if (attachments==NULL) return; + + if (attachments == NULL) + return; part = attachments->parts; - while (part) { - soap_ctx_add_file(ctx, part->filename, part->content_type, href); + while (part) + { + soap_ctx_add_file (ctx, part->filename, part->content_type, href); part = part->next; } } -herror_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* content_type, char *dest_href) +herror_t +soap_ctx_add_file (SoapCtx * ctx, const char *filename, + const char *content_type, char *dest_href) { char cid[250]; char id[250]; part_t *part; static int counter = 1; - FILE *test = fopen(filename, "r"); - if (!test) - return herror_new("soap_ctx_add_file", FILE_ERROR_OPEN, - "Can not open file '%s'", filename); - - fclose(test); - + FILE *test = fopen (filename, "r"); + if (!test) + return herror_new ("soap_ctx_add_file", FILE_ERROR_OPEN, + "Can not open file '%s'", filename); + + fclose (test); + /* generate an id */ - sprintf(id, "005512345894583%d", counter++); - sprintf(dest_href, "cid:%s", id); - sprintf(cid, "<%s>", id); + sprintf (id, "005512345894583%d", counter++); + sprintf (dest_href, "cid:%s", id); + sprintf (cid, "<%s>", id); /* add part to context */ - part = part_new(cid, filename, content_type, NULL, NULL); - if (!ctx->attachments) ctx->attachments = attachments_new(); - attachments_add_part(ctx->attachments, part); + part = part_new (cid, filename, content_type, NULL, NULL); + if (!ctx->attachments) + ctx->attachments = attachments_new (); + attachments_add_part (ctx->attachments, part); return H_OK; } -part_t *soap_ctx_get_file(SoapCtx* ctx, xmlNodePtr node) +part_t * +soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node) { - xmlChar *prop; - char href[MAX_HREF_SIZE]; - char buffer[MAX_HREF_SIZE]; - part_t *part; - - if (!ctx->attachments) return NULL; - - prop = xmlGetProp(node, "href"); - - if (!prop) return NULL; - - strcpy(href, (const char*)prop); - if (!strncmp(href, "cid:", 4)) { - for (part = ctx->attachments->parts; part; part=part->next) - { - sprintf(buffer, "<%s>", href+4); - if (!strcmp(part->id, buffer)) - return part; - - } - } else { - for (part = ctx->attachments->parts; part; part=part->next) - { - if (!strcmp(part->location, href)) - return part; - - } - } - - return NULL; + xmlChar *prop; + char href[MAX_HREF_SIZE]; + char buffer[MAX_HREF_SIZE]; + part_t *part; + + if (!ctx->attachments) + return NULL; + + prop = xmlGetProp (node, "href"); + + if (!prop) + return NULL; + + strcpy (href, (const char *) prop); + if (!strncmp (href, "cid:", 4)) + { + for (part = ctx->attachments->parts; part; part = part->next) + { + sprintf (buffer, "<%s>", href + 4); + if (!strcmp (part->id, buffer)) + return part; + + } + } + else + { + for (part = ctx->attachments->parts; part; part = part->next) + { + if (!strcmp (part->location, href)) + return part; + + } + } + + return NULL; } -void soap_ctx_free(SoapCtx* ctx) +void +soap_ctx_free (SoapCtx * ctx) { - if (!ctx) return; - + if (!ctx) + return; + if (ctx->attachments) - attachments_free(ctx->attachments); + attachments_free (ctx->attachments); if (ctx->env) - soap_env_free(ctx->env); - - free(ctx); + soap_env_free (ctx->env); + + free (ctx); } -herror_t soap_ctx_new_with_method(const char *urn, const char *method, SoapCtx **out) +herror_t +soap_ctx_new_with_method (const char *urn, const char *method, SoapCtx ** out) { - SoapEnv *env; - herror_t err; - err = soap_env_new_with_method(urn, method, &env); - if (err != H_OK) return err; - *out = soap_ctx_new(env); + SoapEnv *env; + herror_t err; + err = soap_env_new_with_method (urn, method, &env); + if (err != H_OK) + return err; + *out = soap_ctx_new (env); return H_OK; } - diff --git a/libcsoap/soap-ctx.h b/libcsoap/soap-ctx.h index a8a8337..2df74b9 100755 --- a/libcsoap/soap-ctx.h +++ b/libcsoap/soap-ctx.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-ctx.h,v 1.5 2004/11/02 23:09:26 snowdrop Exp $ + * $Id: soap-ctx.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003-2004 Ferhat Ayaz @@ -38,10 +38,10 @@ typedef struct _SoapCtx { SoapEnv *env; attachments_t *attachments; -}SoapCtx; +} SoapCtx; -SoapCtx* soap_ctx_new(SoapEnv *env); /* should only be used internally */ +SoapCtx *soap_ctx_new (SoapEnv * env); /* should only be used internally */ /** Returns the attached file if any found. @@ -51,21 +51,22 @@ SoapCtx* soap_ctx_new(SoapEnv *env); /* should only be used internally */ @returns a part_t object of attachment was found, NULL otherwise. */ -part_t *soap_ctx_get_file(SoapCtx* ctx, xmlNodePtr node); +part_t *soap_ctx_get_file (SoapCtx * ctx, xmlNodePtr node); /** Creates a new soap context object. */ -herror_t soap_ctx_new_with_method(const char *urn, const char *method, SoapCtx **out); +herror_t soap_ctx_new_with_method (const char *urn, const char *method, + SoapCtx ** out); /* Size of destination dest_href should be MAX_HREF_SIZE */ -herror_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* content_type, char *dest_href); +herror_t soap_ctx_add_file (SoapCtx * ctx, const char *filename, + const char *content_type, char *dest_href); /* Used internally. Will switch the deleteOnExit flag from the given one to the added part. */ -void soap_ctx_add_files(SoapCtx* ctx, attachments_t *attachments); -void soap_ctx_free(SoapCtx* ctx); +void soap_ctx_add_files (SoapCtx * ctx, attachments_t * attachments); +void soap_ctx_free (SoapCtx * ctx); #endif - diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c index 2018b3d..ec27137 100644 --- a/libcsoap/soap-env.c +++ b/libcsoap/soap-env.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-env.c,v 1.10 2004/11/02 23:09:26 snowdrop Exp $ +* $Id: soap-env.c,v 1.11 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -90,12 +90,12 @@ struct XmlNodeHolder static void xmlbuilder_start_element (const xmlChar * element_name, int attr_count, - xmlChar ** keys, xmlChar ** values, - void *userData); + xmlChar ** keys, xmlChar ** values, + void *userData); static void xmlbuilder_characters (const xmlChar * element_name, - const xmlChar * chars, void *userData); + const xmlChar * chars, void *userData); static void xmlbuilder_end_element (const xmlChar * element_name, void *userData); @@ -105,7 +105,7 @@ static herror_t -soap_env_new_from_doc (xmlDocPtr doc, SoapEnv **out) +soap_env_new_from_doc (xmlDocPtr doc, SoapEnv ** out) { xmlNodePtr node; SoapEnv *env; @@ -113,16 +113,17 @@ soap_env_new_from_doc (xmlDocPtr doc, SoapEnv **out) if (doc == NULL) { log_error1 ("Can not create xml document!"); - return herror_new("soap_env_new_from_doc", - GENERAL_INVALID_PARAM, "XML Document (xmlDocPtr) is NULL"); + return herror_new ("soap_env_new_from_doc", + GENERAL_INVALID_PARAM, + "XML Document (xmlDocPtr) is NULL"); } node = xmlDocGetRootElement (doc); if (node == NULL) { log_error1 ("xml document is empty!"); - return herror_new("soap_env_new_from_doc", - XML_ERROR_EMPTY_DOCUMENT, "XML Document is empty!"); + return herror_new ("soap_env_new_from_doc", + XML_ERROR_EMPTY_DOCUMENT, "XML Document is empty!"); } env = (SoapEnv *) malloc (sizeof (SoapEnv)); @@ -130,12 +131,10 @@ soap_env_new_from_doc (xmlDocPtr doc, SoapEnv **out) /* set root */ env->root = node; - /* set method root - set call->cur (current node) to <method>. - xpath: //Envelope/Body/ - */ - node = soap_xml_get_children (env->root);/* Check for NULL ! */ - env->cur = soap_xml_get_children (node); /* Check for NULL ! */ + /* set method root set call->cur (current node) to <method>. xpath: + //Envelope/Body/ */ + node = soap_xml_get_children (env->root); /* Check for NULL ! */ + env->cur = soap_xml_get_children (node); /* Check for NULL ! */ *out = env; return H_OK; @@ -145,22 +144,23 @@ soap_env_new_from_doc (xmlDocPtr doc, SoapEnv **out) herror_t -soap_env_new_from_buffer (const char *buffer, SoapEnv **out) +soap_env_new_from_buffer (const char *buffer, SoapEnv ** out) { xmlDocPtr doc; herror_t err; if (buffer == NULL) - return herror_new("soap_env_new_from_buffer", - GENERAL_INVALID_PARAM, "buffer (first param) is NULL"); + return herror_new ("soap_env_new_from_buffer", + GENERAL_INVALID_PARAM, "buffer (first param) is NULL"); doc = xmlParseDoc (BAD_CAST buffer); if (doc == NULL) - return herror_new("soap_env_new_from_buffer", - XML_ERROR_PARSE, "Can not parse xml"); + return herror_new ("soap_env_new_from_buffer", + XML_ERROR_PARSE, "Can not parse xml"); err = soap_env_new_from_doc (doc, out); - if (err != H_OK) { + if (err != H_OK) + { xmlFreeDoc (doc); } @@ -170,19 +170,21 @@ soap_env_new_from_buffer (const char *buffer, SoapEnv **out) herror_t soap_env_new_with_fault (fault_code_t faultcode, - const char *faultstring, - const char *faultactor, const char *detail, SoapEnv **out) + const char *faultstring, + const char *faultactor, const char *detail, + SoapEnv ** out) { xmlDocPtr doc; herror_t err; - + doc = soap_fault_build (faultcode, faultstring, faultactor, detail); if (doc == NULL) - return herror_new("soap_env_new_with_fault", - XML_ERROR_PARSE, "Can not parse fault xml"); + return herror_new ("soap_env_new_with_fault", + XML_ERROR_PARSE, "Can not parse fault xml"); err = soap_env_new_from_doc (doc, out); - if (err != H_OK) { + if (err != H_OK) + { xmlFreeDoc (doc); } @@ -191,7 +193,7 @@ soap_env_new_with_fault (fault_code_t faultcode, herror_t -soap_env_new_with_response (SoapEnv * request, SoapEnv **out) +soap_env_new_with_response (SoapEnv * request, SoapEnv ** out) { char urn[100]; char methodname[150]; @@ -199,20 +201,24 @@ soap_env_new_with_response (SoapEnv * request, SoapEnv **out) if (request == NULL) { - return herror_new("soap_env_new_with_response", - GENERAL_INVALID_PARAM, "request (first param) is NULL"); + return herror_new ("soap_env_new_with_response", + GENERAL_INVALID_PARAM, + "request (first param) is NULL"); } if (request->root == NULL) { - return herror_new("soap_env_new_with_response", - GENERAL_INVALID_PARAM, "request (first param) has no xml structure"); - } + return herror_new ("soap_env_new_with_response", + GENERAL_INVALID_PARAM, + "request (first param) has no xml structure"); + } if (!soap_env_find_methodname (request, methodname)) { - return herror_new("soap_env_new_with_response", - GENERAL_INVALID_PARAM, "Method name '%s' not found in request", SAVE_STR(methodname)); + return herror_new ("soap_env_new_with_response", + GENERAL_INVALID_PARAM, + "Method name '%s' not found in request", + SAVE_STR (methodname)); } if (!soap_env_find_urn (request, urn)) @@ -229,7 +235,7 @@ soap_env_new_with_response (SoapEnv * request, SoapEnv **out) herror_t -soap_env_new_with_method (const char *urn, const char *method, SoapEnv **out) +soap_env_new_with_method (const char *urn, const char *method, SoapEnv ** out) { xmlDocPtr env; xmlChar buffer[1054]; @@ -238,36 +244,38 @@ soap_env_new_with_method (const char *urn, const char *method, SoapEnv **out) log_verbose2 ("URN = '%s'", urn); log_verbose2 ("Method = '%s'", method); - if (!strcmp(urn, "")) + if (!strcmp (urn, "")) { #ifdef USE_XMLSTRING xmlStrPrintf (buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_EMPTY_TARGET_, - soap_env_ns, soap_env_enc, soap_xsi_ns, - soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method); + soap_env_ns, soap_env_enc, soap_xsi_ns, + soap_xsd_ns, BAD_CAST method, BAD_CAST urn, + BAD_CAST method); #else - sprintf(buffer, _SOAP_MSG_TEMPLATE_EMPTY_TARGET_, - soap_env_ns, soap_env_enc, soap_xsi_ns, - soap_xsd_ns, method, urn, method); + sprintf (buffer, _SOAP_MSG_TEMPLATE_EMPTY_TARGET_, + soap_env_ns, soap_env_enc, soap_xsi_ns, + soap_xsd_ns, method, urn, method); #endif } else { #ifdef USE_XMLSTRING xmlStrPrintf (buffer, 1054, BAD_CAST _SOAP_MSG_TEMPLATE_, - soap_env_ns, soap_env_enc, soap_xsi_ns, - soap_xsd_ns, BAD_CAST method, BAD_CAST urn, BAD_CAST method); -#else - sprintf(buffer, _SOAP_MSG_TEMPLATE_, - soap_env_ns, soap_env_enc, soap_xsi_ns, - soap_xsd_ns, method, urn, method); + soap_env_ns, soap_env_enc, soap_xsi_ns, + soap_xsd_ns, BAD_CAST method, BAD_CAST urn, + BAD_CAST method); +#else + sprintf (buffer, _SOAP_MSG_TEMPLATE_, + soap_env_ns, soap_env_enc, soap_xsi_ns, + soap_xsd_ns, method, urn, method); #endif } - + env = xmlParseDoc (buffer); if (!env) - return herror_new("soap_env_new_with_method", - XML_ERROR_PARSE, "Can not parse xml"); + return herror_new ("soap_env_new_with_method", + XML_ERROR_PARSE, "Can not parse xml"); return soap_env_new_from_doc (env, out); @@ -275,22 +283,22 @@ soap_env_new_with_method (const char *urn, const char *method, SoapEnv **out) -static -int _soap_env_xml_io_read(void* ctx, char *buffer, int len) +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, buffer, len); - if (readed == -1) - return 0; - return readed; + 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, buffer, len); + if (readed == -1) + return 0; + return readed; } -static -int _soap_env_xml_io_close(void *ctx) +static int +_soap_env_xml_io_close (void *ctx) { /* do nothing */ return 0; @@ -298,17 +306,19 @@ int _soap_env_xml_io_close(void *ctx) herror_t -soap_env_new_from_stream(http_input_stream_t *in, SoapEnv **out) +soap_env_new_from_stream (http_input_stream_t * in, SoapEnv ** out) { xmlDocPtr doc; herror_t err; - - doc = xmlReadIO(_soap_env_xml_io_read, - _soap_env_xml_io_close, in, "", NULL, 0); - if (in->err != H_OK) return in->err; - if (doc == NULL) return herror_new("soap_env_new_from_stream", - XML_ERROR_PARSE, "Trying to parse not valid xml"); + doc = xmlReadIO (_soap_env_xml_io_read, + _soap_env_xml_io_close, in, "", NULL, 0); + + if (in->err != H_OK) + return in->err; + if (doc == NULL) + return herror_new ("soap_env_new_from_stream", + XML_ERROR_PARSE, "Trying to parse not valid xml"); err = soap_env_new_from_doc (doc, out); return err; } @@ -316,7 +326,7 @@ soap_env_new_from_stream(http_input_stream_t *in, SoapEnv **out) xmlNodePtr soap_env_add_item (SoapEnv * call, const char *type, - const char *name, const char *value) + const char *name, const char *value) { xmlNodePtr newnode; @@ -345,7 +355,7 @@ soap_env_add_item (SoapEnv * call, const char *type, xmlNodePtr soap_env_add_itemf (SoapEnv * call, const char *type, - const char *name, const char *format, ...) + const char *name, const char *format, ...) { va_list ap; @@ -361,8 +371,8 @@ soap_env_add_itemf (SoapEnv * call, const char *type, -xmlNodePtr -soap_env_add_attachment(SoapEnv* call, const char *name, const char *href) +xmlNodePtr +soap_env_add_attachment (SoapEnv * call, const char *name, const char *href) { xmlNodePtr newnode; @@ -388,7 +398,7 @@ soap_env_add_attachment(SoapEnv* call, const char *name, const char *href) void soap_env_add_custom (SoapEnv * call, void *obj, XmlSerializerCallback cb, - const char *type, const char *name) + const char *type, const char *name) { struct XmlNodeHolder holder; @@ -470,14 +480,15 @@ soap_env_get_body (SoapEnv * env) xmlNodePtr -soap_env_get_fault(SoapEnv * env) +soap_env_get_fault (SoapEnv * env) { xmlNodePtr node; - - node = soap_env_get_body(env); - if (!node) return NULL; + node = soap_env_get_body (env); + + if (!node) + return NULL; while (node != NULL) { @@ -530,9 +541,7 @@ _soap_env_get_body (SoapEnv * env) } /* - find <Body> tag find out namespace - xpath: //Envelope/Body/ - */ + find <Body> tag find out namespace xpath: //Envelope/Body/ */ xpathobj = soap_xpath_eval (env->root->doc, "//Envelope/Body"); if (!xpathobj) @@ -556,7 +565,7 @@ _soap_env_get_body (SoapEnv * env) return NULL; } - body = nodeset->nodeTab[0]; /* body is <Body> */ + body = nodeset->nodeTab[0]; /* body is <Body> */ xmlXPathFreeObject (xpathobj); return body; @@ -591,13 +600,13 @@ soap_env_find_urn (SoapEnv * env, char *urn) if (ns != NULL) { strcpy (urn, (char *) ns->href); - return 1; /* namespace found! */ + return 1; /* namespace found! */ } } else - { - strcpy(urn,""); - log_warn1("No namespace found"); + { + strcpy (urn, ""); + log_warn1 ("No namespace found"); return 1; } @@ -614,7 +623,7 @@ soap_env_find_methodname (SoapEnv * env, char *method) if (body == NULL) return 0; - node = soap_xml_get_children (body); /* node is the first child */ + node = soap_xml_get_children (body); /* node is the first child */ if (node == NULL) { @@ -643,7 +652,7 @@ soap_env_find_methodname (SoapEnv * env, char *method) static void xmlbuilder_start_element (const xmlChar * element_name, int attr_count, - xmlChar ** keys, xmlChar ** values, void *userData) + xmlChar ** keys, xmlChar ** values, void *userData) { struct XmlNodeHolder *holder = (struct XmlNodeHolder *) userData; xmlNodePtr parent = NULL; @@ -660,7 +669,7 @@ xmlbuilder_start_element (const xmlChar * element_name, int attr_count, static void xmlbuilder_characters (const xmlChar * element_name, const xmlChar * chars, - void *userData) + void *userData) { struct XmlNodeHolder *holder = (struct XmlNodeHolder *) userData; xmlNodePtr parent = NULL; diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h index 523438d..6a3d909 100644 --- a/libcsoap/soap-env.h +++ b/libcsoap/soap-env.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-env.h,v 1.9 2004/11/02 23:09:26 snowdrop Exp $ + * $Id: soap-env.h,v 1.10 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -33,10 +33,10 @@ The SOAP envelope object. */ typedef struct _SoapEnv -{ +{ xmlNodePtr root; /** Pointer to the firts xml element (envelope) */ xmlNodePtr cur; /** Pointer to the current xml element. (stack) */ -}SoapEnv; +} SoapEnv; /* -------------------------------------------------------------- */ @@ -73,10 +73,10 @@ typedef struct _SoapEnv */ herror_t -soap_env_new_with_fault(fault_code_t faultcode, - const char *faultstring, - const char *faultactor, - const char *detail, SoapEnv **out); +soap_env_new_with_fault (fault_code_t faultcode, + const char *faultstring, + const char *faultactor, + const char *detail, SoapEnv ** out); /** Creates an envelope with a method to invoke a soap service. @@ -104,7 +104,8 @@ soap_env_new_with_fault(fault_code_t faultcode, */ herror_t -soap_env_new_with_method(const char *urn, const char *method, SoapEnv **out); +soap_env_new_with_method (const char *urn, const char *method, + SoapEnv ** out); /** @@ -137,7 +138,7 @@ soap_env_new_with_method(const char *urn, const char *method, SoapEnv **out); */ -herror_t soap_env_new_with_response(SoapEnv *req,SoapEnv **out); +herror_t soap_env_new_with_response (SoapEnv * req, SoapEnv ** out); /** @@ -149,7 +150,7 @@ herror_t soap_env_new_with_response(SoapEnv *req,SoapEnv **out); @returns H_OK if success */ -herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv **out); +herror_t soap_env_new_from_doc (xmlDocPtr doc, SoapEnv ** out); /** @@ -160,7 +161,7 @@ herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv **out); @param out the output envelope object @returns H_OK if success */ -herror_t soap_env_new_from_buffer(const char* buffer,SoapEnv **out); +herror_t soap_env_new_from_buffer (const char *buffer, SoapEnv ** out); /** @@ -170,18 +171,21 @@ herror_t soap_env_new_from_buffer(const char* buffer,SoapEnv **out); @param out the output envelope object @returns H_OK if success */ -herror_t soap_env_new_from_stream(http_input_stream_t *in, SoapEnv **out); +herror_t soap_env_new_from_stream (http_input_stream_t * in, SoapEnv ** out); /* --------------------------------------------------- */ /* XML Serializer functions and typedefs */ /* --------------------------------------------------- */ typedef void (*XmlSerializerCallback) - (void* /*obj*/, const xmlChar * /*root_element_name*/, - void (*OnStartElement)(const xmlChar* element_name, int attr_count, xmlChar **keys, xmlChar **values, void* userData), - void (*OnCharacters)(const xmlChar* element_name, const xmlChar* chars, void* userData), - void (*OnEndElement)(const xmlChar* element_name, void* userData), - void* /* userdata*/); + (void * /* obj */ , const xmlChar * /* root_element_name */ , + void (*OnStartElement) (const xmlChar * element_name, int attr_count, + xmlChar ** keys, xmlChar ** values, + void *userData), + void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars, + void *userData), + void (*OnEndElement) (const xmlChar * element_name, void *userData), + void * /* userdata */ ); /* ------------------------------------------------------ */ @@ -206,9 +210,9 @@ typedef void (*XmlSerializerCallback) @see tutorial */ -xmlNodePtr -soap_env_add_item(SoapEnv* env, const char *type, - const char *name, const char *value); +xmlNodePtr +soap_env_add_item (SoapEnv * env, const char *type, + const char *name, const char *value); /** @@ -227,8 +231,8 @@ soap_env_add_item(SoapEnv* env, const char *type, @see soap_ctx_add_file tutorial */ -xmlNodePtr -soap_env_add_attachment(SoapEnv* env, const char *name, const char *href); +xmlNodePtr +soap_env_add_attachment (SoapEnv * env, const char *name, const char *href); /** @@ -239,8 +243,8 @@ soap_env_add_attachment(SoapEnv* env, const char *name, const char *href); */ void -soap_env_add_custom(SoapEnv* env, void *obj, XmlSerializerCallback cb, - const char *type, const char *name); +soap_env_add_custom (SoapEnv * env, void *obj, XmlSerializerCallback cb, + const char *type, const char *name); /** Same as soap_env_add_item() with c style arguments @@ -251,9 +255,9 @@ soap_env_add_custom(SoapEnv* env, void *obj, XmlSerializerCallback cb, @see soap_env_add_item */ -xmlNodePtr -soap_env_add_itemf(SoapEnv* env, const char *type, - const char *name, const char *value, ...); +xmlNodePtr +soap_env_add_itemf (SoapEnv * env, const char *type, + const char *name, const char *value, ...); /** @@ -280,9 +284,8 @@ soap_env_add_itemf(SoapEnv* env, const char *type, @see tutorial */ -xmlNodePtr -soap_env_push_item(SoapEnv *env, const char *type, - const char *name); +xmlNodePtr +soap_env_push_item (SoapEnv * env, const char *type, const char *name); /** Sets the xml pointer 1 level higher. @@ -290,16 +293,14 @@ soap_env_push_item(SoapEnv *env, const char *type, @param env The envelope object @see soap_env_push_item */ -void -soap_env_pop_item(SoapEnv* env); +void soap_env_pop_item (SoapEnv * env); /** Free the envelope. @param env The envelope object */ -void -soap_env_free(SoapEnv *env); +void soap_env_free (SoapEnv * env); /* --------------------------------------------------- */ @@ -310,33 +311,29 @@ soap_env_free(SoapEnv *env); /** Gets the xml node pointing to SOAP Body. */ -xmlNodePtr -soap_env_get_body(SoapEnv* env); +xmlNodePtr soap_env_get_body (SoapEnv * env); /** Get the xml node pointing to SOAP method (call) */ -xmlNodePtr -soap_env_get_method(SoapEnv* env); +xmlNodePtr soap_env_get_method (SoapEnv * env); /** Get the xml node pointing to SOAP Fault */ -xmlNodePtr -soap_env_get_fault(SoapEnv* env); +xmlNodePtr soap_env_get_fault (SoapEnv * env); /** Get the xml node pointing to SOAP Header */ -xmlNodePtr -soap_env_get_header(SoapEnv* env); +xmlNodePtr soap_env_get_header (SoapEnv * env); -int soap_env_find_urn(SoapEnv *env, char *urn); -int soap_env_find_methodname(SoapEnv *env, char *methodname); +int soap_env_find_urn (SoapEnv * env, char *urn); +int soap_env_find_methodname (SoapEnv * env, char *methodname); @@ -344,5 +341,3 @@ int soap_env_find_methodname(SoapEnv *env, char *methodname); #endif - - diff --git a/libcsoap/soap-fault.c b/libcsoap/soap-fault.c index eeb146d..3c8f5c1 100644 --- a/libcsoap/soap-fault.c +++ b/libcsoap/soap-fault.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-fault.c,v 1.6 2005/12/19 14:06:16 snowdrop Exp $ +* $Id: soap-fault.c,v 1.7 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -62,67 +62,67 @@ static char *fault_mu = "MustUnderstand"; static char *fault_client = "Client"; static char *fault_server = "Server"; -xmlDocPtr soap_fault_build(fault_code_t fcode, - const char *faultstring, - const char *faultactor, - const char *detail) +xmlDocPtr +soap_fault_build (fault_code_t fcode, + const char *faultstring, + const char *faultactor, const char *detail) { - /* variables */ - char *faultcode; - int bufferlen = 2000; - char *buffer; - xmlDocPtr fault; /* result */ + /* variables */ + char *faultcode; + int bufferlen = 2000; + char *buffer; + xmlDocPtr fault; /* result */ - log_verbose1("Build fault"); + log_verbose1 ("Build fault"); - switch (fcode) { + switch (fcode) + { case Fault_VersionMismatch: - faultcode = fault_vm; - break; + faultcode = fault_vm; + break; case Fault_MustUnderstand: - faultcode = fault_mu; - break; + faultcode = fault_mu; + break; case Fault_Client: - faultcode = fault_client; - break; + faultcode = fault_client; + break; case Fault_Server: - faultcode = fault_server; - break; + faultcode = fault_server; + break; default: - faultcode = fault_client; - } + faultcode = fault_client; + } - /* calculate buffer length */ - if (faultstring) bufferlen += strlen(faultstring); - if (faultactor) bufferlen += strlen(faultactor); - if (detail) bufferlen += strlen(detail); + /* calculate buffer length */ + if (faultstring) + bufferlen += strlen (faultstring); + if (faultactor) + bufferlen += strlen (faultactor); + if (detail) + bufferlen += strlen (detail); - log_verbose2("Creating buffer with %d bytes", bufferlen); - buffer = (char*)malloc(bufferlen); + log_verbose2 ("Creating buffer with %d bytes", bufferlen); + buffer = (char *) malloc (bufferlen); - sprintf(buffer, _SOAP_FAULT_TEMPLATE_, - soap_env_ns, soap_env_enc, soap_xsi_ns, - soap_xsd_ns, faultcode, - faultstring?faultstring:"error", - faultactor?faultactor:"", - detail?detail:""); + sprintf (buffer, _SOAP_FAULT_TEMPLATE_, + soap_env_ns, soap_env_enc, soap_xsi_ns, + soap_xsd_ns, faultcode, + faultstring ? faultstring : "error", + faultactor ? faultactor : "", detail ? detail : ""); - fault = xmlParseDoc(BAD_CAST buffer); - free(buffer); - - if (fault == NULL) { - log_error1("Can not create xml document!"); - - return soap_fault_build(fcode, "Can not create fault object in xml", - "soap_fault_build()", NULL); - } - - log_verbose2("Returning fault (%p)", fault); - return fault; - -} + fault = xmlParseDoc (BAD_CAST buffer); + free (buffer); + if (fault == NULL) + { + log_error1 ("Can not create xml document!"); + return soap_fault_build (fcode, "Can not create fault object in xml", + "soap_fault_build()", NULL); + } + log_verbose2 ("Returning fault (%p)", fault); + return fault; +} diff --git a/libcsoap/soap-fault.h b/libcsoap/soap-fault.h index dcc18e2..46471a0 100644 --- a/libcsoap/soap-fault.h +++ b/libcsoap/soap-fault.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-fault.h,v 1.2 2004/10/15 13:34:02 snowdrop Exp $ + * $Id: soap-fault.h,v 1.3 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -28,18 +28,18 @@ -typedef enum _fault_code { +typedef enum _fault_code +{ Fault_VersionMismatch, Fault_MustUnderstand, Fault_Client, Fault_Server -}fault_code_t; +} fault_code_t; -xmlDocPtr soap_fault_build(fault_code_t faultcode, - const char *faultstring, - const char *faultactor, - const char *detail); +xmlDocPtr soap_fault_build (fault_code_t faultcode, + const char *faultstring, + const char *faultactor, const char *detail); #endif diff --git a/libcsoap/soap-router.c b/libcsoap/soap-router.c index 966edad..74c53be 100644 --- a/libcsoap/soap-router.c +++ b/libcsoap/soap-router.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-router.c,v 1.3 2004/08/26 17:06:18 rans Exp $ +* $Id: soap-router.c,v 1.4 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -24,80 +24,88 @@ #include <libcsoap/soap-router.h> #include <string.h> -SoapRouter *soap_router_new() +SoapRouter * +soap_router_new () { - SoapRouter *router; + SoapRouter *router; - router = (SoapRouter*)malloc(sizeof(SoapRouter)); - router->service_head = NULL; - router->service_tail = NULL; + router = (SoapRouter *) malloc (sizeof (SoapRouter)); + router->service_head = NULL; + router->service_tail = NULL; - return router; + return router; } -void soap_router_register_service(SoapRouter *router, - SoapServiceFunc func, - const char* method, - const char* urn) +void +soap_router_register_service (SoapRouter * router, + SoapServiceFunc func, + const char *method, const char *urn) { - SoapService *service; - - service = soap_service_new(urn, method, func); - - if (router->service_tail == NULL) { - router->service_head = - router->service_tail = soap_service_node_new(service, NULL); - } else { - router->service_tail->next = - soap_service_node_new(service, NULL); - router->service_tail = router->service_tail->next; - } + SoapService *service; + + service = soap_service_new (urn, method, func); + + if (router->service_tail == NULL) + { + router->service_head = + router->service_tail = soap_service_node_new (service, NULL); + } + else + { + router->service_tail->next = soap_service_node_new (service, NULL); + router->service_tail = router->service_tail->next; + } } -SoapService* soap_router_find_service(SoapRouter *router, - const char* urn, - const char* method) +SoapService * +soap_router_find_service (SoapRouter * router, + const char *urn, const char *method) { - SoapServiceNode *node; + SoapServiceNode *node; - if (router == NULL || urn == NULL || method == NULL) - return NULL; + if (router == NULL || urn == NULL || method == NULL) + return NULL; - node = router->service_head; + node = router->service_head; - while (node) { - if (node->service && node->service->urn - && node->service->method) { + while (node) + { + if (node->service && node->service->urn && node->service->method) + { - if (!strcmp(node->service->urn, urn) - && !strcmp(node->service->method, method)) - return node->service; + if (!strcmp (node->service->urn, urn) + && !strcmp (node->service->method, method)) + return node->service; - } + } - node = node->next; - } + node = node->next; + } - return NULL; + return NULL; } -void soap_router_free(SoapRouter *router) +void +soap_router_free (SoapRouter * router) { - SoapServiceNode *node; - log_verbose2("enter: router=%p", router); - if (router == NULL) return; - - while (router->service_head) { - node = router->service_head->next; - /* log_verbose2("soap_service_free(%p)\n", router->service_head->service);*/ - soap_service_free(router->service_head->service); - free(router->service_head); - router->service_head = node; - } - - free(router); - log_verbose1("leave with success"); + SoapServiceNode *node; + log_verbose2 ("enter: router=%p", router); + if (router == NULL) + return; + + while (router->service_head) + { + node = router->service_head->next; + /* log_verbose2("soap_service_free(%p)\n", + router->service_head->service); */ + soap_service_free (router->service_head->service); + free (router->service_head); + router->service_head = node; + } + + free (router); + log_verbose1 ("leave with success"); } diff --git a/libcsoap/soap-router.h b/libcsoap/soap-router.h index b0a2536..f82d43c 100644 --- a/libcsoap/soap-router.h +++ b/libcsoap/soap-router.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-router.h,v 1.2 2004/02/10 09:51:10 snowdrop Exp $ + * $Id: soap-router.h,v 1.3 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -35,7 +35,7 @@ typedef struct _SoapRouter { SoapServiceNode *service_head; SoapServiceNode *service_tail; -}SoapRouter; +} SoapRouter; /** @@ -47,7 +47,7 @@ typedef struct _SoapRouter @returns Soap router @see soap_router_free */ -SoapRouter *soap_router_new(); +SoapRouter *soap_router_new (); /** @@ -60,10 +60,9 @@ SoapRouter *soap_router_new(); the client side. @param urn The urn for this service */ -void soap_router_register_service(SoapRouter *router, - SoapServiceFunc func, - const char* method, - const char* urn); +void soap_router_register_service (SoapRouter * router, + SoapServiceFunc func, + const char *method, const char *urn); /** @@ -75,9 +74,8 @@ void soap_router_register_service(SoapRouter *router, @return The service if found, NULL otherwise. */ -SoapService* soap_router_find_service(SoapRouter *router, - const char* urn, - const char* method); +SoapService *soap_router_find_service (SoapRouter * router, + const char *urn, const char *method); /** @@ -85,6 +83,6 @@ SoapService* soap_router_find_service(SoapRouter *router, @param router The router object to free */ -void soap_router_free(SoapRouter *router); +void soap_router_free (SoapRouter * router); #endif diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c index 591ecc0..9daf639 100644 --- a/libcsoap/soap-server.c +++ b/libcsoap/soap-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-server.c,v 1.12 2005/12/19 14:06:16 snowdrop Exp $ +* $Id: soap-server.c,v 1.13 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -28,362 +28,409 @@ typedef struct _SoapRouterNode { - char *context; - SoapRouter *router; - struct _SoapRouterNode *next; + char *context; + SoapRouter *router; + struct _SoapRouterNode *next; -}SoapRouterNode; +} SoapRouterNode; SoapRouterNode *head = NULL; SoapRouterNode *tail = NULL; static -SoapRouterNode *router_node_new(SoapRouter *router, - const char *context, - SoapRouterNode *next); + SoapRouterNode *router_node_new (SoapRouter * router, + const char *context, + SoapRouterNode * next); -static -SoapRouter *router_find(const char *context); +static SoapRouter *router_find (const char *context); -static -void _soap_server_send_ctx(httpd_conn_t* conn, SoapCtx *ctxres); +static void _soap_server_send_ctx (httpd_conn_t * conn, SoapCtx * ctxres); /*---------------------------------*/ -void soap_server_entry(httpd_conn_t *conn, hrequest_t *req); +void soap_server_entry (httpd_conn_t * conn, hrequest_t * req); +static void _soap_server_send_env (http_output_stream_t * out, SoapEnv * env); static -void _soap_server_send_env(http_output_stream_t *out, SoapEnv* env); -static -void _soap_server_send_fault(httpd_conn_t *conn, hpair_t *header, - const char* errmsg); + void _soap_server_send_fault (httpd_conn_t * conn, hpair_t * header, + const char *errmsg); /*---------------------------------*/ -herror_t soap_server_init_args(int argc, char *argv[]) +herror_t +soap_server_init_args (int argc, char *argv[]) { - return httpd_init(argc, argv); + return httpd_init (argc, argv); } -int soap_server_register_router(SoapRouter *router, const char* context) +int +soap_server_register_router (SoapRouter * router, const char *context) { - if (!httpd_register(context, soap_server_entry)) { - return 0; - } - - if (tail == NULL) { - head = tail = router_node_new(router, context, NULL); - } else { - tail->next = router_node_new(router, context, NULL); - tail = tail->next; - } - - return 1; + if (!httpd_register (context, soap_server_entry)) + { + return 0; + } + + if (tail == NULL) + { + head = tail = router_node_new (router, context, NULL); + } + else + { + tail->next = router_node_new (router, context, NULL); + tail = tail->next; + } + + return 1; } -herror_t soap_server_run() +herror_t +soap_server_run () { - return httpd_run(); + return httpd_run (); } -void soap_server_destroy() +void +soap_server_destroy () { - SoapRouterNode *node = head; - SoapRouterNode *tmp; - - while (node != NULL) { - tmp = node->next; - log_verbose2("soap_router_free(%p)", node->router); - soap_router_free(node->router); - free(node->context); - free(node); - node = tmp; - } - httpd_destroy(); + SoapRouterNode *node = head; + SoapRouterNode *tmp; + + while (node != NULL) + { + tmp = node->next; + log_verbose2 ("soap_router_free(%p)", node->router); + soap_router_free (node->router); + free (node->context); + free (node); + node = tmp; + } + httpd_destroy (); } -void soap_server_entry(httpd_conn_t *conn, hrequest_t *req) +void +soap_server_entry (httpd_conn_t * conn, hrequest_t * req) { - hpair_t *header = NULL; - char buffer[1054]; - char urn[150]; - char method[150]; - SoapCtx *ctx, *ctxres; - SoapRouter *router; - SoapService *service; - SoapEnv *env; - herror_t err; - - if (req->method != HTTP_REQUEST_POST) { - - httpd_send_header(conn, 200, "OK"); - http_output_stream_write_string(conn->out, "<html><head></head><body>"); - http_output_stream_write_string(conn->out, "<h1>Sorry! </h1><hr>"); - http_output_stream_write_string(conn->out, "I only speak with 'POST' method"); - http_output_stream_write_string(conn->out, "</body></html>"); - return; - } - - - header = hpairnode_new(HEADER_CONTENT_TYPE, "text/xml", NULL); - - err = soap_env_new_from_stream(req->in, &env); - if (err != H_OK) - { - _soap_server_send_fault(conn, header, herror_message(err)); - herror_release(err); - return; - } - - - if (env == NULL) { - - _soap_server_send_fault(conn, header,"Can not receive POST data!"); - - } else { - - ctx = soap_ctx_new(env); - soap_ctx_add_files(ctx, req->attachments); + hpair_t *header = NULL; + char buffer[1054]; + char urn[150]; + char method[150]; + SoapCtx *ctx, *ctxres; + SoapRouter *router; + SoapService *service; + SoapEnv *env; + herror_t err; - if (ctx->env == NULL) { + if (req->method != HTTP_REQUEST_POST) + { - _soap_server_send_fault(conn, header,"Can not parse POST data!"); + httpd_send_header (conn, 200, "OK"); + http_output_stream_write_string (conn->out, "<html><head></head><body>"); + http_output_stream_write_string (conn->out, "<h1>Sorry! </h1><hr>"); + http_output_stream_write_string (conn->out, + "I only speak with 'POST' method"); + http_output_stream_write_string (conn->out, "</body></html>"); + return; + } - } else { - /*soap_xml_doc_print(env->root->doc);*/ + header = hpairnode_new (HEADER_CONTENT_TYPE, "text/xml", NULL); - router = router_find(req->path); + err = soap_env_new_from_stream (req->in, &env); + if (err != H_OK) + { + _soap_server_send_fault (conn, header, herror_message (err)); + herror_release (err); + return; + } - if ( router == NULL) { - _soap_server_send_fault(conn, header, "Can not find router!"); + if (env == NULL) + { - } else { + _soap_server_send_fault (conn, header, "Can not receive POST data!"); - if (!soap_env_find_urn(ctx->env, urn)) { + } + else + { - _soap_server_send_fault(conn, header, "No URN found!"); - soap_ctx_free(ctx); - return; - } else { - log_verbose2("urn: '%s'", urn); - } + ctx = soap_ctx_new (env); + soap_ctx_add_files (ctx, req->attachments); - if (!soap_env_find_methodname(ctx->env, method)) { + if (ctx->env == NULL) + { - _soap_server_send_fault(conn, header, "No method found!"); - soap_ctx_free(ctx); - return; - }else { - log_verbose2("method: '%s'", method); - } + _soap_server_send_fault (conn, header, "Can not parse POST data!"); - service = soap_router_find_service(router, urn, method); + } + else + { - if (service == NULL) { + /* soap_xml_doc_print(env->root->doc); */ - sprintf(buffer, "URN '%s' not found", urn); - _soap_server_send_fault(conn, header, buffer); - soap_ctx_free(ctx); - return; - } else { + router = router_find (req->path); - log_verbose2("func: %p", service->func); - ctxres = soap_ctx_new(NULL); - /* ===================================== */ - /* CALL SERVICE FUNCTION */ - /* ===================================== */ - err = service->func(ctx, ctxres); - if (err != H_OK) { - sprintf(buffer, "Service returned following error message: '%s'", - herror_message(err)); - herror_release(err); - _soap_server_send_fault(conn, header, buffer); - soap_ctx_free(ctx); - return; - } + if (router == NULL) + { - if (ctxres->env == NULL) { + _soap_server_send_fault (conn, header, "Can not find router!"); - sprintf(buffer, "Service '%s' returned no envelope", urn); - _soap_server_send_fault(conn, header, buffer); - soap_ctx_free(ctx); - return; - - } else { + } + else + { + + if (!soap_env_find_urn (ctx->env, urn)) + { + + _soap_server_send_fault (conn, header, "No URN found!"); + soap_ctx_free (ctx); + return; + } + else + { + log_verbose2 ("urn: '%s'", urn); + } + + if (!soap_env_find_methodname (ctx->env, method)) + { + + _soap_server_send_fault (conn, header, "No method found!"); + soap_ctx_free (ctx); + return; + } + else + { + log_verbose2 ("method: '%s'", method); + } + + service = soap_router_find_service (router, urn, method); + + if (service == NULL) + { + + sprintf (buffer, "URN '%s' not found", urn); + _soap_server_send_fault (conn, header, buffer); + soap_ctx_free (ctx); + return; + } + else + { + + log_verbose2 ("func: %p", service->func); + ctxres = soap_ctx_new (NULL); + /* ===================================== */ + /* CALL SERVICE FUNCTION */ + /* ===================================== */ + err = service->func (ctx, ctxres); + if (err != H_OK) + { + sprintf (buffer, "Service returned following error message: '%s'", + herror_message (err)); + herror_release (err); + _soap_server_send_fault (conn, header, buffer); + soap_ctx_free (ctx); + return; + } + + if (ctxres->env == NULL) + { + + sprintf (buffer, "Service '%s' returned no envelope", urn); + _soap_server_send_fault (conn, header, buffer); + soap_ctx_free (ctx); + return; + + } + else + { /* httpd_send_header(conn, 200, "OK"); _soap_server_send_env(conn->out, ctxres->env); */ - _soap_server_send_ctx(conn, ctxres); - /* free envctx */ - soap_ctx_free(ctxres); - } + _soap_server_send_ctx (conn, ctxres); + /* free envctx */ + soap_ctx_free (ctxres); + } - } + } - } - } - soap_ctx_free(ctx); - } + } + } + soap_ctx_free (ctx); + } } -static -void _soap_server_send_ctx(httpd_conn_t* conn, SoapCtx *ctx) +static void +_soap_server_send_ctx (httpd_conn_t * conn, SoapCtx * ctx) { - xmlBufferPtr buffer; - static int counter = 1; - char strbuffer[150]; - part_t *part; + xmlBufferPtr buffer; + static int counter = 1; + char strbuffer[150]; + part_t *part; - if (ctx->env == NULL || ctx->env->root == NULL) return; + if (ctx->env == NULL || ctx->env->root == NULL) + return; - buffer = xmlBufferCreate(); + buffer = xmlBufferCreate (); /* xmlIndentTreeOutput = 1;*/ - xmlThrDefIndentTreeOutput(1); + xmlThrDefIndentTreeOutput (1); /* xmlKeepBlanksDefault(0);*/ - xmlNodeDump(buffer, ctx->env->root->doc, ctx->env->root, 1 ,1); - - if (ctx->attachments) - { - sprintf(strbuffer, "000128590350940924234%d", counter++); - httpd_mime_send_header(conn, strbuffer, "", "text/xml", 200, "OK"); - httpd_mime_next(conn, strbuffer, "text/xml", "binary"); - http_output_stream_write_string(conn->out, (const char*)xmlBufferContent(buffer)); - part = ctx->attachments->parts; - while (part) - { - httpd_mime_send_file(conn, part->id, part->content_type, part->transfer_encoding, part->filename); - part = part->next; - } - httpd_mime_end(conn); - } - else - { - char buflen[100]; - xmlXPathContextPtr xpathCtx; - xmlXPathObjectPtr xpathObj; - xpathCtx = xmlXPathNewContext(ctx->env->root->doc); - xpathObj = xmlXPathEvalExpression("//Fault", xpathCtx); + xmlNodeDump (buffer, ctx->env->root->doc, ctx->env->root, 1, 1); + + if (ctx->attachments) + { + sprintf (strbuffer, "000128590350940924234%d", counter++); + httpd_mime_send_header (conn, strbuffer, "", "text/xml", 200, "OK"); + httpd_mime_next (conn, strbuffer, "text/xml", "binary"); + http_output_stream_write_string (conn->out, + (const char *) + xmlBufferContent (buffer)); + part = ctx->attachments->parts; + while (part) + { + httpd_mime_send_file (conn, part->id, part->content_type, + part->transfer_encoding, part->filename); + part = part->next; + } + httpd_mime_end (conn); + } + else + { + char buflen[100]; + xmlXPathContextPtr xpathCtx; + xmlXPathObjectPtr xpathObj; + xpathCtx = xmlXPathNewContext (ctx->env->root->doc); + xpathObj = xmlXPathEvalExpression ("//Fault", xpathCtx); #ifdef WIN32 #define snprintf(buffer, num, s1, s2) sprintf(buffer, s1,s2) #endif - snprintf(buflen,100,"%d", strlen((const char*)xmlBufferContent (buffer))); - httpd_set_header (conn, HEADER_CONTENT_LENGTH, buflen); - if((xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0){ - httpd_send_header(conn, 500, "FAILED"); - } else { - httpd_send_header(conn, 200, "OK"); - } - - http_output_stream_write_string(conn->out, (const char*)xmlBufferContent(buffer)); - xmlXPathFreeObject(xpathObj); - xmlXPathFreeContext(xpathCtx); - - } - xmlBufferFree(buffer); + snprintf (buflen, 100, "%d", + strlen ((const char *) xmlBufferContent (buffer))); + httpd_set_header (conn, HEADER_CONTENT_LENGTH, buflen); + if ((xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0) + { + httpd_send_header (conn, 500, "FAILED"); + } + else + { + httpd_send_header (conn, 200, "OK"); + } + + http_output_stream_write_string (conn->out, + (const char *) + xmlBufferContent (buffer)); + xmlXPathFreeObject (xpathObj); + xmlXPathFreeContext (xpathCtx); + + } + xmlBufferFree (buffer); } -static -void _soap_server_send_env(http_output_stream_t *out, SoapEnv* env) +static void +_soap_server_send_env (http_output_stream_t * out, SoapEnv * env) { - xmlBufferPtr buffer; - if (env == NULL || env->root == NULL) return; + xmlBufferPtr buffer; + if (env == NULL || env->root == NULL) + return; - buffer = xmlBufferCreate(); - xmlNodeDump(buffer, env->root->doc, env->root, 1 ,1); - http_output_stream_write_string(out, (const char*)xmlBufferContent(buffer)); - xmlBufferFree(buffer); + buffer = xmlBufferCreate (); + xmlNodeDump (buffer, env->root->doc, env->root, 1, 1); + http_output_stream_write_string (out, + (const char *) xmlBufferContent (buffer)); + xmlBufferFree (buffer); } -static -void _soap_server_send_fault(httpd_conn_t *conn, hpair_t *header, - const char* errmsg) +static void +_soap_server_send_fault (httpd_conn_t * conn, hpair_t * header, + const char *errmsg) { - SoapEnv *envres; - herror_t err; - char buffer[45]; - httpd_set_headers(conn, header); - err = httpd_send_header(conn, 500, "FAILED"); - if (err != H_OK) { - /* WARNING: unhandled exception !*/ - log_error4("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err)); - return; - } - - err = soap_env_new_with_fault(Fault_Server, - errmsg?errmsg:"General error", - "cSOAP_Server", NULL, &envres); - if (err != H_OK) { - log_error1(herror_message(err)); - http_output_stream_write_string(conn->out, "<html><head></head><body>"); - http_output_stream_write_string(conn->out, "<h1>Error</h1><hr>"); - http_output_stream_write_string(conn->out, "Error while sending fault object:<br>Message: "); - http_output_stream_write_string(conn->out, herror_message(err)); - http_output_stream_write_string(conn->out, "<br>Function: "); - http_output_stream_write_string(conn->out, herror_func(err)); - http_output_stream_write_string(conn->out, "<br>Error code: "); - sprintf(buffer, "%d", herror_code(err)); - http_output_stream_write_string(conn->out, buffer); - http_output_stream_write_string(conn->out, "</body></html>"); - return; - - herror_release(err); - } else { - _soap_server_send_env(conn->out, envres); - } + SoapEnv *envres; + herror_t err; + char buffer[45]; + httpd_set_headers (conn, header); + err = httpd_send_header (conn, 500, "FAILED"); + if (err != H_OK) + { + /* WARNING: unhandled exception ! */ + log_error4 ("%s():%s [%d]", herror_func (err), herror_message (err), + herror_code (err)); + return; + } + + err = soap_env_new_with_fault (Fault_Server, + errmsg ? errmsg : "General error", + "cSOAP_Server", NULL, &envres); + if (err != H_OK) + { + log_error1 (herror_message (err)); + http_output_stream_write_string (conn->out, "<html><head></head><body>"); + http_output_stream_write_string (conn->out, "<h1>Error</h1><hr>"); + http_output_stream_write_string (conn->out, + "Error while sending fault object:<br>Message: "); + http_output_stream_write_string (conn->out, herror_message (err)); + http_output_stream_write_string (conn->out, "<br>Function: "); + http_output_stream_write_string (conn->out, herror_func (err)); + http_output_stream_write_string (conn->out, "<br>Error code: "); + sprintf (buffer, "%d", herror_code (err)); + http_output_stream_write_string (conn->out, buffer); + http_output_stream_write_string (conn->out, "</body></html>"); + return; + + herror_release (err); + } + else + { + _soap_server_send_env (conn->out, envres); + } } -static -SoapRouterNode *router_node_new(SoapRouter *router, - const char *context, - SoapRouterNode *next) +static SoapRouterNode * +router_node_new (SoapRouter * router, + const char *context, SoapRouterNode * next) { - SoapRouterNode *node; - const char *noname = "/lost_found"; - - node = (SoapRouterNode*)malloc(sizeof(SoapRouterNode)); - if (context) { - node->context = (char*)malloc(strlen(context)+1); - strcpy(node->context, context); - } else { - log_warn2("context is null. Using '%s'", noname); - node->context = (char*)malloc(strlen(noname)+1); - strcpy(node->context, noname); - } - - node->router = router; - node->next = next; - - return node; + SoapRouterNode *node; + const char *noname = "/lost_found"; + + node = (SoapRouterNode *) malloc (sizeof (SoapRouterNode)); + if (context) + { + node->context = (char *) malloc (strlen (context) + 1); + strcpy (node->context, context); + } + else + { + log_warn2 ("context is null. Using '%s'", noname); + node->context = (char *) malloc (strlen (noname) + 1); + strcpy (node->context, noname); + } + + node->router = router; + node->next = next; + + return node; } -static -SoapRouter *router_find(const char* context) +static SoapRouter * +router_find (const char *context) { - SoapRouterNode *node = head; + SoapRouterNode *node = head; - while (node != NULL) { - if (!strcmp(node->context, context)) - return node->router; - node = node->next; - } + while (node != NULL) + { + if (!strcmp (node->context, context)) + return node->router; + node = node->next; + } - return NULL; + return NULL; } - - - - - diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h index 5290642..b829909 100644 --- a/libcsoap/soap-server.h +++ b/libcsoap/soap-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-server.h,v 1.5 2004/11/02 23:09:26 snowdrop Exp $ + * $Id: soap-server.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -44,7 +44,7 @@ @returns 1 if success, 0 otherwise */ -herror_t soap_server_init_args(int argc, char *argv[]); +herror_t soap_server_init_args (int argc, char *argv[]); /** @@ -61,22 +61,20 @@ herror_t soap_server_init_args(int argc, char *argv[]); @see soap_router_register_service */ -int soap_server_register_router(SoapRouter *router, const char* context); +int soap_server_register_router (SoapRouter * router, const char *context); /** Enters the server loop and starts to listen to http requests. */ -herror_t soap_server_run(); +herror_t soap_server_run (); /** Frees the soap server. */ -void soap_server_destroy(); +void soap_server_destroy (); #endif - - diff --git a/libcsoap/soap-service.c b/libcsoap/soap-service.c index e8ef81d..91be66e 100644 --- a/libcsoap/soap-service.c +++ b/libcsoap/soap-service.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-service.c,v 1.4 2004/09/19 07:05:03 snowdrop Exp $ +* $Id: soap-service.c,v 1.5 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -25,65 +25,71 @@ #include <nanohttp/nanohttp-common.h> #include <string.h> -SoapServiceNode *soap_service_node_new(SoapService *service, - SoapServiceNode *next) +SoapServiceNode * +soap_service_node_new (SoapService * service, SoapServiceNode * next) { - SoapServiceNode *node ; + SoapServiceNode *node; - node = (SoapServiceNode*)malloc(sizeof(SoapServiceNode)); - node->service = service; - node->next = next; + node = (SoapServiceNode *) malloc (sizeof (SoapServiceNode)); + node->service = service; + node->next = next; - return node; + return node; } -SoapService *soap_service_new(const char* urn, - const char *method, - SoapServiceFunc f) +SoapService * +soap_service_new (const char *urn, const char *method, SoapServiceFunc f) { - SoapService *service; - - - service = (SoapService*)malloc(sizeof(SoapService)); - service->func = f; - - if (urn != NULL) { - service->urn = (char*)malloc(strlen(urn)+1); - strcpy(service->urn, urn); - } else { - log_warn1("urn is NULL"); - service->urn = ""; - } - - if (method != NULL) { - service->method = (char*)malloc(strlen(method)+1); - strcpy(service->method, method); - } else { - log_warn1("method is NULL"); - service->method = ""; - } - - return service; + SoapService *service; + + + service = (SoapService *) malloc (sizeof (SoapService)); + service->func = f; + + if (urn != NULL) + { + service->urn = (char *) malloc (strlen (urn) + 1); + strcpy (service->urn, urn); + } + else + { + log_warn1 ("urn is NULL"); + service->urn = ""; + } + + if (method != NULL) + { + service->method = (char *) malloc (strlen (method) + 1); + strcpy (service->method, method); + } + else + { + log_warn1 ("method is NULL"); + service->method = ""; + } + + return service; } -void soap_service_free(SoapService *service) +void +soap_service_free (SoapService * service) { - log_verbose2("enter: service=%p", service); + log_verbose2 ("enter: service=%p", service); - if (service == NULL) return; + if (service == NULL) + return; - if (strcmp(service->urn, "")) - free(service->urn); + if (strcmp (service->urn, "")) + free (service->urn); - if (strcmp(service->method, "")) - free(service->method); + if (strcmp (service->method, "")) + free (service->method); - free(service); - log_verbose1("leave with success"); + free (service); + log_verbose1 ("leave with success"); } - diff --git a/libcsoap/soap-service.h b/libcsoap/soap-service.h index c03d7df..497e77b 100644 --- a/libcsoap/soap-service.h +++ b/libcsoap/soap-service.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-service.h,v 1.3 2004/10/28 10:30:46 snowdrop Exp $ + * $Id: soap-service.h,v 1.4 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -28,7 +28,7 @@ #include <libcsoap/soap-env.h> #include <libcsoap/soap-ctx.h> -typedef herror_t (*SoapServiceFunc)(SoapCtx*, SoapCtx*); +typedef herror_t (*SoapServiceFunc) (SoapCtx *, SoapCtx *); typedef struct _SoapService @@ -36,24 +36,22 @@ typedef struct _SoapService char *urn; char *method; SoapServiceFunc func; -}SoapService; +} SoapService; typedef struct _SoapServiceNode { SoapService *service; struct _SoapServiceNode *next; -}SoapServiceNode; +} SoapServiceNode; -SoapServiceNode *soap_service_node_new(SoapService *service, - SoapServiceNode *next); +SoapServiceNode *soap_service_node_new (SoapService * service, + SoapServiceNode * next); -SoapService *soap_service_new(const char* urn, const char *method, - SoapServiceFunc f); -void soap_service_free(SoapService *service); +SoapService *soap_service_new (const char *urn, const char *method, + SoapServiceFunc f); +void soap_service_free (SoapService * service); #endif - - diff --git a/libcsoap/soap-xml.c b/libcsoap/soap-xml.c index f973036..288e5ff 100644 --- a/libcsoap/soap-xml.c +++ b/libcsoap/soap-xml.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-xml.c,v 1.6 2004/10/15 13:34:02 snowdrop Exp $ +* $Id: soap-xml.c,v 1.7 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -23,111 +23,125 @@ ******************************************************************/ #include <libcsoap/soap-xml.h> -static const char* soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/"; +static const char *soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/"; -xmlNodePtr soap_xml_get_children(xmlNodePtr param) +xmlNodePtr +soap_xml_get_children (xmlNodePtr param) { - xmlNodePtr children; - - if (param == NULL) { - log_error1("Invalid parameter 'param' (null)"); - return NULL; - } - - children = param->xmlChildrenNode; - while (children != NULL) { - if (children->type != XML_ELEMENT_NODE) - children = children->next; - else break; - } - - return children; + xmlNodePtr children; + + if (param == NULL) + { + log_error1 ("Invalid parameter 'param' (null)"); + return NULL; + } + + children = param->xmlChildrenNode; + while (children != NULL) + { + if (children->type != XML_ELEMENT_NODE) + children = children->next; + else + break; + } + + return children; } -xmlNodePtr soap_xml_get_next(xmlNodePtr param) +xmlNodePtr +soap_xml_get_next (xmlNodePtr param) { - xmlNodePtr node = param->next; + xmlNodePtr node = param->next; - while (node != NULL) { - if (node->type != XML_ELEMENT_NODE) - node = node->next; - else break; - } + while (node != NULL) + { + if (node->type != XML_ELEMENT_NODE) + node = node->next; + else + break; + } - return node; + return node; } -xmlXPathObjectPtr -soap_xpath_eval(xmlDocPtr doc, const char *xpath) +xmlXPathObjectPtr +soap_xpath_eval (xmlDocPtr doc, const char *xpath) { - xmlXPathContextPtr context; - xmlXPathObjectPtr result; - - context = xmlXPathNewContext(doc); - result = xmlXPathEvalExpression(BAD_CAST xpath, context); - if(xmlXPathNodeSetIsEmpty(result->nodesetval)){ - /* no result */ - return NULL; - } - - xmlXPathFreeContext(context); - return result; + xmlXPathContextPtr context; + xmlXPathObjectPtr result; + + context = xmlXPathNewContext (doc); + result = xmlXPathEvalExpression (BAD_CAST xpath, context); + if (xmlXPathNodeSetIsEmpty (result->nodesetval)) + { + /* no result */ + return NULL; + } + + xmlXPathFreeContext (context); + return result; } int -soap_xpath_foreach(xmlDocPtr doc, const char *xpath, - soap_xmlnode_callback cb, void *userdata) +soap_xpath_foreach (xmlDocPtr doc, const char *xpath, + soap_xmlnode_callback cb, void *userdata) { - int i = 0; - xmlNodeSetPtr nodeset; - xmlXPathObjectPtr xpathobj; + int i = 0; + xmlNodeSetPtr nodeset; + xmlXPathObjectPtr xpathobj; - xpathobj = soap_xpath_eval(doc, xpath); + xpathobj = soap_xpath_eval (doc, xpath); - if (!xpathobj) return 0; + if (!xpathobj) + return 0; - nodeset = xpathobj->nodesetval; - if (!nodeset) return 0; + nodeset = xpathobj->nodesetval; + if (!nodeset) + return 0; - for (i=0;i < nodeset->nodeNr; i++) { - if (!cb(nodeset->nodeTab[i], userdata)) - break; - } + for (i = 0; i < nodeset->nodeNr; i++) + { + if (!cb (nodeset->nodeTab[i], userdata)) + break; + } - xmlXPathFreeObject((xmlXPathObjectPtr)nodeset); - return i; + xmlXPathFreeObject ((xmlXPathObjectPtr) nodeset); + return i; } -void soap_xml_doc_print(xmlDocPtr doc) +void +soap_xml_doc_print (xmlDocPtr doc) { - xmlBufferPtr buffer; - xmlNodePtr root; + xmlBufferPtr buffer; + xmlNodePtr root; - if (doc == NULL) { - puts("xmlDocPtr is NULL!"); - return; - } + if (doc == NULL) + { + puts ("xmlDocPtr is NULL!"); + return; + } - root = xmlDocGetRootElement(doc); - if (root == NULL) { - puts("Empty document!"); - return; - } + root = xmlDocGetRootElement (doc); + if (root == NULL) + { + puts ("Empty document!"); + return; + } - buffer = xmlBufferCreate(); - xmlNodeDump(buffer, doc, root, 1 ,0); - puts( (const char*)xmlBufferContent(buffer)); - xmlBufferFree(buffer); + buffer = xmlBufferCreate (); + xmlNodeDump (buffer, doc, root, 1, 0); + puts ((const char *) xmlBufferContent (buffer)); + xmlBufferFree (buffer); } -char *soap_xml_get_text(xmlNodePtr node) +char * +soap_xml_get_text (xmlNodePtr node) { - return (char*)xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1); + return (char *) xmlNodeListGetString (node->doc, node->xmlChildrenNode, 1); } - diff --git a/libcsoap/soap-xml.h b/libcsoap/soap-xml.h index 5c0a599..de11e2d 100644 --- a/libcsoap/soap-xml.h +++ b/libcsoap/soap-xml.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-xml.h,v 1.5 2004/10/15 13:34:02 snowdrop Exp $ + * $Id: soap-xml.h,v 1.6 2006/01/10 11:21:55 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -29,21 +29,20 @@ #include <nanohttp/nanohttp-common.h> -typedef int (*soap_xmlnode_callback)(xmlNodePtr, void*); +typedef int (*soap_xmlnode_callback) (xmlNodePtr, void *); -xmlNodePtr soap_xml_get_children(xmlNodePtr param); -xmlNodePtr soap_xml_get_next(xmlNodePtr param); +xmlNodePtr soap_xml_get_children (xmlNodePtr param); +xmlNodePtr soap_xml_get_next (xmlNodePtr param); -xmlXPathObjectPtr -soap_xpath_eval(xmlDocPtr doc, const char *xpath); +xmlXPathObjectPtr soap_xpath_eval (xmlDocPtr doc, const char *xpath); int -soap_xpath_foreach(xmlDocPtr doc, const char *xpath, - soap_xmlnode_callback cb, void* userdata); +soap_xpath_foreach (xmlDocPtr doc, const char *xpath, + soap_xmlnode_callback cb, void *userdata); -void soap_xml_doc_print(xmlDocPtr doc); -char *soap_xml_get_text(xmlNodePtr node); +void soap_xml_doc_print (xmlDocPtr doc); +char *soap_xml_get_text (xmlNodePtr node); #endif |