Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

header.c File Reference


Detailed Description

Header parsing routines.

Author:
Raphael Manfredi
Date:
2001-2003

#include "common.h"
#include "header.h"
#include "glib-missing.h"
#include "misc.h"
#include "walloc.h"
#include "getline.h"
#include "override.h"

Data Structures

struct  header_fmt
 Header formatting context. More...


Defines

#define HEAD_F_EOH   0x00000001 /**< EOH reached */
 EOH reached.

#define HEAD_F_SKIP   0x00000002 /**< Skip continuations */
 Skip continuations.

#define HEADER_FMT_MAGIC   0xf7a91c
#define HEADER_FMT_DFLT_LEN   256 /**< Default field length if no hint */
 Default field length if no hint.

#define HEADER_FMT_LINE_LEN   78 /**< Try to never emit longer lines */
 Try to never emit longer lines.

#define HEADER_FMT_MAX_SIZE   1024 /**< Max line size for header */
 Max line size for header.


Functions

 RCSID ("$Id:header.c, v 1.10 2005/11/09 19:16:53 cbiere Exp $")
const gchar * header_strerror (guint errnum)
void normalize (gchar *field)
 In-place normalize the header field name: all letters starting a word are upper-cased, the others are lowercased.

header_field_thfield_make (const gchar *name)
 Create a new empty header field, whose normalized name is `name'.

void hfield_free (header_field_t *h)
 hfield_free

void hfield_append (header_field_t *h, const gchar *text)
 Append line of text to given header field.

void hfield_dump (const header_field_t *h, FILE *out)
 Dump field on specified file descriptor.

header_theader_make (void)
 Create a new header object.

gboolean free_header_data (gpointer key, gpointer value, gpointer unused_udata)
 htable callback

void header_free (header_t *o)
 Destroy header object.

void header_reset (header_t *o)
 Reset header object, for new header parsing.

gchar * header_get (const header_t *o, const gchar *field)
 Get field value, or NULL if not present.

gchar * header_getdup (const header_t *o, const gchar *field)
 Get field value, or NULL if not present.

void add_header (header_t *o, const gchar *field, const gchar *text)
 Add header line to the `headers' hash for specified field name.

void add_continuation (header_t *o, const gchar *field, const gchar *text)
 Add continuation line to the `headers' hash for specified field name.

gint header_append (header_t *o, const gchar *text, gint len)
 Append a new line of text at the end of the header.

void header_dump (const header_t *o, FILE *out)
 Dump whole header on specified file.

gint stripped_strlen (const gchar *s, gint len)
 Compute the length of the string `s' whose length is `len' with trailing whitespace ignored.

gpointer header_fmt_make (const gchar *field, const gchar *separator, gint len_hint)
 Create a new formatting context for a header line.

void header_fmt_set_line_length (gpointer o, gint maxlen)
 Set max line length.

void header_fmt_free (gpointer o)
 Dispose of header formatting context.

gboolean header_fmt_value_fits (gpointer o, gint len, gint maxlen)
 Checks whether appending `len' bytes of data to the header would fit within the `maxlen' total header size requirement in case a continuation is emitted, and using the configured separator.

void header_fmt_append_full (struct header_fmt *hf, const gchar *str, const gchar *separator, gint slen, gint sslen)
 Append data `str' to the header line, atomically.

void header_fmt_append (gpointer o, const gchar *str, const gchar *separator)
 Append data `str' to the header line, atomically.

void header_fmt_append_value (gpointer o, const gchar *str)
 Append data `str' to the header line, atomically.

gint header_fmt_length (gpointer o)
void header_fmt_end (gpointer o)
 Terminate header, emitting the trailing "\r\n".

gchar * header_fmt_string (gpointer o)
gchar * header_fmt_to_string (gpointer o)
 Convert current header to a string.


Variables

const char * error_str []


Define Documentation

#define HEAD_F_EOH   0x00000001 /**< EOH reached */
 

EOH reached.

#define HEAD_F_SKIP   0x00000002 /**< Skip continuations */
 

Skip continuations.

#define HEADER_FMT_DFLT_LEN   256 /**< Default field length if no hint */
 

Default field length if no hint.

#define HEADER_FMT_LINE_LEN   78 /**< Try to never emit longer lines */
 

Try to never emit longer lines.

#define HEADER_FMT_MAGIC   0xf7a91c
 

#define HEADER_FMT_MAX_SIZE   1024 /**< Max line size for header */
 

Max line size for header.


Function Documentation

void add_continuation header_t o,
const gchar *  field,
const gchar *  text
[static]
 

Add continuation line to the `headers' hash for specified field name.

A private copy of the data is made.

void add_header header_t o,
const gchar *  field,
const gchar *  text
[static]
 

Add header line to the `headers' hash for specified field name.

A private copy of the `field' name and of the `text' data is made.

gboolean free_header_data gpointer  key,
gpointer  value,
gpointer  unused_udata
[static]
 

htable callback

Frees the key/values from the headers hash.

gint header_append header_t o,
const gchar *  text,
gint  len
 

