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() --- libcsoap/soap-client.c | 13 +------------ libcsoap/soap-client.h | 6 +----- libcsoap/soap-ctx.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- libcsoap/soap-ctx.h | 21 ++++++++++++++++++++- 4 files changed, 67 insertions(+), 19 deletions(-) (limited to 'libcsoap') 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); /* -- cgit v1.1-32-gdbae