2011-05-09 12:37:57 +00:00
|
|
|
/**
|
|
|
|
* @file psyc.h
|
2011-04-20 17:18:35 +00:00
|
|
|
* @brief Main PSYC interface providing crucial functionality.
|
2011-05-09 12:37:57 +00:00
|
|
|
*/
|
2011-04-19 20:57:49 +00:00
|
|
|
|
2011-05-09 12:37:57 +00:00
|
|
|
/**
|
|
|
|
* @mainpage PSYC Core Library
|
2011-04-19 20:57:49 +00:00
|
|
|
*
|
|
|
|
* @section intro_sec Introduction
|
|
|
|
*
|
2011-05-09 07:11:59 +00:00
|
|
|
* Welcome to the libpsyc documentation!
|
2011-04-19 20:57:49 +00:00
|
|
|
*
|
|
|
|
* @section install_sec Installation
|
|
|
|
*/
|
2011-05-09 12:37:57 +00:00
|
|
|
// * @subsection step1 Step 1: Opening the box
|
2011-04-19 20:57:49 +00:00
|
|
|
|
2011-04-20 17:18:35 +00:00
|
|
|
#ifndef PSYC_H
|
|
|
|
|
2011-04-16 15:30:03 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2011-05-20 00:58:32 +00:00
|
|
|
#include <sys/types.h>
|
2011-04-16 15:30:03 +00:00
|
|
|
|
|
|
|
#define PSYC_EPOCH 1440444041 // 2015-08-24 21:20:41 CET (Monday)
|
|
|
|
|
2011-10-22 22:13:42 +00:00
|
|
|
#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
|
2011-05-03 23:00:35 +00:00
|
|
|
|
2011-10-31 19:04:16 +00:00
|
|
|
#define PSYC_NUM_ELEM(a) (sizeof(a) / sizeof(*(a)))
|
|
|
|
|
2011-04-20 17:18:35 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSYC_FALSE = 0,
|
|
|
|
PSYC_TRUE = 1,
|
2011-10-30 15:04:54 +00:00
|
|
|
PSYC_NO = 0,
|
|
|
|
PSYC_YES = 1,
|
2011-04-25 21:40:38 +00:00
|
|
|
} psycBool;
|
2011-04-20 17:18:35 +00:00
|
|
|
|
2011-04-21 12:20:24 +00:00
|
|
|
/**
|
|
|
|
* PSYC packet parts.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSYC_PART_RESET = -1,
|
2011-05-05 22:13:37 +00:00
|
|
|
PSYC_PART_ROUTING = 0,
|
|
|
|
PSYC_PART_LENGTH = 1,
|
|
|
|
PSYC_PART_CONTENT = 2,
|
|
|
|
PSYC_PART_METHOD = 3,
|
|
|
|
PSYC_PART_DATA = 4,
|
|
|
|
PSYC_PART_END = 5,
|
2011-04-25 21:40:38 +00:00
|
|
|
} psycPart;
|
2011-04-21 12:20:24 +00:00
|
|
|
|
2011-04-20 17:18:35 +00:00
|
|
|
/**
|
|
|
|
* Different types that a variable can have.
|
|
|
|
*
|
|
|
|
* This enum lists PSYC variable types that
|
|
|
|
* this library is capable of checking for
|
|
|
|
* validity. Other variable types are treated
|
|
|
|
* as opaque data.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
2011-04-22 15:09:32 +00:00
|
|
|
PSYC_TYPE_UNKNOWN,
|
2011-04-20 17:18:35 +00:00
|
|
|
PSYC_TYPE_AMOUNT,
|
|
|
|
PSYC_TYPE_COLOR,
|
|
|
|
PSYC_TYPE_DATE,
|
|
|
|
PSYC_TYPE_DEGREE,
|
|
|
|
PSYC_TYPE_ENTITY,
|
|
|
|
PSYC_TYPE_FLAG,
|
|
|
|
PSYC_TYPE_LANGUAGE,
|
|
|
|
PSYC_TYPE_LIST,
|
|
|
|
PSYC_TYPE_NICK,
|
|
|
|
PSYC_TYPE_PAGE,
|
|
|
|
PSYC_TYPE_UNIFORM,
|
|
|
|
PSYC_TYPE_TIME,
|
2011-04-25 21:40:38 +00:00
|
|
|
} psycType;
|
2011-04-20 17:18:35 +00:00
|
|
|
|
2011-04-21 12:20:24 +00:00
|
|
|
/**
|
|
|
|
* List types.
|
|
|
|
* Possible types are text and binary.
|
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PSYC_LIST_TEXT = 1,
|
|
|
|
PSYC_LIST_BINARY = 2,
|
2011-04-25 21:40:38 +00:00
|
|
|
} psycListType;
|
2011-04-21 12:20:24 +00:00
|
|
|
|
2011-05-08 23:49:04 +00:00
|
|
|
/**
|
|
|
|
* String struct.
|
|
|
|
*
|
|
|
|
* Contains pointer and length for a buffer.
|
|
|
|
*/
|
2011-04-22 15:09:32 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2011-05-08 23:49:04 +00:00
|
|
|
/// Length of the data pointed to by ptr
|
2011-05-28 17:39:42 +00:00
|
|
|
size_t length;
|
2011-05-08 23:49:04 +00:00
|
|
|
/// pointer to the data
|
2011-10-22 22:13:42 +00:00
|
|
|
char *ptr;
|
2011-04-25 21:40:38 +00:00
|
|
|
} psycString;
|
2011-04-22 15:09:32 +00:00
|
|
|
|
2011-04-29 20:58:19 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2011-10-31 19:04:16 +00:00
|
|
|
psycString key;
|
2011-04-29 20:58:19 +00:00
|
|
|
int value;
|
|
|
|
} psycMatchVar;
|
|
|
|
|
2011-04-25 12:20:13 +00:00
|
|
|
/**
|
2011-04-25 21:40:38 +00:00
|
|
|
* Shortcut for creating a psycString.
|
2011-04-25 12:20:13 +00:00
|
|
|
*
|
2011-10-31 19:04:16 +00:00
|
|
|
* @param str Pointer to the buffer.
|
|
|
|
* @param len Length of that buffer.
|
2011-04-25 12:20:13 +00:00
|
|
|
*
|
2011-04-25 21:40:38 +00:00
|
|
|
* @return An instance of the psycString struct.
|
2011-04-25 12:20:13 +00:00
|
|
|
*/
|
2011-05-03 23:00:35 +00:00
|
|
|
static inline
|
2011-10-31 19:04:16 +00:00
|
|
|
psycString psyc_string_new (char *str, size_t len)
|
2011-04-23 14:51:46 +00:00
|
|
|
{
|
2011-10-31 19:04:16 +00:00
|
|
|
psycString s = {len, str};
|
2011-05-03 23:00:35 +00:00
|
|
|
return s;
|
|
|
|
}
|
2011-04-22 20:44:14 +00:00
|
|
|
|
2011-05-03 23:00:35 +00:00
|
|
|
static inline
|
|
|
|
unsigned int psyc_version ()
|
2011-04-23 14:51:46 +00:00
|
|
|
{
|
2011-05-03 23:00:35 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2011-04-22 20:44:14 +00:00
|
|
|
|
2011-05-23 00:03:34 +00:00
|
|
|
|
2011-05-20 00:58:32 +00:00
|
|
|
/**
|
2011-10-31 19:04:16 +00:00
|
|
|
* Checks if long keyword string inherits from short keyword string.
|
2011-04-20 17:18:35 +00:00
|
|
|
*/
|
2011-10-31 19:04:16 +00:00
|
|
|
int psyc_inherits (char *sho, size_t slen,
|
|
|
|
char *lon, size_t llen);
|
2011-04-20 17:18:35 +00:00
|
|
|
|
|
|
|
/**
|
2011-10-31 19:04:16 +00:00
|
|
|
* Checks if short keyword string matches long keyword string.
|
2011-05-20 00:58:32 +00:00
|
|
|
*/
|
2011-10-31 19:04:16 +00:00
|
|
|
int psyc_matches (char *sho, size_t slen,
|
|
|
|
char *lon, size_t llen);
|
2011-04-20 17:18:35 +00:00
|
|
|
|
2011-10-30 15:04:54 +00:00
|
|
|
/**
|
2011-10-31 19:04:16 +00:00
|
|
|
* Check if keyword is in array.
|
2011-10-30 15:04:54 +00:00
|
|
|
*
|
|
|
|
* @param array The array to search, should be ordered alphabetically.
|
|
|
|
* @param size Size of array.
|
2011-10-31 19:04:16 +00:00
|
|
|
* @param kw Keyword to look for.
|
|
|
|
* @param kwlen Length of keyword.
|
|
|
|
* @param inherit If true, also look for anything inheriting from kw,
|
2011-10-30 15:04:54 +00:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @return The value of the matched variable in the array.
|
|
|
|
*/
|
|
|
|
|
2011-10-31 19:04:16 +00:00
|
|
|
int psyc_in_array (const psycMatchVar *array, size_t size,
|
|
|
|
const char *kw, size_t kwlen,
|
|
|
|
psycBool inherit, int8_t *matching);
|
2011-05-09 17:21:26 +00:00
|
|
|
|
2011-10-31 19:04:16 +00:00
|
|
|
#include "psyc/variable.h"
|
2011-04-16 15:30:03 +00:00
|
|
|
|
2011-05-09 07:02:15 +00:00
|
|
|
#define PSYC_H
|
|
|
|
#endif
|