mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
refactoring - more renames
This commit is contained in:
parent
f25e768482
commit
344cdb7996
21 changed files with 215 additions and 199 deletions
|
@ -24,8 +24,8 @@
|
|||
|
||||
#define PSYC_C2STR(str) {sizeof(str)-1, str}
|
||||
#define PSYC_C2ARG(str) str, sizeof(str)-1
|
||||
#define PSYC_S2ARG(str) (str).ptr, (str).length
|
||||
#define PSYC_S2ARG2(str) (str).length, (str).ptr
|
||||
#define PSYC_S2ARG(str) (str).data, (str).length
|
||||
#define PSYC_S2ARG2(str) (str).length, (str).data
|
||||
|
||||
#define PSYC_NUM_ELEM(a) (sizeof(a) / sizeof(*(a)))
|
||||
|
||||
|
@ -37,6 +37,12 @@ typedef enum
|
|||
PSYC_YES = 1,
|
||||
} PsycBool;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PSYC_OK = 1,
|
||||
PSYC_ERROR = -1,
|
||||
} PsycRC;
|
||||
|
||||
/**
|
||||
* PSYC packet parts.
|
||||
*/
|
||||
|
@ -96,14 +102,20 @@ typedef struct
|
|||
/// Length of the data pointed to by ptr
|
||||
size_t length;
|
||||
/// pointer to the data
|
||||
char *ptr;
|
||||
char *data;
|
||||
} PsycString;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PsycString key;
|
||||
int value;
|
||||
} PsycMatchVar;
|
||||
void *value;
|
||||
} PsycDict;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PsycString key;
|
||||
intptr_t value;
|
||||
} PsycDictInt;
|
||||
|
||||
/**
|
||||
* Shortcut for creating a PsycString.
|
||||
|
@ -140,23 +152,37 @@ int psyc_matches (char *sho, size_t slen,
|
|||
char *lon, size_t llen);
|
||||
|
||||
/**
|
||||
* Check if keyword is in array.
|
||||
* Look up value associated with a key in a dictionary.
|
||||
*
|
||||
* @param array The array to search, should be ordered alphabetically.
|
||||
* @param size Size of array.
|
||||
* @param kw Keyword to look for.
|
||||
* @param kwlen Length of keyword.
|
||||
* @param inherit If true, also look for anything inheriting from kw,
|
||||
otherwise only exact matches are returned.
|
||||
* @param matching A temporary array used for keeping track of results.
|
||||
* Should be the same size as the array we're searching.
|
||||
* @param dict The dictionary to search, should be ordered alphabetically.
|
||||
* @param size Size of dict.
|
||||
* @param key Key to look for.
|
||||
* @param keylen Length of key.
|
||||
* @param inherit If true, also look for anything inheriting from key,
|
||||
otherwise only exact matches are returned.
|
||||
* @param tmp A temporary array used for keeping track of results.
|
||||
* Should be the same size as dict.
|
||||
*
|
||||
* @return The value of the matched variable in the array.
|
||||
* @return The value of the entry if found, or NULL if not found.
|
||||
*/
|
||||
|
||||
int psyc_in_array (const PsycMatchVar *array, size_t size,
|
||||
const char *kw, size_t kwlen,
|
||||
PsycBool inherit, int8_t *matching);
|
||||
void * psyc_dict_lookup (const PsycDict *dict, size_t size,
|
||||
const char *key, size_t keylen,
|
||||
PsycBool inherit, int8_t *tmp);
|
||||
|
||||
/**
|
||||
* Look up value associated with a key in a dictionary of integers.
|
||||
* @see psyc_dict_lookup
|
||||
*/
|
||||
static inline
|
||||
intptr_t psyc_dict_lookup_int (const PsycDictInt *dict, size_t size,
|
||||
const char *key, size_t keylen,
|
||||
PsycBool inherit, int8_t *tmp)
|
||||
{
|
||||
return (intptr_t) psyc_dict_lookup((PsycDict *)dict, size, key, keylen, inherit, tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "psyc/variable.h"
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ PsycModifierFlag psyc_modifier_length_check (PsycModifier *m)
|
|||
|
||||
if (m->value.length > PSYC_MODIFIER_SIZE_THRESHOLD)
|
||||
flag = PSYC_MODIFIER_NEED_LENGTH;
|
||||
else if (memchr(m->value.ptr, (int)'\n', m->value.length))
|
||||
else if (memchr(m->value.data, (int)'\n', m->value.length))
|
||||
flag = PSYC_MODIFIER_NEED_LENGTH;
|
||||
else
|
||||
flag = PSYC_MODIFIER_NO_LENGTH;
|
||||
|
|
|
@ -77,17 +77,17 @@
|
|||
* // Name, value and operator of the variable can now be found in the
|
||||
* // respective variables:
|
||||
* printf("Variable: %.*s Value: %.*s Operator: %c\n",
|
||||
* name.length, name.ptr,
|
||||
* value.length, value.ptr,
|
||||
* name.length, name.data,
|
||||
* value.length, value.data,
|
||||
* oper);
|
||||
* // Note that the .ptr member still points at your original buffer. If
|
||||
* // Note that the .data member still points at your original buffer. If
|
||||
* // you want to reuse that buffer for the next packet, you better copy it
|
||||
* // before passing it to the parser or you copy each variable now.
|
||||
* break;
|
||||
* case PSYC_PARSE_BODY: // it is the method and the body of the packet.
|
||||
* printf("Method Name: %.*s Body: %.*s\n",
|
||||
* name.length, name.ptr, // name of the method
|
||||
* value.length, value.ptr); // value of the body
|
||||
* name.length, name.data, // name of the method
|
||||
* value.length, value.data); // value of the body
|
||||
* break;
|
||||
* case PSYC_PARSE_COMPLETE: // parsing of this packet is complete
|
||||
* // You can simply continue parsing till you get the
|
||||
|
@ -345,7 +345,7 @@ size_t psyc_parse_remaining_length (PsycParseState *state)
|
|||
static inline
|
||||
const char * psyc_parse_remaining_buffer (PsycParseState *state)
|
||||
{
|
||||
return state->buffer.ptr + state->cursor;
|
||||
return state->buffer.data + state->cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ typedef struct
|
|||
* Callback for psyc_text() that produces a value for a match.
|
||||
*
|
||||
* The application looks up a match such as _fruit from [_fruit] and
|
||||
* if found sets value->ptr & value->length to point to the found value,
|
||||
* if found sets value->data & value->length to point to the found value,
|
||||
* "Apple" for example. 0 is a legal value for the length.
|
||||
* The callbacks returns either PSYC_TEXT_VALUE_FOUND or
|
||||
* PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text
|
||||
|
|
|
@ -68,6 +68,7 @@ typedef enum {
|
|||
} PsycTransport;
|
||||
|
||||
typedef enum {
|
||||
PSYC_ENTITY_ROOT = 0,
|
||||
PSYC_ENTITY_PERSON = '~',
|
||||
PSYC_ENTITY_PLACE = '@',
|
||||
PSYC_ENTITY_SERVICE = '$',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
extern const PsycString psyc_routing_vars[];
|
||||
|
||||
// Variable types in alphabetical order.
|
||||
extern const PsycMatchVar psyc_var_types[];
|
||||
extern const PsycDictInt psyc_var_types[];
|
||||
|
||||
extern const size_t psyc_routing_vars_num;
|
||||
extern const size_t psyc_var_types_num;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue