mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
uniform path; more methods
This commit is contained in:
parent
a210128091
commit
80eb590987
6 changed files with 67 additions and 19 deletions
|
@ -19,19 +19,25 @@ typedef enum PsycMethod {
|
|||
PSYC_MC_ECHO_HELLO,
|
||||
PSYC_MC_ERROR,
|
||||
PSYC_MC_FAILURE,
|
||||
PSYC_MC_FAILURE_ALIAS_NONEXISTANT,
|
||||
PSYC_MC_FAILURE_ALIAS_UNAVAILABLE,
|
||||
PSYC_MC_INFO,
|
||||
PSYC_MC_MESSAGE,
|
||||
PSYC_MC_MESSAGE_ACTION,
|
||||
PSYC_MC_MESSAGE_ECHO,
|
||||
PSYC_MC_MESSAGE_ECHO_ACTION,
|
||||
PSYC_MC_NOTICE,
|
||||
PSYC_MC_NOTICE_ALIAS_ADD,
|
||||
PSYC_MC_NOTICE_ALIAS_CHANGE,
|
||||
PSYC_MC_NOTICE_ALIAS_REMOVE,
|
||||
PSYC_MC_NOTICE_CONTEXT_ENTER,
|
||||
PSYC_MC_NOTICE_CONTEXT_LEAVE,
|
||||
PSYC_MC_NOTICE_FRIENDSHIP,
|
||||
PSYC_MC_NOTICE_LINK,
|
||||
PSYC_MC_NOTICE_SET,
|
||||
PSYC_MC_NOTICE_UNLINK,
|
||||
PSYC_MC_REQUEST,
|
||||
PSYC_MC_REQUEST_CONTEXT_ENTER,
|
||||
PSYC_MC_REQUEST_CONTEXT_LEAVE,
|
||||
PSYC_MC_REQUEST_LINK,
|
||||
PSYC_MC_REQUEST_FRIENDSHIP,
|
||||
PSYC_MC_STATUS,
|
||||
PSYC_MC_STATUS_CONTEXTS_ENTERED,
|
||||
PSYC_MC_STATUS_HELLO,
|
||||
|
@ -51,19 +57,25 @@ typedef union PsycTemplates {
|
|||
PsycString _echo_hello;
|
||||
PsycString _error;
|
||||
PsycString _failure;
|
||||
PsycString _failure_alias_nonexistant;
|
||||
PsycString _failure_alias_unavailable;
|
||||
PsycString _info;
|
||||
PsycString _message;
|
||||
PsycString _message_action;
|
||||
PsycString _message_echo;
|
||||
PsycString _message_echo_action;
|
||||
PsycString _notice;
|
||||
PsycString _notice_alias_add;
|
||||
PsycString _notice_alias_change;
|
||||
PsycString _notice_alias_remove;
|
||||
PsycString _notice_context_enter;
|
||||
PsycString _notice_context_leave;
|
||||
PsycString _notice_friendship;
|
||||
PsycString _notice_link;
|
||||
PsycString _notice_set;
|
||||
PsycString _notice_unlink;
|
||||
PsycString _request;
|
||||
PsycString _request_context_enter;
|
||||
PsycString _request_context_leave;
|
||||
PsycString _request_link;
|
||||
PsycString _request_friendship;
|
||||
PsycString _status;
|
||||
PsycString _status_contexts_entered;
|
||||
PsycString _status_hello;
|
||||
|
|
|
@ -38,6 +38,7 @@ typedef struct {
|
|||
PsycString entity; // entity UNI, without the channel
|
||||
PsycString slashes; // the // if the protocol has them
|
||||
PsycString slash; // first / after host
|
||||
PsycString path; // path begins at first / after host
|
||||
PsycString nick; // whatever works as a nickname
|
||||
} PsycUniform;
|
||||
|
||||
|
|
|
@ -1,16 +1,30 @@
|
|||
#define _ PSYC_C2STRI
|
||||
|
||||
._notice_alias_add =
|
||||
_("[_nick] is now an alias for [_uniform]"),
|
||||
._notice_alias_remove =
|
||||
_("[_nick] is no longer an alias for [_uniform]"),
|
||||
._notice_alias_change =
|
||||
_("[_nick_old] is now known as [_nick_new]"),
|
||||
|
||||
._failure_alias_unavailable =
|
||||
_("[_nick] is already an alias for [_uniform]"),
|
||||
._failure_alias_nonexistant =
|
||||
_("[_nick] is not an alias"),
|
||||
|
||||
._request_context_enter =
|
||||
_("[_nick] asks for your permission to enter [_nick_place]"),
|
||||
._echo_context_enter =
|
||||
_("You enter [_nick_place]" ),
|
||||
._echo_context_leave =
|
||||
_("You leave [_nick_place]"),
|
||||
._echo_hello =
|
||||
_("Received hello of psyc://[_key_public]:g/"),
|
||||
|
||||
._notice_context_enter =
|
||||
_("[_nick] enters [_nick_place]"),
|
||||
._notice_context_leave =
|
||||
_("[_nick] leaves [_nick_place]"),
|
||||
|
||||
._echo_hello =
|
||||
_("Received hello of psyc://[_key_public]:g/"),
|
||||
._status_hello =
|
||||
_("Your hello is [_hello]"),
|
||||
._request_context_enter =
|
||||
_("[_nick] asks for your permission to enter [_nick_place]"),
|
||||
|
|
|
@ -158,6 +158,11 @@ psyc_uniform_parse (PsycUniform *uni, const char *buffer, size_t length)
|
|||
uni->body = PSYC_STRING(uni->host.data,
|
||||
length - uni->scheme.length - 1 - uni->slashes.length);
|
||||
|
||||
if (uni->slash.length) {
|
||||
uni->path.data = uni->slash.data;
|
||||
uni->path.length = length - uni->root.length;
|
||||
}
|
||||
|
||||
if (uni->resource.length)
|
||||
uni->nick = PSYC_STRING(uni->resource.data + 1, uni->resource.length);
|
||||
|
||||
|
|
|
@ -54,18 +54,25 @@ const PsycDictInt psyc_methods[] = {
|
|||
{ PSYC_C2STRI("_echo_context_leave"), PSYC_MC_ECHO_CONTEXT_LEAVE },
|
||||
{ PSYC_C2STRI("_echo_hello"), PSYC_MC_ECHO_HELLO },
|
||||
{ PSYC_C2STRI("_echo"), PSYC_MC_ECHO },
|
||||
{ PSYC_C2STRI("_failure_alias_nonexistant"),PSYC_MC_FAILURE_ALIAS_NONEXISTANT },
|
||||
{ PSYC_C2STRI("_failure_alias_unavailable"),PSYC_MC_FAILURE_ALIAS_UNAVAILABLE },
|
||||
{ PSYC_C2STRI("_failure"), PSYC_MC_FAILURE },
|
||||
{ PSYC_C2STRI("_info"), PSYC_MC_INFO },
|
||||
{ PSYC_C2STRI("_message_action"), PSYC_MC_MESSAGE_ACTION },
|
||||
{ PSYC_C2STRI("_message_echo_action"), PSYC_MC_MESSAGE_ECHO_ACTION },
|
||||
{ PSYC_C2STRI("_message_echo"), PSYC_MC_MESSAGE_ECHO },
|
||||
{ PSYC_C2STRI("_message"), PSYC_MC_MESSAGE },
|
||||
{ PSYC_C2STRI("_notice_alias_add"), PSYC_MC_NOTICE_ALIAS_ADD },
|
||||
{ PSYC_C2STRI("_notice_alias_change"), PSYC_MC_NOTICE_ALIAS_CHANGE },
|
||||
{ PSYC_C2STRI("_notice_alias_remove"), PSYC_MC_NOTICE_ALIAS_REMOVE },
|
||||
{ PSYC_C2STRI("_notice_context_enter"), PSYC_MC_NOTICE_CONTEXT_ENTER },
|
||||
{ PSYC_C2STRI("_notice_context_leave"), PSYC_MC_NOTICE_CONTEXT_LEAVE },
|
||||
{ PSYC_C2STRI("_notice_friendship"), PSYC_MC_NOTICE_FRIENDSHIP },
|
||||
{ PSYC_C2STRI("_notice_link"), PSYC_MC_NOTICE_LINK },
|
||||
{ PSYC_C2STRI("_notice_set"), PSYC_MC_NOTICE_SET },
|
||||
{ PSYC_C2STRI("_notice_unlink"), PSYC_MC_NOTICE_UNLINK },
|
||||
{ PSYC_C2STRI("_notice"), PSYC_MC_NOTICE },
|
||||
{ PSYC_C2STRI("_request_context_enter"), PSYC_MC_REQUEST_CONTEXT_ENTER },
|
||||
{ PSYC_C2STRI("_request_context_leave"), PSYC_MC_REQUEST_CONTEXT_LEAVE },
|
||||
{ PSYC_C2STRI("_request_frienship"), PSYC_MC_REQUEST_FRIENDSHIP },
|
||||
{ PSYC_C2STRI("_request"), PSYC_MC_REQUEST },
|
||||
{ PSYC_C2STRI("_status_contexts_entered"), PSYC_MC_STATUS_CONTEXTS_ENTERED },
|
||||
{ PSYC_C2STRI("_status_hello"), PSYC_MC_STATUS_HELLO },
|
||||
|
@ -104,6 +111,8 @@ psyc_method (char *method, size_t methodlen, PsycMethod *family, unsigned int *f
|
|||
| PSYC_METHOD_LOGGABLE;
|
||||
break;
|
||||
case PSYC_MC_FAILURE:
|
||||
case PSYC_MC_FAILURE_ALIAS_NONEXISTANT:
|
||||
case PSYC_MC_FAILURE_ALIAS_UNAVAILABLE:
|
||||
*family = PSYC_MC_FAILURE;
|
||||
*flag = PSYC_METHOD_TEMPLATE | PSYC_METHOD_REPLY | PSYC_METHOD_VISIBLE
|
||||
| PSYC_METHOD_LOGGABLE;
|
||||
|
@ -118,15 +127,16 @@ psyc_method (char *method, size_t methodlen, PsycMethod *family, unsigned int *f
|
|||
*family = PSYC_MC_MESSAGE;
|
||||
*flag = PSYC_METHOD_VISIBLE | PSYC_METHOD_LOGGABLE | PSYC_METHOD_MANUAL;
|
||||
break;
|
||||
case PSYC_MC_MESSAGE_ECHO:
|
||||
case PSYC_MC_MESSAGE_ECHO_ACTION:
|
||||
*family = PSYC_MC_MESSAGE_ECHO;
|
||||
*flag = PSYC_METHOD_REPLY | PSYC_METHOD_VISIBLE | PSYC_METHOD_LOGGABLE
|
||||
| PSYC_METHOD_MANUAL;
|
||||
break;
|
||||
case PSYC_MC_NOTICE:
|
||||
case PSYC_MC_NOTICE_ALIAS_ADD:
|
||||
case PSYC_MC_NOTICE_ALIAS_CHANGE:
|
||||
case PSYC_MC_NOTICE_ALIAS_REMOVE:
|
||||
case PSYC_MC_NOTICE_CONTEXT_ENTER:
|
||||
case PSYC_MC_NOTICE_CONTEXT_LEAVE:
|
||||
case PSYC_MC_NOTICE_FRIENDSHIP:
|
||||
case PSYC_MC_NOTICE_LINK:
|
||||
case PSYC_MC_NOTICE_SET:
|
||||
case PSYC_MC_NOTICE_UNLINK:
|
||||
*family = PSYC_MC_NOTICE;
|
||||
*flag = PSYC_METHOD_TEMPLATE | PSYC_METHOD_VISIBLE | PSYC_METHOD_LOGGABLE;
|
||||
break;
|
||||
|
|
|
@ -12,7 +12,11 @@ testUniform (char *str, int ret)
|
|||
int r = psyc_uniform_parse(uni, str, strlen(str));
|
||||
|
||||
PP(("[%.*s] : [%.*s] [%.*s] : [%.*s] [%.*s] / "
|
||||
"[%.*s] # [%.*s]\n[%.*s]\n[%.*s] [%.*s]\n[%.*s]\n\n",
|
||||
"[%.*s] # [%.*s]\n"
|
||||
"[%.*s]\n"
|
||||
"[%.*s] [%.*s]\n"
|
||||
"[%.*s]\n"
|
||||
"[%.*s]\n\n",
|
||||
(int)PSYC_S2ARG2(uni->scheme),
|
||||
(int)PSYC_S2ARG2(uni->slashes),
|
||||
(int)PSYC_S2ARG2(uni->host),
|
||||
|
@ -23,6 +27,7 @@ testUniform (char *str, int ret)
|
|||
(int)PSYC_S2ARG2(uni->entity),
|
||||
(int)PSYC_S2ARG2(uni->root),
|
||||
(int)PSYC_S2ARG2(uni->nick),
|
||||
(int)PSYC_S2ARG2(uni->path),
|
||||
(int)PSYC_S2ARG2(uni->body)));
|
||||
|
||||
free(uni);
|
||||
|
@ -37,6 +42,7 @@ int
|
|||
main ()
|
||||
{
|
||||
testUniform("psyc://foo.tld:4404d/@bar#baz", PSYC_SCHEME_PSYC);
|
||||
testUniform("psyc://foo.tld:4404d/#baz", PSYC_SCHEME_PSYC);
|
||||
testUniform("psyc://foo:4405/~bar", PSYC_SCHEME_PSYC);
|
||||
testUniform("psyc://foo:1234", PSYC_SCHEME_PSYC);
|
||||
testUniform("psyc://foo:1234d", PSYC_SCHEME_PSYC);
|
||||
|
|
Loading…
Reference in a new issue