Home

Traffic Server Software Developers Kit

MIIME Headers

MIME headers and fields can be components of request headers, response headers, or standalone headers created within your plugin. Make sure you call the MIME header functions appropriately. For example: if you want to clone a MIME header field within a request header, then call INKMimeHdrFieldClone after READ_REQUEST_HDR_HOOK.

The Traffic Server MIME header functions are described below.

INKMimeHdrFieldAppend

Appends a field in a MIME header.

Prototype

INKReturnCode INKMimeHdrFieldAppend (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field)

Description

Appends the MIME field located at field within the marshal buffer bufp into the MIME header located at url_loc within the marshal buffer bufp.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldClone

Copies a MIME field to a marshal buffer and returns the INKMLoc location of the copied field.

Prototype

INKMLoc INKMimeHdrFieldClone (INKMBuffer dest_bufp, INKMLoc dest_hdr, INKMBuffer src_bufp, INKMLoc src_hdr, INKMLoc src_field)

Description

Copies the contents of the MIME field located at src_field within the marshal buffer src_bufp to a MIME header located at dest_hdr within the marshal buffer dest_bufp.

Returns

The INKMLoc location of the copied field. Release the returned handle with a call to INKHandleMLocRelease.

INK_ERROR_PTR if an error occurs.

INKMimeHdrFieldCopy

Copies a MIME field from one specified location to another specified location.

Prototype

INKReturnCode INKMimeHdrFieldCopy (INKMBuffer dest_bufp, INKMLoc dest_hdr, INKMLoc dest_field, INKMBuffer src_bufp, INKMLoc src_hdr, INKMLoc src_field)

Description

Copies the contents of the MIME field located at src_field within the marshal buffer src_bufp to the MIME field located at dest_field within the marshal buffer dest_bufp. INKMimeHdrFieldCopy works correctly even if src_bufp and dest_bufp point to different marshal buffers.

[Note] Note

You must first create the destination MIME field before you can copy into it.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldCopyValues

Copies MIME field values from one location to another.

Prototype

INKReturnCode INKMimeHdrFieldCopyValues (INKMBuffer dest_bufp, INKMLoc dest_hdr, INKMLoc dest_field, INKMBuffer src_bufp, INKMLoc src_hdr, INKMLoc src_field)

Description

Copies the values contained within the MIME field located at src_field within the marshal buffer src_bufp to the MIME field located at dest_field within the marshal buffer dest_bufp. INKMimeHdrFieldCopyValues works correctly even if src_bufp and dest_bufp point to different marshal buffers. INKMimeHdrFieldCopyValues does not copy the field’s name.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldCreate

Creates a new MIME field within a specified marshal buffer.

Prototype

INKMLoc INKMimeHdrFieldCreate (INKMBuffer bufp, INKMLoc hdr)

Description

Creates a new MIME field with the marshal buffer bufp.

Returns

The location of the new MIME field. Release with a call to INKHandleMLocRelease.

INKMimeHdrFieldDestroy

Deletes a specified MIME field from a marshal buffer.

Prototype

void INKMimeHdrFieldDestroy (INKMBuffer bufp, INKMLoc hdr, INKMLoc field)

Description

Destroys the MIME field located at field within the MIME header located at hdr within the marshal buffer bufp.

After the call to INKMimeHdrFieldDestroy, you must release the INKMLoc handle field with a call to INKHandleMLocRelease.

INKMimeHdrFieldLengthGet

Calculates the length of a string representation in a specified MIME field.

Prototype

int INKMimeHdrFieldLengthGet (INKMBuffer bufp, INKMLoc hdr, INKMLoc field)

Description

Calculates the length of the MIME field located at field within the marshal buffer bufp if it was returned as a string. This is the length of the MIME field in its unparsed form.

Returns

The calculated length of a string representation of the specified MIME field.

INK_ERROR if there is an error.

INKMimeHdrFieldNameGet

Gets the name and name length of a specified MIME field.

Prototype

const char* INKMimeHdrFieldNameGet (INKMBuffer bufp, INKMLoc hdr, INKMLoc field, int *length)

Description

Returns the name of the field located at field within the marshal buffer bufp. INKMimeHdrFieldNameGet places the length of the returned string in the length argument.

Returns

A pointer to the name of the specified field within the specified MIME header. Release the returned string with a call to INKHandleStringRelease.

INK_ERROR_PTR if an error occurs.

[Note] Note

The returned string is not guaranteed to be null-terminated.

INKMimeHdrFieldNameSet

Sets the name for a specified MIME field.

Prototype

INKReturnCode INKMimeHdrFieldNameSet (INKMBuffer bufp, INKMLoc hdr, INKMLoc field, const char *name, int length)

Description

Sets the name of the field located at field within the marshal buffer bufp to the string name. If length is -1, then INKMimeHdrFieldNameSet assumes the name is null-terminated. Otherwise, the length of the string name is taken to be length. INKMimeHdrFieldNameSet copies the string to within bufp, so it is okay to modify or delete name after calling INKMimeHdrFieldNameSet. When possible, use the INK_MIME_FIELD_XXX tokens for name .

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldNext

Returns the next MIME field after a specified MIME field in a MIME header.

Prototype

INKMLoc INKMimeHdrFieldNext (INKMBuffer bufp, INKMLoc hdr, INKMLoc field)

Description

Conceptually, MIME fields are listed in a MIME header (see Guide to Traffic Server HTTP Header System). INKMimeHdrFieldNext returns the location of the next field in the list, after the field located at field within the marshal buffer bufp. If the next field is not found, then a NULL pointer is returned.

Returns

The location of the MIME field following the specified MIME field within the specified MIME header. Release the returned INKMLoc with a call to INKHandleMLocRelease (see the code example below).

INK_ERROR_PTR if an error occurs.

Example

An example of a loop through each MIME field of an HTTP header is featured below:

field_loc = INKMimeHdrFieldGet (hdr_bufp, hdr_loc, 0);
  while (field_loc) {
       /* Temp variable used only for the loop */
       INKMLoc next_field_loc;

       /* Do your job with the field here */

       /* Get the next field and release the current one */
       next_field_loc = INKMimeHdrFieldNext (hdr_bufp, hdr_loc, field_loc);
       INKHandleMLocRelease(hdr_bufp, hdr_loc, field_loc);
       field_loc = next_field_loc;
       }

INKMimeHdrFieldNextDup

Returns the next duplicate MIME field after a specified MIME field in a MIME header.

Prototype

INKMLoc INKMimeHdrFieldNextDup (INKMBuffer bufp, INKMLoc hdr, INKMLoc field)

Description

MIME headers can contain more than one MIME field with the same name. While previous versions of Traffic Server joined multiple fields with the same name into one field with composite values, this behavior comes at a performance cost and causes compatability issues with older clients and servers. Future versions of Traffic Server will cease coalescing duplicate fields.

Your plugins should check for the presence of duplicate fields and iterate over duplicate fields via INKMimeHdrFieldNextDup. INKMimeHdrFieldNextDup returns the location of the next duplicate field in the list after the field located at field within the marshal buffer bufp. If the next field is not found, then a NULL pointer is returned.

Returns

The location of the next duplicate MIME field that follows the specified field within the specified MIME header. Release with a call to INKHandleMLocRelease.

INK_ERROR_PTR if an error occurs.

INKMimeHdrFieldValueAppend

Appends a string to a specified value in a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueAppend (INKMBuffer bufp, INKMLoc hdr, INKMLoc field, int idx, const char *value, int length)

Arguments

bufp is the marshal buffer containing the MIME field.

hdr is the location of the parent object within the marshal buffer bufp from which field was retrieved.

field is the location of the MIME field to be appended.

idx is the index of the field value to be appended. For example: in the MIME field Foo: bar, car the index of the value bar is 0 and the index of car is 1.

