mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
uniform parser
This commit is contained in:
parent
1e3368e66a
commit
01358610fd
9 changed files with 387 additions and 77 deletions
|
@ -115,8 +115,7 @@
|
|||
#include <string.h>
|
||||
#include <psyc.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
/// Default Flag. Parse everything.
|
||||
PSYC_PARSE_ALL = 0,
|
||||
/// Parse only the header
|
||||
|
@ -130,8 +129,7 @@ typedef enum
|
|||
* The return value definitions for the packet parsing function.
|
||||
* @see psyc_parse()
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
/// Error, packet is not ending with a valid delimiter.
|
||||
PSYC_PARSE_ERROR_END = -8,
|
||||
/// Error, expected NL after the method.
|
||||
|
@ -197,8 +195,7 @@ typedef enum
|
|||
* The return value definitions for the list parsing function.
|
||||
* @see psyc_parseList()
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
PSYC_PARSE_LIST_ERROR_DELIM = -4,
|
||||
PSYC_PARSE_LIST_ERROR_LEN = -3,
|
||||
PSYC_PARSE_LIST_ERROR_TYPE = -2,
|
||||
|
@ -214,8 +211,7 @@ typedef enum
|
|||
/**
|
||||
* Struct for keeping parser state.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
size_t cursor; ///< Current position in buffer.
|
||||
size_t startc; ///< Position where the parsing would be resumed.
|
||||
psycString buffer; ///< Buffer with data to be parsed.
|
||||
|
@ -234,8 +230,7 @@ typedef struct
|
|||
/**
|
||||
* Struct for keeping list parser state.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
size_t cursor; ///< Current position in buffer.
|
||||
size_t startc; ///< Line start position.
|
||||
psycString buffer; ///< Buffer with data to be parsed.
|
||||
|
@ -291,8 +286,7 @@ void psyc_setParseBuffer (psycParseState *state, psycString buffer)
|
|||
state->buffer = buffer;
|
||||
state->cursor = 0;
|
||||
|
||||
if (state->flags & PSYC_PARSE_START_AT_CONTENT)
|
||||
{
|
||||
if (state->flags & PSYC_PARSE_START_AT_CONTENT) {
|
||||
state->contentLength = buffer.length;
|
||||
state->contentLengthFound = PSYC_TRUE;
|
||||
}
|
||||
|
@ -489,6 +483,84 @@ psycBool psyc_parseDate (psycString *value, time_t *t)
|
|||
return psyc_parseDate2(value->ptr, value->length, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is a glyph.
|
||||
* Glyphs are: : = + - ? !
|
||||
*/
|
||||
static inline
|
||||
char psyc_isGlyph (uint8_t g)
|
||||
{
|
||||
switch(g) {
|
||||
case ':':
|
||||
case '=':
|
||||
case '+':
|
||||
case '-':
|
||||
case '?':
|
||||
case '!':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is numeric.
|
||||
*/
|
||||
static inline
|
||||
char psyc_isNumeric (uint8_t c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is alphabetic.
|
||||
*/
|
||||
static inline
|
||||
char psyc_isAlpha (uint8_t c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is alphanumeric.
|
||||
*/
|
||||
static inline
|
||||
char psyc_isAlphaNumeric (uint8_t c)
|
||||
{
|
||||
return psyc_isAlpha(c) || psyc_isNumeric(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is a keyword character.
|
||||
* Keyword characters are: alphanumeric and _
|
||||
*/
|
||||
static inline
|
||||
char psyc_isKwChar (uint8_t c)
|
||||
{
|
||||
return psyc_isAlphaNumeric(c) || c == '_';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is a name character.
|
||||
* Name characters are: see opaque_part in RFC 2396
|
||||
*/
|
||||
static inline
|
||||
char psyc_isNameChar (uint8_t c)
|
||||
{
|
||||
return psyc_isAlpha(c) || (c >= '$' && c <= ';') ||
|
||||
c == '_' || c == '!' || c == '?' || c == '=' || c == '@' || c == '~';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the argument is a hostname character.
|
||||
* Hostname characters are: alphanumeric and -
|
||||
*/
|
||||
static inline
|
||||
char psyc_isHostChar (uint8_t c)
|
||||
{
|
||||
return psyc_isAlphaNumeric(c) || c == '.' || c == '-';
|
||||
}
|
||||
|
||||
/** @} */ // end of parse group
|
||||
|
||||
#define PSYC_PARSE_H
|
||||
|
|
69
include/psyc/uniform.h
Normal file
69
include/psyc/uniform.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
#ifndef PSYC_UNIFORM_H
|
||||
/**
|
||||
* @file uniform.h
|
||||
* @brief Uniform parsing.
|
||||
*/
|
||||
|
||||
#include <psyc.h>
|
||||
|
||||
typedef enum {
|
||||
// essential parts
|
||||
PSYC_UNIFORM_SCHEME = 0,
|
||||
PSYC_UNIFORM_USER = 1,
|
||||
PSYC_UNIFORM_PASS = 2,
|
||||
PSYC_UNIFORM_HOST = 3,
|
||||
PSYC_UNIFORM_PORT = 4,
|
||||
PSYC_UNIFORM_TRANSPORT = 5,
|
||||
PSYC_UNIFORM_RESOURCE = 6,
|
||||
PSYC_UNIFORM_QUERY = 7,
|
||||
PSYC_UNIFORM_CHANNEL = 8,
|
||||
|
||||
// convenient snippets of the URL
|
||||
PSYC_UNIFORM_FULL = 9, // the URL as such
|
||||
PSYC_UNIFORM_BODY = 10, // the URL without scheme and '//'
|
||||
PSYC_UNIFORM_USERATHOST = 11, // mailto and xmpp style
|
||||
PSYC_UNIFORM_HOSTPORT = 12, // just host:port (and transport)
|
||||
PSYC_UNIFORM_ROOT = 13, // root UNI of peer/server
|
||||
PSYC_UNIFORM_SLASHES = 14, // the // if the protocol has them
|
||||
PSYC_UNIFORM_NICK = 15, // whatever works as a nickname
|
||||
PSYC_UNIFORM_SIZE = 16,
|
||||
} psycUniformField;
|
||||
|
||||
typedef enum {
|
||||
PSYC_PARSE_UNIFORM_INVALID_SLASHES = -7,
|
||||
PSYC_PARSE_UNIFORM_INVALID_CHANNEL = -6,
|
||||
PSYC_PARSE_UNIFORM_INVALID_RESOURCE = -5,
|
||||
PSYC_PARSE_UNIFORM_INVALID_TRANSPORT = -4,
|
||||
PSYC_PARSE_UNIFORM_INVALID_PORT = -3,
|
||||
PSYC_PARSE_UNIFORM_INVALID_HOST = -2,
|
||||
PSYC_PARSE_UNIFORM_INVALID_SCHEME = -1,
|
||||
} psycParseUniformRC;
|
||||
|
||||
typedef enum {
|
||||
PSYC_SCHEME_PSYC = 0,
|
||||
PSYC_SCHEME_IRC = 1,
|
||||
PSYC_SCHEME_XMPP = 2,
|
||||
PSYC_SCHEME_SIP = 3,
|
||||
} psycScheme;
|
||||
|
||||
typedef enum {
|
||||
PSYC_TRANSPORT_TCP = 'c',
|
||||
PSYC_TRANSPORT_UDP = 'd',
|
||||
PSYC_TRANSPORT_TLS = 's',
|
||||
PSYC_TRANSPORT_GNUNET = 'g',
|
||||
} psycTransport;
|
||||
|
||||
typedef enum {
|
||||
PSYC_ENTITY_PERSON = '~',
|
||||
PSYC_ENTITY_PLACE = '@',
|
||||
PSYC_ENTITY_SERVICE = '$',
|
||||
} psycEntityType;
|
||||
|
||||
typedef psycString psycUniform[PSYC_UNIFORM_SIZE];
|
||||
|
||||
int psyc_parseUniform2(psycUniform *uni, const char *str, size_t length);
|
||||
|
||||
int psyc_parseUniform(psycUniform *uni, psycString *str);
|
||||
|
||||
#define PSYC_UNIFORM_H
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue