2011-10-13 22:29:32 +00:00
|
|
|
#ifndef PSYC_UNIFORM_H
|
2011-11-11 21:18:24 +00:00
|
|
|
#define PSYC_UNIFORM_H
|
|
|
|
|
2011-10-13 22:29:32 +00:00
|
|
|
/**
|
|
|
|
* @file uniform.h
|
|
|
|
* @brief Uniform parsing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <psyc.h>
|
|
|
|
|
|
|
|
typedef enum {
|
2011-11-11 21:18:24 +00:00
|
|
|
PSYC_SCHEME_PSYC = 0,
|
|
|
|
PSYC_SCHEME_IRC = 1,
|
|
|
|
PSYC_SCHEME_XMPP = 2,
|
|
|
|
PSYC_SCHEME_SIP = 3,
|
2011-10-31 19:26:47 +00:00
|
|
|
} PsycScheme;
|
2011-10-13 23:16:09 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2011-10-13 22:29:32 +00:00
|
|
|
// essential parts
|
2011-11-11 21:18:24 +00:00
|
|
|
uint8_t valid;
|
|
|
|
PsycScheme type;
|
|
|
|
PsycString scheme;
|
|
|
|
PsycString user;
|
|
|
|
PsycString pass;
|
|
|
|
PsycString host;
|
|
|
|
PsycString port;
|
|
|
|
PsycString transport;
|
|
|
|
PsycString resource;
|
|
|
|
PsycString query;
|
|
|
|
PsycString channel;
|
2011-10-13 22:29:32 +00:00
|
|
|
|
|
|
|
// convenient snippets of the URL
|
2011-11-11 21:18:24 +00:00
|
|
|
PsycString full; // the URL as such
|
|
|
|
PsycString body; // the URL without scheme and '//'
|
|
|
|
PsycString user_host; // mailto and xmpp style
|
|
|
|
PsycString host_port; // just host:port (and transport)
|
|
|
|
PsycString root; // root UNI
|
|
|
|
PsycString entity; // entity UNI, without the channel
|
|
|
|
PsycString slashes; // the // if the protocol has them
|
|
|
|
PsycString slash; // first / after host
|
|
|
|
PsycString nick; // whatever works as a nickname
|
2011-10-31 19:26:47 +00:00
|
|
|
} PsycUniform;
|
2011-10-13 23:16:09 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2011-11-11 21:18:24 +00:00
|
|
|
PSYC_UNIFORM_SCHEME = 0,
|
|
|
|
PSYC_UNIFORM_SLASHES,
|
|
|
|
PSYC_UNIFORM_USER,
|
|
|
|
PSYC_UNIFORM_PASS,
|
|
|
|
PSYC_UNIFORM_HOST,
|
|
|
|
PSYC_UNIFORM_PORT,
|
|
|
|
PSYC_UNIFORM_TRANSPORT,
|
|
|
|
PSYC_UNIFORM_RESOURCE,
|
|
|
|
PSYC_UNIFORM_QUERY,
|
|
|
|
PSYC_UNIFORM_CHANNEL,
|
2011-10-31 19:26:47 +00:00
|
|
|
} PsycUniformPart;
|
2011-10-13 22:29:32 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2011-11-11 21:18:24 +00:00
|
|
|
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,
|
2011-10-31 19:26:47 +00:00
|
|
|
} PsycParseUniformRC;
|
2011-10-13 22:29:32 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2011-11-11 21:18:24 +00:00
|
|
|
PSYC_TRANSPORT_TCP = 'c',
|
|
|
|
PSYC_TRANSPORT_UDP = 'd',
|
|
|
|
PSYC_TRANSPORT_TLS = 's',
|
|
|
|
PSYC_TRANSPORT_GNUNET = 'g',
|
2011-10-31 19:26:47 +00:00
|
|
|
} PsycTransport;
|
2011-10-13 22:29:32 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2011-11-11 21:18:24 +00:00
|
|
|
PSYC_ENTITY_ROOT = 0,
|
|
|
|
PSYC_ENTITY_PERSON = '~',
|
|
|
|
PSYC_ENTITY_PLACE = '@',
|
|
|
|
PSYC_ENTITY_SERVICE = '$',
|
2011-10-31 19:26:47 +00:00
|
|
|
} PsycEntityType;
|
2011-10-13 22:29:32 +00:00
|
|
|
|
2011-12-03 13:34:29 +00:00
|
|
|
/**
|
|
|
|
* Parse uniform.
|
|
|
|
*
|
|
|
|
* @return PsycScheme on success, PsycParseUniformRC on error.
|
|
|
|
*/
|
2011-11-11 21:18:24 +00:00
|
|
|
int
|
2011-12-01 13:12:41 +00:00
|
|
|
psyc_uniform_parse (PsycUniform *uni, const char *buffer, size_t length);
|
2011-10-13 22:29:32 +00:00
|
|
|
|
2011-12-03 13:34:29 +00:00
|
|
|
/**
|
|
|
|
* Get entity type.
|
|
|
|
*
|
|
|
|
* @return PsycEntityType on success, PSYC_ERROR on error.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
psyc_entity_type (char entity)
|
|
|
|
{
|
|
|
|
switch (entity) {
|
|
|
|
case PSYC_ENTITY_PERSON:
|
|
|
|
return PSYC_ENTITY_PERSON;
|
|
|
|
case PSYC_ENTITY_PLACE:
|
|
|
|
return PSYC_ENTITY_PLACE;
|
|
|
|
case PSYC_ENTITY_SERVICE:
|
|
|
|
return PSYC_ENTITY_SERVICE;
|
|
|
|
default:
|
|
|
|
return PSYC_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 22:29:32 +00:00
|
|
|
#endif
|