HTTP Parser and message builder / objects in plain C Snapshot
Classes | Defines | Typedefs | Functions
URI

uri parser More...

Classes

struct  tagURI

Defines

#define URI_FLAGS_PARSE_PARTS   1
#define URI_FLAGS_IS_ABSOLUTE_URI   2
#define URI_FLAGS_IS_OPAQUE   4
#define URI_FLAGS_HOST_IPv4   8
#define URI_FLAGS_HOST_IPv6   16
#define URI_FLAGS_HOST_HOSTNAME   32
#define URI_FLAGS_HAS_SCHEME   64

Typedefs

typedef struct tagURI URI

Functions

M_INLINE void URI_init (URI *url)
int URI_parse (URI *url, char *line)
M_INLINE void URI_free (URI *url)
M_INLINE const char * URI_scheme (URI *url)
M_INLINE const char * URI_userinfo_raw (URI *url)
M_INLINE const char * URI_userinfo (URI *url)
M_INLINE const char * URI_host (URI *url)
M_INLINE int URI_port (URI *url)
M_INLINE const char * URI_path_raw (URI *url)
M_INLINE const char * URI_path (URI *url)
M_INLINE const char * URI_query_raw (URI *url)
M_INLINE const char * URI_query (URI *url)
M_INLINE const char * URI_fragment_raw (URI *url)
M_INLINE const char * URI_fragment (URI *url)
M_INLINE const char * URI_opaque_raw (URI *url)
M_INLINE const char * URI_opaque (URI *url)

Detailed Description

uri parser


Define Documentation

#define URI_FLAGS_HAS_SCHEME   64

Definition at line 22 of file uri.h.

#define URI_FLAGS_HOST_HOSTNAME   32

Definition at line 21 of file uri.h.

#define URI_FLAGS_HOST_IPv4   8

Definition at line 19 of file uri.h.

#define URI_FLAGS_HOST_IPv6   16

Definition at line 20 of file uri.h.

#define URI_FLAGS_IS_ABSOLUTE_URI   2

Definition at line 17 of file uri.h.

#define URI_FLAGS_IS_OPAQUE   4

Definition at line 18 of file uri.h.

#define URI_FLAGS_PARSE_PARTS   1

Definition at line 16 of file uri.h.


Typedef Documentation

typedef struct tagURI URI

Function Documentation

M_INLINE const char* URI_fragment ( URI url)

Definition at line 131 of file uri.h.

{
  return url->fragment;
}
M_INLINE const char* URI_fragment_raw ( URI url)

Definition at line 126 of file uri.h.

{
  return url->fragment_raw;
}
M_INLINE void URI_free ( URI url)

Definition at line 65 of file uri.h.

                                  {
  if (url->cdata_raw) {
    free( url->cdata_raw );
  }

  if (url->cdata) {
    free(url->cdata);
  }

  if ( url->cdata_is_escaped ) {
    free( url->cdata_is_escaped );
  }
  URI_init( url );
}
M_INLINE const char* URI_host ( URI url)

Definition at line 95 of file uri.h.

{
  return url->host;
}
M_INLINE void URI_init ( URI url)

Definition at line 55 of file uri.h.

{
  memset( url, 0, sizeof( URI ) );
  url->port = -1;
}
M_INLINE const char* URI_opaque ( URI url)

Definition at line 141 of file uri.h.

{
  return url->opaque;
}
M_INLINE const char* URI_opaque_raw ( URI url)

Definition at line 136 of file uri.h.

{
  return url->opaque_raw;
}
int URI_parse ( URI url,
char *  line 
)

Definition at line 523 of file uri.c.

{
   URI_init( url );
   URIPARSECTX ctx;
   char *ptr,*next;
   size_t slen;

   ctx.rep = url;

   slen = strlen( line );
   url->cdata = (char *) malloc( slen );
   if (!url->cdata) {
     goto err;
   }

   ctx.cdata_pos_off = ctx.cdata_pos_start = ctx.cdata_pos = url->cdata;

   url->cdata_raw = (char *) malloc( slen );
   if (!url->cdata_raw) {
     goto err;
   }

   url->cdata_is_escaped = (char *) malloc( slen );
   if (!url->cdata_is_escaped) {
     goto err;
   }
   memset( url->cdata_is_escaped, 0, slen );
   ctx.cdata_is_escaped_start = url->cdata_is_escaped;

   ctx.cdata_raw_pos = url->cdata_raw;


   ptr = line;
   if (ptr[0] == '/') {
        if ( parse_hier_part( &ctx, ptr, &next, 0) ) {
          goto err;
        }
   } else {
        if (! parse_scheme( &ctx, ptr, &next )) {
            ptr = next;
            if ( parse_hier_part( &ctx, ptr, &next, 1 ) ) {
              goto err;
            }   
        } else {
            if ( parse_authority( &ctx, ptr, &next )) {
               goto err;
            }
        }   
   }

  if (*next == '\0') {
    return 0;
  }

err:
  URI_free( url );
  return -1;
}
M_INLINE const char* URI_path ( URI url)

Definition at line 111 of file uri.h.

{
  return url->path;
}
M_INLINE const char* URI_path_raw ( URI url)

Definition at line 106 of file uri.h.

{
  return url->path_raw;
}
M_INLINE int URI_port ( URI url)

Definition at line 100 of file uri.h.

{
  return url->port;
}
M_INLINE const char* URI_query ( URI url)

Definition at line 121 of file uri.h.

{
  return url->query;
}
M_INLINE const char* URI_query_raw ( URI url)

Definition at line 116 of file uri.h.

{
  return url->query_raw;
}
M_INLINE const char* URI_scheme ( URI url)

Definition at line 80 of file uri.h.

{
  return url->scheme;
}
M_INLINE const char* URI_userinfo ( URI url)

Definition at line 90 of file uri.h.

{
  return url->userinfo;
}
M_INLINE const char* URI_userinfo_raw ( URI url)

Definition at line 85 of file uri.h.

{
  return url->userinfo_raw;
}