Append a new line of text at the end of the header.

A private copy of the text is made.

Returns:
an error code, or HEAD_OK if appending was successful.

void header_dump const header_t o,
FILE *  out
 

Dump whole header on specified file.

void header_fmt_append gpointer  o,
const gchar *  str,
const gchar *  separator
 

Append data `str' to the header line, atomically.

`separator' is an optional separator string that will be emitted BEFORE outputting the data, and only when nothing has been emitted already. Any trailing space will be stripped out of `separator' if emitting at the end of a line. It supersedes any separator configured at make time.

To use the standard separator, use header_fmt_append_value().

void header_fmt_append_full struct header_fmt hf,
const gchar *  str,
const gchar *  separator,
gint  slen,
gint  sslen
[static]
 

Append data `str' to the header line, atomically.

Parameters:
`hf' no brief description.
`str' no brief description.
`separator' is an optional separator string that will be emitted BEFORE outputting the data, and only when nothing has been emitted already.
`slen' is the separator length, 0 if empty.
`sslen' is the stripped separator length, -1 if unknown yet.

void header_fmt_append_value gpointer  o,
const gchar *  str
 

Append data `str' to the header line, atomically.

Values are separated using the string specified at make time, if any. If emitted before a continuation, the version with stripped trailing whitespaces is used.

To supersede the default separator, use header_fmt_append().

void header_fmt_end gpointer  o  ) 
 

Terminate header, emitting the trailing "\r\n".

Further appending is forbidden.

void header_fmt_free gpointer  o  ) 
 

Dispose of header formatting context.

gint header_fmt_length gpointer  o  ) 
 

Returns:
length of currently formatted header.

gpointer header_fmt_make const gchar *  field,
const gchar *  separator,
gint  len_hint
 

Create a new formatting context for a header line.

Parameters:
`field' is the header field name, without trailing ':'.
`separator' is the optional default separator to emit between the values added via header_fmd_append_value(). To supersede the default separator, use header_fmd_append() and specify another separator explicitly. If set to NULL, there will be no default separator and values will be simply concatenated together. The value given must NOT be freed before the header_fmt_end() call (usually it will just be a static string). Trailing spaces in the separator will be stripped if it is emitted at the end of a line before a continuation.
`len_hint' is the expected line size, for pre-sizing purposes. (0 to guess).
Returns:
opaque pointer.

void header_fmt_set_line_length gpointer  o,
gint  maxlen
 

Set max line length.

gchar* header_fmt_string gpointer  o  ) 
 

Returns:
current header string.

gchar* header_fmt_to_string gpointer  o  ) 
 

Convert current header to a string.

Attention:
NB: returns pointer to static data!

gboolean header_fmt_value_fits gpointer  o,
gint  len,
gint  maxlen
 

Checks whether appending `len' bytes of data to the header would fit within the `maxlen' total header size requirement in case a continuation is emitted, and using the configured separator.

Attention:
NB: The `maxlen' parameter is the amount of data that can be generated for the header string, not counting the final "\r\n" + the trailing NUL byte.

void header_free header_t o  ) 
 

Destroy header object.

gchar* header_get const header_t o,
const gchar *  field
 

Get field value, or NULL if not present.

The value returned is a pointer to the internals of the header structure, so it must not be kept around.

The requested header field must be in normalized form since they are stored that way.

gchar* header_getdup const header_t o,
const gchar *  field
 

Get field value, or NULL if not present.

The value returned is a copy of the internal value, so it may be kept around, but must be freed by the caller.

header_t* header_make void   ) 
 

Create a new header object.

void header_reset header_t o  ) 
 

Reset header object, for new header parsing.

const gchar* header_strerror guint  errnum  ) 
 

Returns:
human-readable error string corresponding to error code `errnum'.

void hfield_append header_field_t h,
const gchar *  text
[static]
 

Append line of text to given header field.

A private copy of the data is made.

void hfield_dump const header_field_t h,
FILE *  out
[static]
 

Dump field on specified file descriptor.

void hfield_free header_field_t h  )  [static]
 

hfield_free

Dispose of the header field.

header_field_t* hfield_make const gchar *  name  )  [static]
 

Create a new empty header field, whose normalized name is `name'.

A private copy of `name' is done.

void normalize gchar *  field  )  [static]
 

In-place normalize the header field name: all letters starting a word are upper-cased, the others are lowercased.

RCSID "$Id:header.  c,
v 1.10 2005/11/09 19:16:53 cbiere Exp $" 
 

gint stripped_strlen const gchar *  s,
gint  len
[static]
 

Compute the length of the string `s' whose length is `len' with trailing whitespace ignored.


Variable Documentation

const char* error_str[] [static]
 

Initial value:

 {
    "OK",                                   
    "Unexpected continuation line",         
    "Malformed header line",                
    "Invalid characters in field name",     
    "End of header already reached",        
    "Skipped continuation line",            
    "Header too large",                     
    "Header has too many lines",            
    "End of header",                        
}


Generated on Sun Feb 12 10:50:03 2006 for Gtk-Gnutella by doxygen 1.3.6