value is the string that will be appended to the MIME field value at idx.

length is the length of the string value to be appended.

Description

Appends the string stored in value to a specific value in the MIME field located at field within the marshal buffer bufp. The effect of INKMimeHdrFieldValueAppend is as if the previous value was retrieved, the string value was appended to it, and this new string was stored back in the MIME field at the same position. The idx parameter specifies which value in the field to append to. If idx is not between 0 and INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1, then no operation is performed.

Returns

INK_SUCCESS if the string is successfully appended.

INK_ERROR if the hook is not added.

INKMimeHdrFieldValueDateGet

Gets the date value from a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueDateGet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, time_t *value)

Description

Retrieves a date value from within the MIME field located at field within the marshal buffer bufp. All values are stored as strings within the MIME field. INKMimeHdrFieldValueDateGet parses the string value to return an integer date representation.

Returns

The date value from the specified MIME header.

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueDateInsert

Inserts a date value into a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueDateInsert (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, time_t value)

Description

Inserts the date value into the MIME field located at field within the marshal buffer bufp. All values are stored as strings within the MIME field. INKMimeHdrFieldValueDateInsert simply formats the date into a string and then calls INKMimeHdrFieldValueInsert.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueDateSet

Sets a date value in a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueDateSet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, time_t value)

Description

Sets a value in the MIME field located at field within the marshal buffer bufp to the date value. All values are stored as strings within the MIME field. INKMimeHdrFieldValueDateSet simply formats the date into a string and then calls INKMimeHdrFieldValueStringSet.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueDelete

Deletes a specified value from a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldVcoalueDelete (INKMBuffer bufp, INKMLoc hdr, INKMLoc field, int idx)

Description

Removes and deletes a value from the MIME field located at field within the marshal buffer bufp. The idx parameter specifies which value should be deleted. If idx is not between 0 and INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1, then no operation is performed.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldValueIntGet

Gets an integer field value in a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueIntGet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int idx, int *value)

Description

Retrieves an integer value from within the MIME field located at field within the marshal buffer bufp . The idx parameter specifies which value within the field to retrieve. The fields are numbered from 0 to INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1. If idx does not lie within that range, then INKMimeHdrFieldValueIntGet returns (int) 0. All values are stored as strings within the MIME field; INKMimeHdrFieldValueIntGet parses the string value to return an integer.

Returns

The integer value from the specified MIME field.

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueIntInsert

Inserts an integer value into a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueIntInsert (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int value, int idx)

Description

Inserts the integer value into the MIME field located at field within the marshal buffer bufp. The idx parameter specifies where the inserted value should be placed with respect to the other values already in the MIME field. If idx is 0, then the value is prepended to the list of values in the field. Increasing values of idx places the value farther down the list of values. If idx is -1, then the value is appended to the list of values. Normal usage is to specify -1 for idx so that the value is appended to the list of values. All values are stored as strings within the MIME field. INKMimeHdrFieldValueIntInsert simply formats the integer into a string and then calls INKMimeHdrFieldValueInsert.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueIntSet

Sets an integer value within a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueIntSet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int idx, int value)

Description

Sets a value in the MIME field located at field within the marshal buffer bufp. The idx parameter specifies which value in the field to change. If idx is not between 0 and INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1, then no operation is performed. All values are stored as strings within the MIME field. INKMimeHdrFieldValueIntSet simply formats the integer into a string and then calls INKMimeHdrFieldValueSet.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueStringGet

Gets a specified field value from a MIME header.

Prototype

INKReturnCode INKMimeHdrFieldValueStringGet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int idx, const char **value, int *value_len)

Description

Retrieves a string value from within the MIME field within the marshal buffer bufp. The idx parameter specifies which field to retrieve. The fields are numbered from 0 to INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1. If idx does not lie within that range, then NULL is returned. The length of the returned string is placed in the value_len argument. If value_len is NULL, then no attempt is made to dereference it.

