1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00

psyc_is_var_routing() -> psyc_var_routing()

This commit is contained in:
tg(x) 2012-01-31 19:34:11 +01:00
parent 8fcceff88f
commit eaeab8c226
7 changed files with 76 additions and 76 deletions

View file

@ -1,7 +1,7 @@
#ifndef PSYC_METHOD_H
#define PSYC_METHOD_H
typedef enum PsycMethodFlag {
typedef enum {
PSYC_METHOD_TEMPLATE = 1 << 0,
PSYC_METHOD_REPLY = 1 << 1,
PSYC_METHOD_VISIBLE = 1 << 2,
@ -9,7 +9,7 @@ typedef enum PsycMethodFlag {
PSYC_METHOD_MANUAL = 1 << 4,
} PsycMethodFlag;
typedef enum PsycMethod {
typedef enum {
PSYC_MC_UNKNOWN,
PSYC_MC_DATA,

View file

@ -8,8 +8,7 @@
#include "packet.h"
/// Routing variables in alphabetical order.
//extern const PsycString psyc_routing_vars[];
extern const PsycDictInt psyc_routing_vars[];
extern const PsycDictInt psyc_rvars[];
// Variable types in alphabetical order.
extern const PsycDictInt psyc_var_types[];
@ -17,18 +16,35 @@ extern const PsycDictInt psyc_var_types[];
/// Method names in alphabetical order.
extern const PsycDictInt psyc_methods[];
extern const size_t psyc_routing_vars_num;
extern const size_t psyc_rvars_num;
extern const size_t psyc_var_types_num;
extern const size_t psyc_methods_num;
typedef enum {
PSYC_RVAR_UNKNOWN,
PSYC_RVAR_AMOUNT_FRAGMENTS,
PSYC_RVAR_CONTEXT,
PSYC_RVAR_COUNTER,
PSYC_RVAR_FRAGMENT,
PSYC_RVAR_SOURCE,
PSYC_RVAR_SOURCE_RELAY,
PSYC_RVAR_TAG,
PSYC_RVAR_TAG_RELAY,
PSYC_RVAR_TARGET,
PSYC_RVAR_TARGET_RELAY,
PSYC_RVARS_NUM,
} PsycRoutingVar;
/**
* Is this a routing variable name?
* Look up routing variable.
*/
static inline PsycBool
psyc_var_is_routing (const char *name, size_t len)
static inline PsycRoutingVar
psyc_var_routing (const char *name, size_t len)
{
return (PsycBool) psyc_dict_lookup((PsycDict *)psyc_routing_vars,
psyc_routing_vars_num, name, len, PSYC_NO);
return (PsycRoutingVar) psyc_dict_lookup((PsycDict *)psyc_rvars,
psyc_rvars_num, name, len, PSYC_NO);
}
/**

View file

@ -99,7 +99,7 @@ PIKEFUN string psyc_text(string template, mapping vars) {
*! 0 otherwise
*/
PIKEFUN int is_routingvar(string name) {
RETURN psyc_var_is_routing((char *) STR0(name), name->len);
RETURN psyc_var_routing((char *) STR0(name), name->len);
}
/*! @decl string render(mapping rvars, mapping evars, string method, string|void body)

View file

@ -3,31 +3,31 @@
#include <psyc/packet.h>
/// Routing variables in alphabetical order.
//const PsycString psyc_routing_vars[] = {
const PsycDictInt psyc_routing_vars[] = {
{ PSYC_C2STRI("_amount_fragments"), 1 },
{ PSYC_C2STRI("_context"), 1 },
//{ PSYC_C2STRI("_count"), 1 }, // older PSYC
{ PSYC_C2STRI("_counter"), 1 },
{ PSYC_C2STRI("_fragment"), 1 },
//{ PSYC_C2STRI("_length"), 1 }, // older PSYC
{ PSYC_C2STRI("_source"), 1 },
//{ PSYC_C2STRI("_source_identification"), 1 }, // older PSYC
{ PSYC_C2STRI("_source_identity"), 1 },
{ PSYC_C2STRI("_source_relay"), 1 },
// until you have a better idea.. is this really in use?
{ PSYC_C2STRI("_source_relay_relay"), 1 },
{ PSYC_C2STRI("_tag"), 1 },
{ PSYC_C2STRI("_tag_relay"), 1 },
//{ PSYC_C2STRI("_tag_reply"), 1 }, // older PSYC
{ PSYC_C2STRI("_target"), 1 },
{ PSYC_C2STRI("_target_forward"), 1 },
{ PSYC_C2STRI("_target_relay"), 1 },
//{ PSYC_C2STRI("_understand_modules"), 1 }, // older PSYC
//{ PSYC_C2STRI("_using_modules"), 1 }, // older PSYC
const PsycDictInt psyc_rvars[] = {
{ PSYC_C2STRI("_amount_fragments"), PSYC_RVAR_AMOUNT_FRAGMENTS },
{ PSYC_C2STRI("_context"), PSYC_RVAR_CONTEXT },
{ PSYC_C2STRI("_counter"), PSYC_RVAR_COUNTER },
{ PSYC_C2STRI("_fragment"), PSYC_RVAR_FRAGMENT },
{ PSYC_C2STRI("_source"), PSYC_RVAR_SOURCE },
{ PSYC_C2STRI("_source_relay"), PSYC_RVAR_SOURCE_RELAY },
{ PSYC_C2STRI("_tag"), PSYC_RVAR_TAG },
{ PSYC_C2STRI("_tag_relay"), PSYC_RVAR_TAG_RELAY },
{ PSYC_C2STRI("_target"), PSYC_RVAR_TARGET },
{ PSYC_C2STRI("_target_relay"), PSYC_RVAR_TARGET_RELAY },
/* old psyc:
{ PSYC_C2STRI("_length"), PSYC_RVAR_LENGTH },
{ PSYC_C2STRI("_source_identification"), PSYC_RVAR_SOURCE_IDENTIFICATION },
{ PSYC_C2STRI("_source_identity"), PSYC_RVAR_SOURCE_IDENTITY },
{ PSYC_C2STRI("_source_relay_relay"), PSYC_RVAR_RELAY_RELAY },
{ PSYC_C2STRI("_tag_reply"), PSYC_RVAR_TAG_REPLY },
{ PSYC_C2STRI("_target_forward"), PSYC_RVAR_TARGET_FORWARD },
{ PSYC_C2STRI("_understand_modules"), PSYC_RVAR_UNDERSTAND_MODULES },
{ PSYC_C2STRI("_using_modules"), PSYC_RVAR_USING_MODULES },
*/
};
const size_t psyc_rvars_num = PSYC_NUM_ELEM(psyc_rvars);
// Variable types in alphabetical order.
const PsycDictInt psyc_var_types[] = {
@ -46,6 +46,7 @@ const PsycDictInt psyc_var_types[] = {
{ PSYC_C2STRI("_time"), PSYC_TYPE_TIME },
{ PSYC_C2STRI("_uniform"), PSYC_TYPE_UNIFORM },
};
const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types);
/// Method names in alphabetical order.
const PsycDictInt psyc_methods[] = {
@ -79,9 +80,6 @@ const PsycDictInt psyc_methods[] = {
{ PSYC_C2STRI("_status"), PSYC_MC_STATUS },
{ PSYC_C2STRI("_warning"), PSYC_MC_WARNING },
};
const size_t psyc_routing_vars_num = PSYC_NUM_ELEM(psyc_routing_vars);
const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types);
const size_t psyc_methods_num = PSYC_NUM_ELEM(psyc_methods);
/**

View file

@ -3,7 +3,7 @@ DEBUG = 2
CFLAGS = -I../include -I../src -Wall -std=c99 ${OPT}
LDFLAGS = -L../lib
LOADLIBES = -lpsyc -lm
TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_is_routing var_type uniform_parse test_list test_table test_packet_id method
TARGETS = test_psyc test_psyc_speed test_parser test_match test_render test_text var_routing var_type uniform_parse test_list test_table test_packet_id method
O = test.o
WRAPPER =
DIET = diet
@ -45,7 +45,7 @@ test: ${TARGETS}
./test_render
./test_match
./test_text
./var_is_routing
./var_routing
./var_type
./uniform_parse
./test_list

View file

@ -1,37 +0,0 @@
#include <psyc.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <lib.h>
int main() {
#if 0
const char* vars[] = {
"_source",
"_source_relay",
"_source_foo",
"_sourcherry",
"_foo",
"bar",
"_",
};
int i;
for (i = 0; i < sizeof(vars) / sizeof(*vars); i++) {
printf(">> %s: %d %d\n", vars[i], sizeof(vars[i]), sizeof(*vars[i]));
printf("%s: %d\n", vars[i], psyc_var_is_routing(vars[i], strlen(vars[i])));
}
#else
unless (psyc_var_is_routing(PSYC_C2ARG("_source"))) return 1;
unless (psyc_var_is_routing(PSYC_C2ARG("_source_relay"))) return 2;
if (psyc_var_is_routing(PSYC_C2ARG("_source_foo"))) return 3;
if (psyc_var_is_routing(PSYC_C2ARG("_sourcherry"))) return 4;
if (psyc_var_is_routing(PSYC_C2ARG("_sour"))) return 5;
if (psyc_var_is_routing(PSYC_C2ARG("_foo"))) return 6;
if (psyc_var_is_routing(PSYC_C2ARG("bar"))) return 7;
if (psyc_var_is_routing(PSYC_C2ARG("_"))) return 8;
puts("psyc_var_is_routing passed all tests.");
#endif
return 0; // passed all tests
}

23
test/var_routing.c Normal file
View file

@ -0,0 +1,23 @@
#include <psyc.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <lib.h>
int main() {
int i;
for (i = 0; i < psyc_rvars_num; i++)
if (psyc_var_routing(PSYC_S2ARG(psyc_rvars[i].key)) != psyc_rvars[i].value)
return i + 1;
if (psyc_var_routing(PSYC_C2ARG("_source_foo"))) return 3;
if (psyc_var_routing(PSYC_C2ARG("_sourcherry"))) return 4;
if (psyc_var_routing(PSYC_C2ARG("_sour"))) return 5;
if (psyc_var_routing(PSYC_C2ARG("_foo"))) return 6;
if (psyc_var_routing(PSYC_C2ARG("bar"))) return 7;
if (psyc_var_routing(PSYC_C2ARG("_"))) return 8;
puts("psyc_var_routing passed all tests.");
return 0;
}