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

getline.h File Reference


Detailed Description

Line-oriented parsing from memory buffer.

Author:
Raphael Manfredi
Date:
2001-2003

#include "common.h"

Go to the source code of this file.

Data Structures

struct  getline
 A getline "object". More...

Defines

#define MAX_LINE_SIZE   1024
 Maximum length for regular line.
#define getline_maxlen(o)   ((o)->maxlen)

Typedefs

typedef enum getline_result getline_result_t
typedef getline getline_t
 A getline "object".

Enumerations

enum  getline_result { READ_MORE, READ_DONE, READ_OVERFLOW }

Functions

getline_tgetline_make (size_t maxsize)
 Create a new line reading object, capable of holding a line of at most `maxlen' bytes.
void getline_free (getline_t *o)
 Destroy getline object.
void getline_reset (getline_t *o)
 Prepare getline object for a new read cycle by forgetting whatever it currently holds.
getline_result_t getline_read (getline_t *o, const gchar *data, size_t len, size_t *used)
 Read line of a header from supplied buffer.
const gchar * getline_str (getline_t *o)
size_t getline_length (getline_t *o)
void getline_copy (getline_t *source, getline_t *dest)
 Copy source into dest.


Define Documentation

#define getline_maxlen  )     ((o)->maxlen)
 

#define MAX_LINE_SIZE   1024
 

Maximum length for regular line.


Typedef Documentation

typedef enum getline_result getline_result_t
 

typedef struct getline getline_t
 

A getline "object".


Enumeration Type Documentation

enum getline_result
 

Enumeration values:
READ_MORE  OK, expecting more.
READ_DONE  OK, got whole line.
READ_OVERFLOW  Reached max line size.


Function Documentation

void getline_copy getline_t source,
getline_t dest
 

Copy source into dest.

void getline_free getline_t o  ) 
 

Destroy getline object.

size_t getline_length getline_t o  ) 
 

Returns:
the length of the currently accumulated line.

getline_t* getline_make size_t  maxsize  ) 
 

Create a new line reading object, capable of holding a line of at most `maxlen' bytes.

getline_result_t getline_read getline_t o,
const gchar *  data,
size_t  len,
size_t *  used
 

Read line of a header from supplied buffer.

We define a line as being something that ends with either "\r\n" or "\n". Although in the Gnutella world, everything is specified to use "\r\n", we must acknowledge the fact that we have to be liberal. In the UNIX world, lines end by "\n", and most Internet protocols (SMTP, NNTP, HTTP) allow for both endings.

We read from `data', at most `len' bytes. If `used' is non-null, it is filled with the amount of bytes we effectively used, unless an error occurs. When READ_MORE is returned, it is guaranteed that used will be `len'.

The trailing "\r\n" or "\n" is stripped from the accumulated line.

void getline_reset getline_t o  ) 
 

Prepare getline object for a new read cycle by forgetting whatever it currently holds.

const gchar* getline_str getline_t o  ) 
 

Returns:
a C string (NUL-terminated) corresponding to the line we currently have in the buffer.


Generated on Sat Jun 30 17:53:26 2007 for gtk-gnutella by  doxygen 1.3.9.1