Returns

A pointer to the specified field value in the MIME header. Release with a call to INKHandleStringRelease.

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueStringInsert

Inserts a value into a specified location within a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueStringInsert (INKMBuffer bufp, INKMLoc hdr, INKMLoc field, int idx, const char *value, int length)

Description

Inserts the string value into the MIME field located at field within the marshal buffer bufp. If len is -1, then INKMimeHdrFieldValueStringInsert assumes that value is null-terminated. Otherwise, the length of the string value is taken to be length. INKMimeHdrFieldValueStringInsert copies the string to within bufp, so it is okay to modify or delete value after calling INKMimeHdrFieldValueStringSet. The idx parameter specifies where the inserted value should be placed with respect to the other values already in the MIME field. If idx is 0, then INKMimeHdrFieldValueStringInsert prepends the value to the list of values in the field. Increasing values of idx place the value farther down the list of values. If idx is -1, then INKMimeHdrFieldValueStringInsert appends the value to the list of values. Normal usage is to specify -1 for idx so that the value is appended to the list of values.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueStringSet

Sets a value in a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueStringSet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int idx, const char *value, int len)

Description

Sets a value in the MIME field located at field within the marshal buffer bufp to the string value. If len is -1, then it is assumed that value is null-terminated. Otherwise, the length of the string value is taken to be len. The string is copied to within bufp, so it is okay to modify or delete value after calling INKMimeHdrFieldValueStringSet. The idx parameter specifies which value in the field to change. If idx is not between 0 and INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1, then no operation will be performed. If idx is set to -1, then all the MIME field values are returned.

Example

Suppose the MIME field is MyField: value1, value2, value3. If INKMimeHdrFieldGet is called with idx set to -1, then it will return a pointer to “value1, value2, value3”.

[Note] Note

As with other MIME header manipulation APIs, the string is not null-terminated.

INKMimeHdrFieldValueUintGet

Gets an unsigned integer field value in a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueUintGet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int idx, unsigned int *value)

Description

Retrieves an unsigned integer value from within the MIME field located at field within the marshal buffer bufp. The idx parameter specifies which field to retrieve. The fields are numbered from 0 to INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1. If idx does not lie within that range, then INKMimeHdrFieldValueGetUnit returns (unsigned int) 0. All values are stored as strings within the MIME field. INKMimeHdrFieldValueUintGet parses the string value to return an unsigned integer.

It is not possible to determine if INKMimeHdrFieldValueUintGet is returning an unsigned int value in error. If you need to check for errors in MIME header field values, then you can fetch the header as a string and examine it (see the example below).

Returns

The unsigned integer value from the specified MIME field.

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

Example

The example below contains sample code that fetches MIME headers from marshal buffers into strings using INKMimeHdrFieldValueGet instead. The context of this example is that the plugin is processing an HTTP transaction and has access to a transaction.

static void
handle_string (INKHttpTxn txnp, INKCont contp) {
    INKMBuffer bufp;
    INKMLoc hdr_loc;
    INKMLoc field;
    int len;
    char* output_string;
    const char* value;
/* Fetch  the transaction's client request header into a marshal buffer. */
    if (!INKHttpTxnClientReqGet (txnp, &bufp, &hdr_loc)) { 
        INKError ("couldn't retrieve client request header\n"); 
        goto done;
    }
    field=INKMimeHdrFieldFind(bufp, hdr_loc, 
                                  INK_MIME_FIELD_CONTENT_LENGTH);
         
    if (!field) { 
        INKError ("Content-Length field not found.\n"); 
        INKHandleMLocRelease (bufp, INK_NULL_MLOC, hdr_loc);
        goto done;
    } 
    /* Obtain the value of the content length (normally an 
     * unsigned int) as a string. */
    value=INKMimeHdrFieldValueGet (bufp, hdr_loc, field, 0, &len); 
 
    if ((!value) || (len<=0))}
        INKHandleMLocRelease (bufp, hdr_loc, field);
        INKHandleMLocRelease (bufp, INK_NULL_MLOC, hdr_loc);
        goto done;
    }
    /* Allocate the string with an extra byte for the string terminator. */
    output_string = (char*) INKmalloc(len + 1);
         
    /* Copy the value. */
    strncpy (output_string, value, len);

    /* Terminate the string */
    output_string[len] = '\0';
