This module defines functions to set and get MIME/MTOM attachments.
More...
|
| int | soap_set_mime_attachment (struct soap *soap, const char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description) |
| | Add a MIME attachment to the SOAP/XML message.
|
| int | soap_set_mime (struct soap *soap, const char *boundary, const char *start) |
| | Enable MIME attachments.
|
| void | soap_clr_mime (struct soap *soap) |
| | Disable MIME attachments.
|
| int | soap_post_check_mime_attachments (struct soap *soap) |
| | Enable post-processing of MIME/MTOM attachments.
|
| int | soap_check_mime_attachments (struct soap *soap) |
| | Check for a MIME/MTOM attachment.
|
| struct soap_multipart * | soap_recv_mime_attachment (struct soap *soap, void *handle) |
| | Get a MIME/MTOM attachment.
|
This module defines functions to set and get MIME/MTOM attachments.
To enable MIME or MTOM, first initialize the soap context with #SOAP_ENC_MIME (for MIME) or #SOAP_ENC_MTOM (for MTOM) using ::soap_new1, soap_init1, soap_set_mode, or soap_set_mime to enable MIME and also to set a start id. To disable MIME use soap_clr_mime.
There are two ways to add MIME/MTOM attachments to SOAP/XML messages for sending:
- use soap_set_mime_attachment to explicitly add an attachment that contains the specified source of data;
- use xsd__base64Binary (MIME and MTOM) or _xop__Include (MTOM) structures in the serializable data of a SOAP/XML message, where the specified data is serialized in MIME/MTOM attachments automatically when one of the id, type or options member variables are non-NULL.
Both methods also support streaming MIME attachments to send using the soap::fmimereadopen, soap::fmimeread, and soap::fmimereadclose callbacks that fetch the data to send, where a user-defined handle should be specified for the ptr parameter of soap_set_mime_attachment or the xsd__base64Binary::__ptr member variable instead of a pointer to the actual data. This handle can be used by the callbacks to fetch the specific data to transmit.
Receiving MIME/MTOM attachments attached to SOAP/XML messages is automatic. The MIME/MTOM attachments are converted to binary data and stored in the xsd__base64Binary structures that reference the MIME/MTOM attachments via the xsd__base64Binary::id string, meaning that the xsd__base64Binary::__ptr (points to the data) and xsd__base64Binary::__size (data length) are populated automatically with the MIME/MTOM binary data. However, if the streaming MIME callbacks soap::fmimewriteopen, soap::fmimewrite, and soap::fmimewriteclose are defined then the attachments are streamed to these callbacks instead.
For example, to send and receive a SOAP/XML message with MIME attachments using a serializable xsd__base64Binary structure:
};
XSD base64Binary structure with attachment data.
Definition stdsoap2.h:10034
char * options
extra member: DIME options or a description of the MIME attachment or NULL
Definition stdsoap2.h:10039
char * id
extra member: NULL to generate an id or assign this member variable a unique UUID
Definition stdsoap2.h:10037
unsigned char * __ptr
pointer to binary data
Definition stdsoap2.h:10035
int __size
size of the binary data
Definition stdsoap2.h:10036
char * type
extra member: MIME type of the data
Definition stdsoap2.h:10038
#include "soapH.h"
int main()
{
data.__size = ...;
data.type = "image/jpg";
data.options = "A picture";
if (soap_call_ns__webmethod(
soap, endpoint, NULL, &data, &result))
else
...
}
*Delete all dynamically allocated C objects managed by the specified ::soap context void soap_destroy(struct soap *soap)
*Copy a string to managed memory char * soap_strdup(struct soap *soap, const char *string) * @returns copy of string or NULL when the specified string is NULL or on failure to allocate(out of memory)
*Delete all data from heap memory managed by the specified ::soap context and release the freed memory back to the heap void soap_end(struct soap *soap)
*Finalize and free the given ::soap context from unmanaged heap memory void soap_free(struct soap *soap)
void soap_print_fault(struct soap *soap, FILE *fd)
Print error message on the specified output.
const char * soap_rand_uuid(struct soap *soap, const char *prefix)
Returns a randomized unique UUID string.
Context with the engine state.
Definition stdsoap2.h:2929
#include "soapH.h"
int main()
{
...
}
{
retult->type = data->
type;
}
#define SOAP_OK
The soap_status code for no error (zero).
Definition stdsoap2.h:2392
To send MIME attachments without SOAP/XML (i.e. with REST methods), simply add attachments with soap_set_mime_attachment. The soap_end_send function then adds the attachments before finalizing the message transmission. To receive MIME attachments without SOAP/XML (i.e. with REST methods), simply call soap_begin_recv (not needed at the server side since this is already called to parse the HTTP header) and soap_end_recv.
For example a client-side multipart-related POST operation that sends a multipart-related message with one MIME attachment and receives a message consisting of multipart-related MIME attachments:
#include "soapH.h"
int main()
{
const char *ptr = "<attached>Some attached text</attached>";
size_t size = strlen(ptr);
{
}
else
{
int n = 0;
{
++n;
printf("Part %d:\n", n);
printf(
"ptr =%p\n", attachment->
ptr);
printf(
"size =%ul\n", attachment->
size);
printf(
"id =%s\n", attachment->
id ? attachment->
id :
"");
printf(
"type =%s\n", attachment->
type ? attachment->
type :
"");
}
}
}
*Initialize the context for receiving int soap_begin_recv(struct soap *soap) * @returns `
*HTTP POST content to server int soap_POST(struct soap *soap, const char *endpoint, const char *action, const char *type) * @returns `
*Send a string int soap_send(struct soap *soap, const char *s) * @returns `
*Finalize the context after receiving int soap_end_recv(struct soap *soap) * @returns `
*Finalize the context after sending int soap_end_send(struct soap *soap) * @returns `
int soap_set_mime_attachment(struct soap *soap, const char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description)
Add a MIME attachment to the SOAP/XML message.
void soap_clr_mime(struct soap *soap)
Disable MIME attachments.
int soap_set_mime(struct soap *soap, const char *boundary, const char *start)
Enable MIME attachments.
@ SOAP_MIME_NONE
no encoding, raw data content (recommended)
Definition stdsoap2.h:10421
struct soap_multipart * list
list of MIME attachments received
Definition stdsoap2.h:10617
DIME/MIME/MTOM attachment data received by the engine.
Definition stdsoap2.h:10627
const char * type
DIME/MIME/MTOM type (MIME type format).
Definition stdsoap2.h:10632
struct soap_multipart * next
next attachment in the linked list
Definition stdsoap2.h:10628
const char * ptr
points to raw data content
Definition stdsoap2.h:10629
const char * description
MIME Content-Description (optional).
Definition stdsoap2.h:10636
const char * id
DIME/MIME/MTOM content ID or form data name.
Definition stdsoap2.h:10631
const char * location
MIME Content-Location (optional).
Definition stdsoap2.h:10635
size_t size
size of data content
Definition stdsoap2.h:10630
*MIME attachments received struct soap_mime mime
Definition stdsoap2.h:4314
In C++ you can use an iterator for the last part of this example:
...
int n = 0;
{
++n;
printf("Part %d:\n", n);
printf("ptr =%p\n", i->ptr);
...
}
soap_multipart::iterator begin()
C++ only: an iterator over soap_multipart attachments.
soap_multipart::iterator end()
C++ only: an iterator over soap_multipart attachments.
soap_multipart_iterator iterator
C++ only: an iterator over soap_multipart attachments.
Definition stdsoap2.h:10638
At the server side the code to retrieve the REST message sent consisting of a set of multipart-related MIME attachments is the same. To respond with multipart-related MIME attachments use soap_set_mime and use soap_set_mime_attachment to add attachments. For example:
#include "soapH.h"
int main()
{
...
}
{
const char *ptr = "<attached>Some attached text</attached>";
size_t size = strlen(ptr);
return soap_closesock(
soap);
}
*Callback to implement logic at the server side to serve responses to HTTP GET requests from clients int(* fget)(struct soap *soap)
Definition stdsoap2.h:4455
#define SOAP_FILE
A special soap_status error code to signal that a custom file-based HTTP response is present and no H...
Definition stdsoap2.h:2842
*Initialize the context for server side sending and send a HTTP response header int soap_response(struct soap *soap, int status) * @returns `
const char * http_content
String with HTTP content type header value received, can also be assigned to specify a content type h...
Definition stdsoap2.h:3105
To disable MIME again, use soap_clr_mime.
◆ soap_mime_encoding
RFC2045 MIME content transfer encodings.
These values are used by the soap_set_mime_attachment function parameter encoding.
- Warning
- You are responsible to ensure that the MIME/MTOM content conforms to the encoding specified. We recommend #SOAP_MIME_NONE to transmit any data of any type which is usually the purpose of MIME/MTOM attachments to SOAP/XML.
- See also
- soap_set_mime_attachment.
| Enumerator |
|---|
| SOAP_MIME_NONE | no encoding, raw data content (recommended)
|
| SOAP_MIME_7BIT | 7 bit data content
|
| SOAP_MIME_8BIT | 8 bit data content
|
| SOAP_MIME_BINARY | binary raw data content
|
| SOAP_MIME_QUOTED_PRINTABLE | data is formatted as quoted printable
|
| SOAP_MIME_BASE64 | data is formatted in base64
|
| SOAP_MIME_IETF_TOKEN | data is an IETF token
|
| SOAP_MIME_X_TOKEN | data is an X-token
|
◆ soap_check_mime_attachments()
| int soap_check_mime_attachments |
( |
struct soap * | soap | ) |
|
Check for a MIME/MTOM attachment.
This function checks the presence of a MIME/MTOM attachment after calling a service operation by returning nonzero when attachments are present. Returns nonzero if attachments are present. Requires soap_post_check_mime_attachments.
- See also
- soap_post_check_mime_attachments.
- Returns
- nonzero if MIME/MTOM attachments are present
- Parameters
-
◆ soap_clr_mime()
| void soap_clr_mime |
( |
struct soap * | soap | ) |
|
◆ soap_post_check_mime_attachments()
| int soap_post_check_mime_attachments |
( |
struct soap * | soap | ) |
|
Enable post-processing of MIME/MTOM attachments.
This function enables post-processing of MTOM/MIME attachments attached to a message and is useful when MIME/MTOM are streamed (asynchronously) by configuring the callbacks ::fmimewriteopen, soap::fmimewrite, and soap::fmimewriteclose to write the attachment to memory, file or, other resources. By calling this function, the presence of MIME/MTOM attachments must be explicitly checked after each message is received by calling soap_check_mime_attachments. When this function returns nonzero (true), soap_recv_mime_attachment must be called repeatedly to retrieve each attachment until this function returns NULL indicating the end of attachments and the channel is closed, or if an error occurred with soap::error set to a nonzero soap_status error code.
If attachments are not referenced by the SOAP/XML message received, then normallly an error will be produced to indicate that attachments exist that were not converted into binary xsd__base64Binary or _xop__Include structures (i.e. deserialized from the message by resolving references to MIME/MTOM attachments). This error can be avoided by using soap_post_check_mime_attachments to indicate that attachments may appear that cannot be automatically resolved and should be handled explicitly by calling soap_check_mime_attachments and soap_recv_mime_attachment.
- Examples:
#include "soapH.h"
int main()
{
if (soap_call_ns__webmethod(
soap, ...))
{
}
else
{
{
int n = 0;
do
{
++n;
printf("Part %d:\n", n);
printf(
"ptr =%p\n", attachment->
ptr);
printf(
"size =%ul\n", attachment->
size);
printf(
"id =%s\n", attachment->
id ? attachment->
id :
"");
printf(
"type =%s\n", attachment->
type ? attachment->
type :
"");
} while (attachment);
}
}
}
struct soap_multipart * soap_recv_mime_attachment(struct soap *soap, void *handle)
Get a MIME/MTOM attachment.
int soap_post_check_mime_attachments(struct soap *soap)
Enable post-processing of MIME/MTOM attachments.
int soap_check_mime_attachments(struct soap *soap)
Check for a MIME/MTOM attachment.
int error
The soap context soap_status (int) error code of the last operation or #SOAP_OK (zero).
Definition stdsoap2.h:3045
#include "soapH.h"
int main()
{
if (soap_call_ns__webmethod(
soap, ...))
{
}
else
{
{
int n = 0;
do
{
handle = ...;
++n;
printf("Part %d:\n", n);
printf("ptr =%p\n", attachment->ptr);
printf("size =%ul\n", attachment->size);
printf("id =%s\n", attachment->id ? attachment->id : "");
printf("type =%s\n", attachment->type ? attachment->type : "");
printf("location =%s\n", attachment->location ? attachment->location : "");
printf("description=%s\n", attachment->description ? attachment->description : "");
} while (attachment);
}
}
}
*Callback to open a streaming MIME MTOM attachment for writing void *(* fmimewriteopen)(struct soap *soap, void *handle, const char *id, const char *type, const char *description, enum soap_mime_encoding encoding)
Definition stdsoap2.h:5138
*Callback to close a MIME MTOM attachment stream after writing void(* fmimewriteclose)(struct soap *soap, void *handle)
Definition stdsoap2.h:5160
*Callback to write data in a MIME attachment stream int(* fmimewrite)(struct soap *soap, void *handle, const char *buf, size_t len)
Definition stdsoap2.h:5149
- Warning
- When soap_post_check_mime_attachments is used, every message received must be followed by a call to soap_check_mime_attachments. When this function returns nonzero, soap_check_mime_attachments must be called repeatedly until this function returns NULL. This sequence of calls is necessary to properly handle messages with and without attachments. The connection is closed if HTTP keep-alive is not enabled. With HTTP keep-alive enabled, this sequence of calls allows the next message to be properly received.
- See also
- soap_check_mime_attachments, soap_recv_mime_attachment, soap::fmimewriteopen, soap::fmimewrite, soap::fmimewriteclose.
- Returns
- #SOAP_OK or a soap_status error code
- Parameters
-
◆ soap_recv_mime_attachment()
Get a MIME/MTOM attachment.
This function parses an attachment and invokes the MIME callbacks when set. The handle parameter is passed to fmimewriteopen. The handle may contain any data that is extracted from the SOAP message body to guide the redirection of the stream in the callbacks. Returns a struct with a char *ptr member that contains the handle value returned by the fmimewriteopen callback, and char *id, char *type, and char *description member variables with the MIME id, type, and description info when present in the attachment.
- See also
- soap_post_check_mime_attachments, soap_check_mime_attachments.
- Returns
- MIME attachment data or NULL if no more attachments were found
- Parameters
-
| soap | soap context |
| handle | a handle to pass to the callbacks |
◆ soap_set_mime()
| int soap_set_mime |
( |
struct soap * | soap, |
|
|
const char * | boundary, |
|
|
const char * | start ) |
Enable MIME attachments.
This function enables sending MIME attachments. This function is generally not required when the context is initialized with #SOAP_ENC_MIME, because MIME attachments are automatically detected as xsd__base64Binary and _xop__Include structures in the data to serialize as an XML message with the attachments automatically added or MIME attachments can be explicitly added with soap_set_mime_attachment. Parameter boundary specifies a MIME boundary string or NULL to have the engine generate a MIME boundary string. Parameter start specifiesthe start content ID for the first MIME body containing the SOAP or XML message. When NULL, the start ID of the SOAP message is <SOAP-ENV:Envelope>.
- See also
- soap_set_mime_attachment, soap_clr_mime, #SOAP_ENC_MIME, #SOAP_ENC_MTOM.
- Parameters
-
| soap | soap context |
| boundary | MIME boundary string to use or NULL to generate a random boundary |
| start | string id of the first MIME attachment with the SOAP/XML message or NULL |
◆ soap_set_mime_attachment()
| int soap_set_mime_attachment |
( |
struct soap * | soap, |
|
|
const char * | ptr, |
|
|
size_t | size, |
|
|
enum soap_mime_encoding | encoding, |
|
|
const char * | type, |
|
|
const char * | id, |
|
|
const char * | location, |
|
|
const char * | description ) |
Add a MIME attachment to the SOAP/XML message.
This function adds a MIME attachment to a SOAP/XML message to send. The specified ptr points to the data to send of length specified by size. The encoding parameter is a soap_mime_encoding value that is recommended to be specified as #SOAP_MIME_NONE to specify that the MIME data content is not encoded in any way (the MIME attachment function simply copies the raw data to the MIME block without encoding). The type parameter is required and indicates the MIME type of the data, such as "image/jpg". The id parameter uniquely identifies the attachment in the message, which can be omitted by specifying NULL. The location parameter specifies a location string or NULL. The description parameter is a string that describes the data or NULL. Returns #SOAP_OK or a soap_status error code.
There are two ways to add MIME/MTOM attachments to SOAP/XML:
- use soap_set_mime_attachment to explicitly add an attachment that contains the specified source of data;
- use xsd__base64Binary or _xop__Include structures in the serializable data of a SOAP/XML message, where the specified data is serialized in MIME/MTOM attachments automatically when one of the id, type or options member variables are non-NULL. This option requires #SOAP_ENC_MIME or #SOAP_ENC_MTOM.
Both methods support streaming MIME/MTOM attachments, where a user-defined handle instead of the actual data is specified for the ptr parameter or the __ptr member variable.
- Example:
#include "soapH.h"
const char *data = ...;
size_t size = ...;
{
exit(EXIT_FAILURE);
}
else
{
...
}
#define SOAP_IO_CHUNK
soap_mode IO output flag value to send HTTP chunked messages, buffers the message in packets of size ...
Definition stdsoap2.h:1672
int errnum
The errno value of the last failed IO operation.
Definition stdsoap2.h:3052
ULONG64 recv_maxlength
User-definable maximum message length that is permitted to be received, zero means unlimited (the val...
Definition stdsoap2.h:3267
int send_timeout
User-definable timeout to send a packet of data, positive timeout values are seconds,...
Definition stdsoap2.h:3309
char endpoint[SOAP_TAGLEN]
The endpoint URL as received on the server side.
Definition stdsoap2.h:4143
int connect_timeout
User-definable timeout when waiting to connect to a server at the client-side, positive timeout value...
Definition stdsoap2.h:3384
int transfer_timeout
User-definable timeout to send or receive an entire message, positive timeout values are seconds,...
Definition stdsoap2.h:3281
- See also
- xsd__base64Binary, _xop__Include, soap_rand_uuid, soap::fmimereadopen, soap::fmimeread, soap::fmimereadclose.
- Returns
- #SOAP_OK or a soap_status error code
- Parameters
-
| soap | soap context |
| ptr | pointer to data |
| size | length of the data |
| encoding | encoding of the data |
| type | MIME type of the data |
| id | content ID of the data or NULL |
| location | location of the data or NULL |
| description | description of the data or NULL |