From c28397f760d22a1e8be126725ff7784b2d8fec23 Mon Sep 17 00:00:00 2001 From: snowdrop Date: Mon, 1 Nov 2004 15:16:22 +0000 Subject: added soap_ctx_add_file() --- examples/csoap/echoattachments-client.c | 7 +++-- examples/csoap/echoattachments-server.c | 32 +-------------------- examples/csoap/simpleclient.c | 4 +-- libcsoap/soap-client.c | 13 +-------- libcsoap/soap-client.h | 6 +--- libcsoap/soap-ctx.c | 46 +++++++++++++++++++++++++++++- libcsoap/soap-ctx.h | 21 +++++++++++++- nanohttp/nanohttp-common.h | 50 +++++++++++++++++---------------- nanohttp/nanohttp-mime.c | 9 ++++-- 9 files changed, 108 insertions(+), 80 deletions(-) diff --git a/examples/csoap/echoattachments-client.c b/examples/csoap/echoattachments-client.c index 0f62fa7..a6dfca7 100755 --- a/examples/csoap/echoattachments-client.c +++ b/examples/csoap/echoattachments-client.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: echoattachments-client.c,v 1.5 2004/10/29 09:27:02 snowdrop Exp $ + * $Id: echoattachments-client.c,v 1.6 2004/11/01 15:16:22 snowdrop Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -96,6 +96,8 @@ int main(int argc, char *argv[]) char href[MAX_HREF_SIZE]; xmlNodePtr fault; herror_t err; + + if (argc < 2) { fprintf(stderr, "usage: %s [url]\n", argv[0]); @@ -110,7 +112,7 @@ int main(int argc, char *argv[]) return 1; } - err = soap_client_ctx_new(urn, method, &ctx); + err = soap_ctx_new_with_method(urn, method, &ctx); if (err != H_OK) { log_error4("[%d] %s():%s ", herror_code(err), herror_func(err), herror_message(err)); herror_release(err); @@ -121,6 +123,7 @@ int main(int argc, char *argv[]) soap_ctx_free(ctx); exit(1); } + soap_env_add_attachment(ctx->env,"source", href); printf("sending request ...\n"); diff --git a/examples/csoap/echoattachments-server.c b/examples/csoap/echoattachments-server.c index 5aeeb76..22b5fb2 100755 --- a/examples/csoap/echoattachments-server.c +++ b/examples/csoap/echoattachments-server.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: echoattachments-server.c,v 1.3 2004/10/28 10:30:42 snowdrop Exp $ + * $Id: echoattachments-server.c,v 1.4 2004/11/01 15:16:22 snowdrop Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -29,37 +29,7 @@ static const char *urn = "urn:examples"; static const char *method = "echo"; -/* -SoapCtx* echo_attachments(SoapCtx *req) -{ - herror_t err; - SoapEnv *env; - SoapCtx* ctx; - part_t *part; - char href[MAX_HREF_SIZE]; - - err = soap_env_new_with_response(req->env, &env); - if (err != H_OK) { - herror_release(err); - return NULL; - } - - ctx = soap_ctx_new(env); - - if (req->attachments) { - part = req->attachments->parts; - while (part) { - log_verbose2("Adding part '%s'", part->filename); - soap_ctx_add_file(ctx, part->filename, "text/plain", href); - soap_env_add_attachment(ctx->env, "echoFile", href); - part = part->next; - } - } - - return ctx; -} -*/ herror_t echo_attachments(SoapCtx *req, SoapCtx* res) { diff --git a/examples/csoap/simpleclient.c b/examples/csoap/simpleclient.c index 7b80193..ea9dcac 100644 --- a/examples/csoap/simpleclient.c +++ b/examples/csoap/simpleclient.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: simpleclient.c,v 1.6 2004/10/28 10:30:42 snowdrop Exp $ + * $Id: simpleclient.c,v 1.7 2004/11/01 15:16:22 snowdrop Exp $ * * CSOAP Project: CSOAP examples project * Copyright (C) 2003-2004 Ferhat Ayaz @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) return 1; } - err = soap_client_ctx_new(urn, method, &ctx); + err = soap_ctx_new_with_method(urn, method, &ctx); if (err != H_OK) { log_error4("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err)); herror_release(err); diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c index 160b255..21eb06a 100644 --- a/libcsoap/soap-client.c +++ b/libcsoap/soap-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-client.c,v 1.11 2004/10/29 09:27:05 snowdrop Exp $ +* $Id: soap-client.c,v 1.12 2004/11/01 15:16:26 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -251,14 +251,3 @@ herror_t } -herror_t soap_client_ctx_new(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); - - return H_OK; -} - diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h index 22e41bb..6826117 100644 --- a/libcsoap/soap-client.h +++ b/libcsoap/soap-client.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-client.h,v 1.6 2004/10/28 10:30:46 snowdrop Exp $ + * $Id: soap-client.h,v 1.7 2004/11/01 15:16:26 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -50,10 +50,6 @@ herror_t soap_client_invoke(SoapCtx *ctx, SoapCtx** response, const char *soap_action); -/** - Creates a new soap context object. -*/ -herror_t soap_client_ctx_new(const char *urn, const char *method, SoapCtx **out); /** Sets the underlaying socket to use while connecting diff --git a/libcsoap/soap-ctx.c b/libcsoap/soap-ctx.c index 944abf0..423bcfe 100755 --- a/libcsoap/soap-ctx.c +++ b/libcsoap/soap-ctx.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-ctx.c,v 1.2 2004/10/28 10:30:46 snowdrop Exp $ + * $Id: soap-ctx.c,v 1.3 2004/11/01 15:16:26 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003-2004 Ferhat Ayaz @@ -75,6 +75,39 @@ herror_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* conte return H_OK; } +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) 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) { @@ -89,3 +122,14 @@ void soap_ctx_free(SoapCtx* ctx) } +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); + + return H_OK; +} + diff --git a/libcsoap/soap-ctx.h b/libcsoap/soap-ctx.h index 0aa8520..a55f18f 100755 --- a/libcsoap/soap-ctx.h +++ b/libcsoap/soap-ctx.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-ctx.h,v 1.3 2004/10/29 09:27:05 snowdrop Exp $ + * $Id: soap-ctx.h,v 1.4 2004/11/01 15:16:26 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003-2004 Ferhat Ayaz @@ -28,6 +28,10 @@ #include #include + +#define SOAP_ERROR_NO_FILE_ATTACHED 4001 +#define SOAP_ERROR_EMPTY_ATTACHMENT 4002 + #define MAX_HREF_SIZE 150 typedef struct _SoapCtx @@ -39,6 +43,21 @@ typedef struct _SoapCtx SoapCtx* soap_ctx_new(SoapEnv *env); /* should only be used internally */ +/** + Returns the attached file if any found. + @param ctx the SoapCtx object which should contain the part + @param node the xml node which points to a file via the "href" xml attribute + + @returns a part_t object of attachment was found, NULL otherwise. + +*/ +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); + /* 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); /* diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h index 1d89d30..e633ab4 100644 --- a/nanohttp/nanohttp-common.h +++ b/nanohttp/nanohttp-common.h @@ -1,25 +1,25 @@ -/****************************************************************** - * $Id: nanohttp-common.h,v 1.15 2004/10/29 09:27:05 snowdrop Exp $ - * - * CSOAP Project: A http client/server library in C - * Copyright (C) 2003-2004 Ferhat Ayaz - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Email: ferhatayaz@yahoo.com +/****************************************************************** + * $Id: nanohttp-common.h,v 1.16 2004/11/01 15:16:26 snowdrop Exp $ + * + * CSOAP Project: A http client/server library in C + * Copyright (C) 2003-2004 Ferhat Ayaz + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Email: ferhatayaz@yahoo.com ******************************************************************/ #ifndef NANO_HTTP_COMMON_H #define NANO_HTTP_COMMON_H @@ -29,7 +29,8 @@ #define HEADER_CONTENT_LENGTH "Content-Length" #define HEADER_CONTENT_TYPE "Content-Type" -#define HEADER_CONTENT_ID "Content-Id" +#define HEADER_CONTENT_ID "Content-Id" +#define HEADER_CONTENT_LOCATION "Content-Location" #define HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding" #define HEADER_TRANSFER_ENCODING "Transfer-Encoding" #define HEADER_CONNECTION "Connection" @@ -412,7 +413,8 @@ void content_type_free(content_type_t *ct); */ typedef struct _part { - char id[250]; + char id[250]; + char location[250]; hpair_t *header; char content_type[128]; char transfer_encoding[128]; diff --git a/nanohttp/nanohttp-mime.c b/nanohttp/nanohttp-mime.c index 5b8a5f4..2089348 100755 --- a/nanohttp/nanohttp-mime.c +++ b/nanohttp/nanohttp-mime.c @@ -3,7 +3,7 @@ * | \/ | | | | \/ | | _/ * |_''_| |_| |_''_| |_'/ PARSER * -* $Id: nanohttp-mime.c,v 1.4 2004/10/29 09:27:05 snowdrop Exp $ +* $Id: nanohttp-mime.c,v 1.5 2004/11/01 15:16:26 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003-2004 Ferhat Ayaz @@ -664,7 +664,7 @@ static void _mime_received_bytes(void *data, const unsigned char* bytes, int size) { int i=0; - char *id, *type; + char *id, *type, *location; mime_callback_data_t *cbdata = (mime_callback_data_t*)data; if (!cbdata ) { @@ -737,6 +737,11 @@ void _mime_received_bytes(void *data, const unsigned char* bytes, int size) if (!strcmp(id, cbdata->root_id)) cbdata->message->root_part = cbdata->current_part; } + location = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_LOCATION); + if (location != NULL) + { + strcpy(cbdata->current_part->location, location); + } type = hpairnode_get(cbdata->current_part->header, HEADER_CONTENT_TYPE); if (type != NULL) { -- cgit v1.1-32-gdbae