/* Now that you have the MIME fields as a string, you can do whatever
       you want to do with it. For example: you can print it or 
       make sure it's an unsigned integer, either by using the
       atol C function or by scanning each ASCII character.  */ 
    INKDebug("my-plugin", "%s", output_string);
     
    /* Release handles and allocated memory. */    
    INKHandleStringRelease (bufp, field, value);

INKMimeHdrFieldValueUIntInsert

Inserts an unsigned integer value into a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValueUIntInsert (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, unsigned int value, int idx)

Description

Inserts the unsigned integer value into the MIME field located at field within the marshal buffer bufp. The idx parameter specifies where the inserted value should be placed with respect to other values already in the MIME field. If idx is 0, then the value is prepended to the list of values in the field. Increasing values of idx simply places the value farther down on the list of values. If idx is -1, then the value is appended to the list of values. Normal usage is to specify -1 for idx so that the value will be appended to the existing list of values. All values are stored as strings within the MIME field. INKMimeHdrFieldValueUIntInsert simply formats the unsigned integer into a string and then calls INKMimeHdrFieldValueStringInsert.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValueUintSet

Sets a value in a MIME field to a specified unsigned integer.

Prototype

INKReturnCode INKMimeHdrFieldValueUintSet (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field, int idx, unsigned int value)

Description

Sets a value in the MIME field located at field within the marshal buffer bufp to the unsigned integer value. The idx parameter specifies which value in the field to change. If idx is not between 0 and INKMimeHdrFieldValuesCount (bufp, hdr, field) - 1, then no operation is performed. All values are stored as strings within the MIME field. INKMimeHdrFieldValueUintSet simply formats the unsigned integer into a string and then calls INKMimeHdrFieldValueStringSet.

Returns

INK_SUCCESS if the API is called successfully.

INK_ERROR if an error occurs while calling the API or if an argument is invalid.

INKMimeHdrFieldValuesClear

Clears all values in a MIME field.

Prototype

INKReturnCode INKMimeHdrFieldValuesClear (INKMBuffer bufp, INKMLoc hdr, INKMLoc field)

Description

Removes and destroys all values within the MIME field located at field within the marshal buffer bufp.

Make sure you release any corresponding INKMLoc or string handles via INKHandleMLocRelease or INKHandleStringRelease.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldValuesCount

Counts the values in a MIME field.

Prototype

int INKMimeHdrFieldValuesCount (INKMBuffer bufp, INKMLoc hdr, INKMLoc field)

Description

Retrieves a count of the number of values in the MIME field located at field within the marshal buffer bufp.

Returns

The number of values in the specified MIME field.

INK_ERROR if an error occurs.

INKMimeHdrClone

Copies a MIME header and returns the location of the copied header.

Prototype

INKMLoc INKMimeHdrClone(INKMBuffer dest_bufp, INKMBuffer src_bufp, INKMLoc src_hdr_loc)

Description

Copies the contents of the MIME header located at src_hdr_loc within the marshal buffer src_bufp to the marshal buffer dest_bufp.

Returns

The INKMLoc location of the copied header. Release the returned handle with a call to INKHandleMLocRelease.

INK_ERROR_PTR if an error occurs.

INKMimeHdrCopy

Copies a MIME header to a specified MIME header location.

Prototype

INKReturnCode INKMimeHdrCopy (INKMBuffer dest_bufp, INKMLoc dest_hdr_loc, INKMBuffer src_bufp, INKMLoc src_hdr_loc)

Description

Copies the contents of the MIME header located at src_hdr_loc within the marshal buffer src_bufp to the MIME header located at dest_hdr_loc within the marshal buffer dest_bufp. INKMimeHdrCopy works correctly even if src_bufp and dest_bufp point to different marshal buffers.

[Note] Note

Make sure the destination marshal buffer and destination MIME header location have been created before copying (see the example below).

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

Example
static void
copyResponseMimeHdr (INKCont pCont, INKHttpTxn pTxn) 
{
   INKMBuffer respHdrBuf, tmpBuf;
   INKMLoc respHttpHdrLoc, tmpMimeHdrLoc; 

   if ( !INKHttpTxnClientRespGet (pTxn, &respHdrBuf, &respHttpHdrLoc) ) { 
      INKError ("couldn't retrieve client response header\n"); 
      INKHandleMLocRelease (respHdrBuf, INK_NULL_MLOC, 
         respHttpHdrLoc); 
      goto done;
   }
   tmpBuf = INKMBufferCreate ();
   tmpMimeHdrLoc = INKMimeHdrCreate(tmpBuf); 

   INKMimeHdrCopy(tmpBuf, tmpMimeHdrLoc, respHdrBuf, respHttpHdrLoc); 

   INKHandleMLocRelease (tmpBuf, INK_NULL_MLOC, tmpMimeHdrLoc); 
   INKHandleMLocRelease (respHdrBuf, INK_NULL_MLOC, respHttpHdrLoc); 

   INKMBufferDestroy(tmpBuf);

   done:
   INKHttpTxnReenable(pTxn, INK_EVENT_HTTP_CONTINUE); }

INKMimeHdrCreate

Creates a MIME header.

Prototype

INKMLoc INKMimeHdrCreate (INKMBuffer bufp)

Description

Creates a new MIME header within the marshal buffer bufp.

Returns

Location of the newly-created MIME header. Release with a call to INKHandleMLocRelease.

INK_ERROR_PTR if an error occurs.

INKMimeHdrDestroy

Destroys a MIME header.

Prototype

INKReturnCode INKMimeHdrDestroy (INKMBuffer bufp, INKMLoc hdr_loc)

Description

Destroys the MIME header located at hdr_loc within the marshal buffer bufp.

Release the INKMLoc handle hdr_loc with a call to INKHandleMLocRelease.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldFind

Finds specific fields in a MIME header.

Prototype

INKMLoc INKMimeHdrFieldFind (INKMBuffer bufp, INKMLoc loc, const char* name, int length)

Description

Retrieves a MIME field from within the MIME header located at loc within the marshal buffer bufp. The name and length parameters specify which field to retrieve. For each MIME field in the MIME header, a case-insensitive string comparison is done between the field name and name. The length parameter specifies the length of the string that name points to. If length is -1, then name is assumed to be null-terminated. If the requested field cannot be found, then 0 is returned.

Returns

The location of the retrieved MIME header. Release with a call to INKHandleMLocRelease.

INK_ERROR_PTR if an error occurs.

INKMimeHdrFieldGet

Gets a field in a MIME header.

Prototype

INKMLoc INKMimeHdrFieldGet (INKMBuffer bufp, INKMLoc hdr_loc, int idx)

Description

Retrieves a MIME field from within the MIME header located at hdr_loc within the marshal buffer bufp. The idx parameter specifies which field to retrieve. The fields are numbered from 0 to INKMimeHdrFieldsCount (bufp, hdr_loc) - 1. If idx does not lie within that range, then 0 is returned.

Returns

The location of the MIME field from within the MIME header. Release with a call to INKHandleMLocRelease.

INK_ERROR_PTR if an error occurs.

INKMimeHdrFieldRemove

Removes a field in a MIME header.

Prototype

INKReturnCode INKMimeHdrFieldRemove (INKMBuffer bufp, INKMLoc hdr_loc, INKMLoc field)

Description

Removes the MIME header located at field within the marshal buffer bufp from the MIME header located at hdr_loc within the marshal buffer bufp. If the specified field cannot be found in the list of fields associated with the header, then nothing is done.

After the call to INKMimeHdrFieldDestroy, you must release the INKMLoc handle field with a call to INKHandleMLocRelease.

[Note] Note

Removing the MIME field doesn't destroy the field - it only detaches it and hides it from the printed output.The field can be reattached by calling INKMimeHdrFieldAppend.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldsClear

Clears all the fields in a MIME header.

Prototype

INKReturnCode INKMimeHdrFieldsClear (INKMBuffer bufp, INKMLoc hdr_loc)

Description

Removes and destroys all MIME fields in the MIME header located at hdr_loc within the marshal buffer bufp.

Make sure that you release any corresponding INKMLoc or string handles using INKHandleMLocRelease or INKHandleStringRelease.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeHdrFieldsCount

Counts the fields in a MIME header.

Prototype

int INKMimeHdrFieldsCount (INKMBuffer bufp, INKMLoc hdr_loc)

Description

Obtains a count of the number of MIME fields within the MIME header located at hdr_loc within the marshal buffer bufp.

Returns

The number of fields within the specified MIME header.

INK_ERROR if an error occurs.

INKMimeHdrLengthGet

Gets the length of a MIME header.

Prototype

int INKMimeHdrLengthGet (INKMBuffer bufp, INKMLoc hdr_loc)

Description

Calculates the length of the MIME header located at hdr_loc within the marshal buffer bufp if it was returned as a string. This is the length of the MIME header in its unparsed form.

Returns

The length of the specified MIME header.

INK_ERROR if an error occurs.

INKMimeHdrParse

Parses a MIME header.

Prototype

int INKMimeHdrParse (INKMimeParser parser, INKMBuffer bufp, INKMLoc hdr_loc, const char **start, const char *end)

Description

Parses a MIME header. The MIME header must have already been allocated, and both bufp and hdr_loc must point within that header. The start argument points to the current position of the buffer being parsed and the end argument points to one byte after the end of the buffer. Upon return, start is modified to point past the last character parsed. It is possible to parse a MIME header a single byte at a time using repeated calls to INKMimeHdrParse. As long as an error does not occur, the INKMimeHdrParse function consumes that single byte and asks for more.

Returns

INK_PARSE_ERROR if an error occurs.

INK_PARSE_DONE when a \r\n\r\n pattern is encountered, indicating the end of the header.

INK_PARSE_CONT if parsing of the header stopped because the end of the buffer was reached.

INKMimeParserClear

Clears a MIME header parser so it can be reused.

Prototype

INKReturnCode INKMimeParserClear (INKMimeParser parser)

Description

Clears the specified MIME parser so it can be used again.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.

INKMimeParserCreate

Creates a parser for MIME headers.

Prototype

INKMimeParser INKMimeParserCreate (void)

Description

Creates a MIME parser. The parser’s data structure contains information about the header being parsed. A single MIME parser can be used multiple times, but not simultaneously. Before being used again, the parser must be cleared by calling INKMimeParserClear.

Returns

A pointer to the newly-created MIME parser.

INK_ERROR_PTR if an error occurs.

INKMimeParserDestroy

Destroys a MIME header parser.

Prototype

INKReturnCode INKMimeParserDestroy (INKMimeParser parser)

Description

Destroys the specified MIME parser and frees the associated memory.

Returns

INK_SUCCESS if the parser is successfully destroyed.

INK_ERROR if an error occurs.

INKMimeHdrPrint

Prints a MIME header to an IO buffer.

Prototype

INKReturnCode INKMimeHdrPrint (INKMBuffer bufp, INKMLoc hdr_loc, INKIOBuffer iobufp)

Description

Formats the MIME header located at hdr_loc within the marshal buffer bufp into the IO buffer iobufp . See IO Buffers for information about allocating an IO buffer and retrieving data from within one.

Returns

INK_SUCCESS if successful.

INK_ERROR if an error occurs.