mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
refactoring - init functions
This commit is contained in:
parent
19c7cadad2
commit
8906e67529
10 changed files with 158 additions and 173 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -43,7 +43,8 @@ python/*.py
|
||||||
*.rej
|
*.rej
|
||||||
*.log
|
*.log
|
||||||
*.pem
|
*.pem
|
||||||
*old
|
*.old
|
||||||
*bak
|
*.bak
|
||||||
*diff
|
*.orig
|
||||||
*orig
|
*.diff
|
||||||
|
*.patch
|
||||||
|
|
|
@ -142,13 +142,17 @@ struct Packet
|
||||||
char[] method, ubyte[] data,
|
char[] method, ubyte[] data,
|
||||||
PacketFlag flag = PacketFlag.CHECK_LENGTH)
|
PacketFlag flag = PacketFlag.CHECK_LENGTH)
|
||||||
{
|
{
|
||||||
return psyc_packet_new(&routing, &entity, cast(ubyte[]*)&method, &data, flag); // FIXME
|
Packet p;
|
||||||
|
psyc_packet_init(&p, &routing, &entity, cast(ubyte[]*)&method, &data, flag); // FIXME
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Packet opCall (Modifier[] routing, ubyte[] content,
|
static Packet opCall (Modifier[] routing, ubyte[] content,
|
||||||
PacketFlag flag = PacketFlag.CHECK_LENGTH)
|
PacketFlag flag = PacketFlag.CHECK_LENGTH)
|
||||||
{
|
{
|
||||||
return psyc_packet_new_raw(&routing, &content, flag); // FIXME
|
Packet p;
|
||||||
|
psyc_packet_init_raw(&routing, &content, flag); // FIXME
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t length ( )
|
size_t length ( )
|
||||||
|
@ -215,17 +219,19 @@ PacketFlag psyc_packet_length_check (Packet *p);
|
||||||
private size_t psyc_packet_length_set (Packet *p);
|
private size_t psyc_packet_length_set (Packet *p);
|
||||||
|
|
||||||
/** Create new list. */
|
/** Create new list. */
|
||||||
List psyc_list_new (String *elems, size_t num_elems, ListFlag flag);
|
void psyc_list_init (List *list, String *elems, size_t num_elems, ListFlag flag);
|
||||||
|
|
||||||
/** Create new packet. */
|
/** Initialize packet. */
|
||||||
Packet psyc_packet_new (Modifier *routing, size_t routinglen,
|
void psyc_packet_init (Packet packet,
|
||||||
Modifier *entity, size_t entitylen,
|
Modifier *routing, size_t routinglen,
|
||||||
char *method, size_t methodlen,
|
Modifier *entity, size_t entitylen,
|
||||||
char *data, size_t datalen,
|
char *method, size_t methodlen,
|
||||||
PacketFlag flag);
|
char *data, size_t datalen,
|
||||||
|
PacketFlag flag);
|
||||||
|
|
||||||
/** Create new packet with raw content. */
|
/** Initialize packet with raw content. */
|
||||||
Packet psyc_packet_new_raw (Modifier *routing, size_t routinglen,
|
void psyc_packet_init_raw (Packet packet,
|
||||||
char *content, size_t contentlen,
|
Modifier *routing, size_t routinglen,
|
||||||
PacketFlag flag);
|
char *content, size_t contentlen,
|
||||||
|
PacketFlag flag);
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ enum RenderListRC
|
||||||
* This function renders packet->length bytes to the buffer,
|
* This function renders packet->length bytes to the buffer,
|
||||||
* if buflen is less than that an error is returned.
|
* if buflen is less than that an error is returned.
|
||||||
*
|
*
|
||||||
* @see psyc_packet_new
|
* @see psyc_packet_init()
|
||||||
* @see psyc_packet_new_raw
|
* @see psyc_packet_init_raw()
|
||||||
* @see psyc_packet_length_set
|
* @see psyc_packet_length_set()
|
||||||
*/
|
*/
|
||||||
RenderRC psyc_render (Packet *packet, ubyte *buffer, size_t buflen);
|
RenderRC psyc_render (Packet *packet, ubyte *buffer, size_t buflen);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define PSYC_EPOCH 1440444041 // 2015-08-24 21:20:41 CET (Monday)
|
#define PSYC_VERSION 1
|
||||||
|
#define PSYC_EPOCH 1440444041 // 2015-08-24 21:20:41 CET (Monday)
|
||||||
|
|
||||||
#define PSYC_C2STR(str) {sizeof(str)-1, str}
|
#define PSYC_C2STR(str) {sizeof(str)-1, str}
|
||||||
#define PSYC_C2ARG(str) str, sizeof(str)-1
|
#define PSYC_C2ARG(str) str, sizeof(str)-1
|
||||||
|
@ -118,28 +119,6 @@ typedef struct
|
||||||
intptr_t value;
|
intptr_t value;
|
||||||
} PsycDictInt;
|
} PsycDictInt;
|
||||||
|
|
||||||
/**
|
|
||||||
* Shortcut for creating a PsycString.
|
|
||||||
*
|
|
||||||
* @param str Pointer to the buffer.
|
|
||||||
* @param len Length of that buffer.
|
|
||||||
*
|
|
||||||
* @return An instance of the PsycString struct.
|
|
||||||
*/
|
|
||||||
static inline
|
|
||||||
PsycString psyc_string_new (char *str, size_t len)
|
|
||||||
{
|
|
||||||
PsycString s = {len, str};
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
unsigned int psyc_version ()
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if long keyword string inherits from short keyword string.
|
* Checks if long keyword string inherits from short keyword string.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -121,19 +121,17 @@ PsycModifierFlag psyc_modifier_length_check (PsycModifier *m)
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create new modifier */
|
/** Initialize modifier */
|
||||||
static inline
|
static inline
|
||||||
PsycModifier psyc_modifier_new (char oper,
|
void psyc_modifier_init (PsycModifier *m, char oper,
|
||||||
char *name, size_t namelen,
|
char *name, size_t namelen,
|
||||||
char *value, size_t valuelen,
|
char *value, size_t valuelen,
|
||||||
PsycModifierFlag flag)
|
PsycModifierFlag flag)
|
||||||
{
|
{
|
||||||
PsycModifier m = {oper, {namelen, name}, {valuelen, value}, flag};
|
*m = (PsycModifier) {oper, {namelen, name}, {valuelen, value}, flag};
|
||||||
|
|
||||||
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
|
if (flag == PSYC_MODIFIER_CHECK_LENGTH) // find out if it needs a length
|
||||||
m.flag = psyc_modifier_length_check(&m);
|
m->flag = psyc_modifier_length_check(m);
|
||||||
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,20 +163,23 @@ PsycPacketFlag psyc_packet_length_check (PsycPacket *p);
|
||||||
*/
|
*/
|
||||||
size_t psyc_packet_length_set (PsycPacket *p);
|
size_t psyc_packet_length_set (PsycPacket *p);
|
||||||
|
|
||||||
/** Create new list. */
|
/** Initialize list. */
|
||||||
PsycList psyc_list_new (PsycString *elems, size_t num_elems, PsycListFlag flag);
|
void psyc_list_init (PsycList *list, PsycString *elems, size_t num_elems,
|
||||||
|
PsycListFlag flag);
|
||||||
|
|
||||||
/** Create new packet. */
|
/** Initialize packet. */
|
||||||
PsycPacket psyc_packet_new (PsycModifier *routing, size_t routinglen,
|
void psyc_packet_init (PsycPacket *packet,
|
||||||
PsycModifier *entity, size_t entitylen,
|
PsycModifier *routing, size_t routinglen,
|
||||||
char *method, size_t methodlen,
|
PsycModifier *entity, size_t entitylen,
|
||||||
char *data, size_t datalen,
|
char *method, size_t methodlen,
|
||||||
PsycPacketFlag flag);
|
char *data, size_t datalen,
|
||||||
|
PsycPacketFlag flag);
|
||||||
|
|
||||||
/** Create new packet with raw content. */
|
/** Initialize packet with raw content. */
|
||||||
PsycPacket psyc_packet_new_raw (PsycModifier *routing, size_t routinglen,
|
void psyc_packet_init_raw (PsycPacket *packet,
|
||||||
char *content, size_t contentlen,
|
PsycModifier *routing, size_t routinglen,
|
||||||
PsycPacketFlag flag);
|
char *content, size_t contentlen,
|
||||||
|
PsycPacketFlag flag);
|
||||||
|
|
||||||
/** @} */ // end of packet group
|
/** @} */ // end of packet group
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ typedef enum
|
||||||
* This function renders packet->length bytes to the buffer,
|
* This function renders packet->length bytes to the buffer,
|
||||||
* if buflen is less than that an error is returned.
|
* if buflen is less than that an error is returned.
|
||||||
*
|
*
|
||||||
* @see psyc_packet_new
|
* @see psyc_packet_init()
|
||||||
* @see psyc_packet_new_raw
|
* @see psyc_packet_init_raw()
|
||||||
* @see psyc_packet_length_set
|
* @see psyc_packet_length_set()
|
||||||
*/
|
*/
|
||||||
#ifdef __INLINE_PSYC_RENDER
|
#ifdef __INLINE_PSYC_RENDER
|
||||||
static inline
|
static inline
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "interpret.h"
|
#include "interpret.h"
|
||||||
#include "stralloc.h"
|
#include "stralloc.h"
|
||||||
#include "mapping.h"
|
#include "mapping.h"
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
#include "svalue.h"
|
#include "svalue.h"
|
||||||
#include "operators.h"
|
#include "operators.h"
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
#include "builtin_functions.h"
|
#include "builtin_functions.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -37,7 +37,7 @@ PsycTextValueRC lookup_value_mapping(const char *name, size_t len, PsycString *v
|
||||||
//printf("lookup_value_mapping called for %.*s\n", (int) len, name);
|
//printf("lookup_value_mapping called for %.*s\n", (int) len, name);
|
||||||
struct pike_string *key = make_shared_binary_string(name, len);
|
struct pike_string *key = make_shared_binary_string(name, len);
|
||||||
struct mapping *m = (struct mapping *) extra;
|
struct mapping *m = (struct mapping *) extra;
|
||||||
struct svalue *s = low_mapping_string_lookup(m, key);
|
struct svalue *s = low_mapping_string_lookup(m, key);
|
||||||
free_string(key);
|
free_string(key);
|
||||||
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
|
@ -125,17 +125,15 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
||||||
|
|
||||||
// fill headers
|
// fill headers
|
||||||
rheaders.lines = 0;
|
rheaders.lines = 0;
|
||||||
rheaders.modifiers = malloc(sizeof(PsycModifier) * rvars->data->size);
|
rheaders.modifiers = malloc(sizeof(PsycModifier) * rvars->data->size);
|
||||||
NEW_MAPPING_LOOP(rvars->data) {
|
NEW_MAPPING_LOOP(rvars->data) {
|
||||||
if (k->ind.type == PIKE_T_STRING) {
|
if (k->ind.type == PIKE_T_STRING) {
|
||||||
switch(k->val.type) {
|
switch(k->val.type) {
|
||||||
case PIKE_T_STRING:
|
case PIKE_T_STRING:
|
||||||
rheaders.modifiers[rheaders.lines++] = psyc_modifier_new(oper,
|
psyc_modifier_init(&rheaders.modifiers[rheaders.lines++], oper,
|
||||||
(char *)STR0(k->ind.u.string),
|
(char *)STR0(k->ind.u.string), k->ind.u.string->len,
|
||||||
k->ind.u.string->len,
|
(char *)STR0(k->val.u.string), k->val.u.string->len,
|
||||||
(char *)STR0(k->val.u.string),
|
PSYC_MODIFIER_ROUTING);
|
||||||
k->val.u.string->len,
|
|
||||||
PSYC_MODIFIER_ROUTING);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Pike_error("psyc render: unsupported non-string value in rvars\n");
|
Pike_error("psyc render: unsupported non-string value in rvars\n");
|
||||||
|
@ -147,7 +145,7 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
||||||
}
|
}
|
||||||
|
|
||||||
eheaders.lines = 0;
|
eheaders.lines = 0;
|
||||||
eheaders.modifiers = malloc(sizeof(PsycModifier) * evars->data->size);
|
eheaders.modifiers = malloc(sizeof(PsycModifier) * evars->data->size);
|
||||||
NEW_MAPPING_LOOP(evars->data) {
|
NEW_MAPPING_LOOP(evars->data) {
|
||||||
if (k->ind.type == PIKE_T_STRING) {
|
if (k->ind.type == PIKE_T_STRING) {
|
||||||
char *key;
|
char *key;
|
||||||
|
@ -157,7 +155,7 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
||||||
struct pike_string *s;
|
struct pike_string *s;
|
||||||
|
|
||||||
key = (char *) STR0(k->ind.u.string);
|
key = (char *) STR0(k->ind.u.string);
|
||||||
keylen = k->ind.u.string->len;
|
keylen = k->ind.u.string->len;
|
||||||
|
|
||||||
switch(k->val.type) {
|
switch(k->val.type) {
|
||||||
case PIKE_T_INT:
|
case PIKE_T_INT:
|
||||||
|
@ -197,7 +195,7 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
||||||
Pike_error("psyc_render: unsupported data type in list\n");
|
Pike_error("psyc_render: unsupported data type in list\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list = psyc_list_new(elems, k->val.u.array->size, PSYC_LIST_CHECK_LENGTH);
|
psyc_list_init(&list, elems, k->val.u.array->size, PSYC_LIST_CHECK_LENGTH);
|
||||||
|
|
||||||
struct pike_string *listbuf = begin_shared_string(list.length);
|
struct pike_string *listbuf = begin_shared_string(list.length);
|
||||||
psyc_render_list(&list, (char *) STR0(listbuf), listbuf->len);
|
psyc_render_list(&list, (char *) STR0(listbuf), listbuf->len);
|
||||||
|
@ -211,37 +209,32 @@ PIKEFUN string render(mapping rvars, mapping evars, string method, string|void b
|
||||||
Pike_error("psyc_render: unsupported value in evars\n");
|
Pike_error("psyc_render: unsupported value in evars\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
eheaders.modifiers[eheaders.lines++] = psyc_modifier_new(oper,
|
psyc_modifier_init(&eheaders.modifiers[eheaders.lines++], oper,
|
||||||
key, keylen,
|
key, keylen,
|
||||||
val, vallen,
|
val, vallen,
|
||||||
PSYC_MODIFIER_CHECK_LENGTH);
|
PSYC_MODIFIER_CHECK_LENGTH);
|
||||||
} else {
|
} else {
|
||||||
Pike_error("psyc render: unsupported non-string key in evars\n");
|
Pike_error("psyc render: unsupported non-string key in evars\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
packet = psyc_packet_new(rheaders.modifiers,
|
psyc_packet_init(&packet, rheaders.modifiers, rheaders.lines,
|
||||||
rheaders.lines,
|
eheaders.modifiers, eheaders.lines,
|
||||||
eheaders.modifiers,
|
(const char *)STR0(method), method->len,
|
||||||
eheaders.lines,
|
(const char *)STR0(body), body->len,
|
||||||
(const char *)STR0(method), method->len,
|
PSYC_PACKET_CHECK_LENGTH);
|
||||||
(const char *)STR0(body), body->len,
|
|
||||||
PSYC_PACKET_CHECK_LENGTH);
|
|
||||||
} else { // body arg was not given
|
} else { // body arg was not given
|
||||||
packet = psyc_packet_new(rheaders.modifiers,
|
psyc_packet_init(&packet, rheaders.modifiers, rheaders.lines,
|
||||||
rheaders.lines,
|
eheaders.modifiers, eheaders.lines,
|
||||||
eheaders.modifiers,
|
(const char *)STR0(method), method->len,
|
||||||
eheaders.lines,
|
NULL, 0, PSYC_PACKET_CHECK_LENGTH);
|
||||||
(const char *)STR0(method), method->len,
|
|
||||||
NULL, 0,
|
|
||||||
PSYC_PACKET_CHECK_LENGTH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pike_string *s = begin_shared_string(packet.length);
|
struct pike_string *s = begin_shared_string(packet.length);
|
||||||
psyc_render(&packet, (char *) STR0(s), packet.length);
|
psyc_render(&packet, (char *) STR0(s), packet.length);
|
||||||
// pop_n_elems(args);
|
// pop_n_elems(args);
|
||||||
RETURN end_shared_string(s);
|
RETURN end_shared_string(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKECLASS Parser {
|
PIKECLASS Parser {
|
||||||
|
@ -360,7 +353,7 @@ PIKECLASS Parser {
|
||||||
make_shared_binary_string(name.data, name.length),
|
make_shared_binary_string(name.data, name.length),
|
||||||
&sv);
|
&sv);
|
||||||
} else {
|
} else {
|
||||||
err = 3;
|
err = 3;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PSYC_TYPE_FLAG:
|
case PSYC_TYPE_FLAG:
|
||||||
|
@ -415,7 +408,7 @@ PIKECLASS Parser {
|
||||||
make_shared_binary_string(value.data, value.length));
|
make_shared_binary_string(value.data, value.length));
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
if (err) { // there was an error while
|
if (err) { // there was an error while
|
||||||
// FIXME
|
// FIXME
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -443,14 +436,14 @@ PIKECLASS Parser {
|
||||||
push_mapping(THIS->rvars);
|
push_mapping(THIS->rvars);
|
||||||
push_mapping(THIS->evars);
|
push_mapping(THIS->evars);
|
||||||
if (THIS->method == NULL) {
|
if (THIS->method == NULL) {
|
||||||
apply_low(Pike_fp->current_object, THIS->handle_packet, 2);
|
apply_low(Pike_fp->current_object, THIS->handle_packet, 2);
|
||||||
} else if (THIS->body == NULL) {
|
} else if (THIS->body == NULL) {
|
||||||
push_string(THIS->method);
|
push_string(THIS->method);
|
||||||
apply_low(Pike_fp->current_object, THIS->handle_packet, 3);
|
apply_low(Pike_fp->current_object, THIS->handle_packet, 3);
|
||||||
} else {
|
} else {
|
||||||
push_string(THIS->method);
|
push_string(THIS->method);
|
||||||
push_string(THIS->body);
|
push_string(THIS->body);
|
||||||
apply_low(Pike_fp->current_object, THIS->handle_packet, 4);
|
apply_low(Pike_fp->current_object, THIS->handle_packet, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset packet state
|
// reset packet state
|
||||||
|
@ -467,7 +460,7 @@ PIKECLASS Parser {
|
||||||
return;
|
return;
|
||||||
default: // fatal error
|
default: // fatal error
|
||||||
push_int(ret);
|
push_int(ret);
|
||||||
apply_low(Pike_fp->current_object, THIS->handle_error, 1);
|
apply_low(Pike_fp->current_object, THIS->handle_error, 1);
|
||||||
// FIXME: free stuff? or do we kill the socket and parser anyway
|
// FIXME: free stuff? or do we kill the socket and parser anyway
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
50
src/packet.c
50
src/packet.c
|
@ -48,15 +48,15 @@ PsycListFlag psyc_list_length (PsycList *list)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
PsycList psyc_list_new (PsycString *elems, size_t num_elems, PsycListFlag flag)
|
void psyc_list_init (PsycList *list, PsycString *elems, size_t num_elems,
|
||||||
|
PsycListFlag flag)
|
||||||
{
|
{
|
||||||
PsycList list = {num_elems, elems, 0, flag};
|
*list = (PsycList) {num_elems, elems, 0, flag};
|
||||||
|
|
||||||
if (flag == PSYC_LIST_CHECK_LENGTH) // check if list elements need length
|
if (flag == PSYC_LIST_CHECK_LENGTH) // check if list elements need length
|
||||||
list.flag = psyc_list_length_check(&list);
|
list->flag = psyc_list_length_check(list);
|
||||||
|
|
||||||
list.length = psyc_list_length(&list);
|
list->length = psyc_list_length(list);
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,33 +134,33 @@ size_t psyc_packet_length_set (PsycPacket *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
PsycPacket psyc_packet_new (PsycModifier *routing, size_t routinglen,
|
void psyc_packet_init (PsycPacket *p,
|
||||||
PsycModifier *entity, size_t entitylen,
|
PsycModifier *routing, size_t routinglen,
|
||||||
char *method, size_t methodlen,
|
PsycModifier *entity, size_t entitylen,
|
||||||
char *data, size_t datalen,
|
char *method, size_t methodlen,
|
||||||
PsycPacketFlag flag)
|
char *data, size_t datalen,
|
||||||
|
PsycPacketFlag flag)
|
||||||
{
|
{
|
||||||
PsycPacket p = {{routinglen, routing}, {entitylen, entity},
|
*p = (PsycPacket) {{routinglen, routing}, {entitylen, entity},
|
||||||
{methodlen, method}, {datalen, data}, {0,0}, 0, 0, flag};
|
{methodlen, method}, {datalen, data}, {0,0}, 0, 0, flag};
|
||||||
|
|
||||||
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs a length
|
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs length
|
||||||
p.flag = psyc_packet_length_check(&p);
|
p->flag = psyc_packet_length_check(p);
|
||||||
|
|
||||||
psyc_packet_length_set(&p);
|
psyc_packet_length_set(p);
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
PsycPacket psyc_packet_new_raw (PsycModifier *routing, size_t routinglen,
|
void psyc_packet_init_raw (PsycPacket *p,
|
||||||
char *content, size_t contentlen,
|
PsycModifier *routing, size_t routinglen,
|
||||||
PsycPacketFlag flag)
|
char *content, size_t contentlen,
|
||||||
|
PsycPacketFlag flag)
|
||||||
{
|
{
|
||||||
PsycPacket p = {{routinglen, routing}, {0,0}, {0,0}, {0,0},
|
*p = (PsycPacket) {{routinglen, routing}, {0,0}, {0,0}, {0,0},
|
||||||
{contentlen, content}, 0, 0, flag};
|
{contentlen, content}, 0, 0, flag};
|
||||||
|
|
||||||
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs a length
|
if (flag == PSYC_PACKET_CHECK_LENGTH) // find out if it needs length
|
||||||
p.flag = psyc_packet_length_check(&p);
|
p->flag = psyc_packet_length_check(p);
|
||||||
|
|
||||||
psyc_packet_length_set(&p);
|
psyc_packet_length_set(p);
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ int main (int argc, char **argv) {
|
||||||
for (i=0; i<NELEMS; i++)
|
for (i=0; i<NELEMS; i++)
|
||||||
elems_bin[i] = (PsycString) PSYC_C2STR("1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890");
|
elems_bin[i] = (PsycString) PSYC_C2STR("1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890|abcdefghijklmnopqrstuvwxyz|_\n1234567890");
|
||||||
|
|
||||||
list_text = psyc_list_new(elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_NO_LENGTH);
|
psyc_list_init(&list_text, elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_NO_LENGTH);
|
||||||
list_bin = psyc_list_new(elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
psyc_list_init(&list_bin, elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
||||||
|
|
||||||
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
||||||
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
||||||
|
|
|
@ -11,24 +11,26 @@ int testPresence (const char *avail, int availlen,
|
||||||
const char *desc, int desclen,
|
const char *desc, int desclen,
|
||||||
const char *rendered, uint8_t verbose)
|
const char *rendered, uint8_t verbose)
|
||||||
{
|
{
|
||||||
PsycModifier routing[] = {
|
PsycModifier routing[1];
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
|
psyc_modifier_init(&routing[0], C_GLYPH_OPERATOR_SET,
|
||||||
PSYC_MODIFIER_ROUTING),
|
PSYC_C2ARG("_context"),
|
||||||
};
|
PSYC_C2ARG(myUNI), PSYC_MODIFIER_ROUTING);
|
||||||
|
|
||||||
PsycModifier entity[] = {
|
PsycModifier entity[2];
|
||||||
// presence is to be assigned permanently in distributed state
|
// presence is to be assigned permanently in distributed state
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_degree_availability"),
|
psyc_modifier_init(&entity[0], C_GLYPH_OPERATOR_ASSIGN,
|
||||||
avail, availlen, PSYC_MODIFIER_CHECK_LENGTH),
|
PSYC_C2ARG("_degree_availability"),
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_ASSIGN, PSYC_C2ARG("_description_presence"),
|
avail, availlen, PSYC_MODIFIER_CHECK_LENGTH);
|
||||||
desc, desclen, PSYC_MODIFIER_CHECK_LENGTH),
|
psyc_modifier_init(&entity[1], C_GLYPH_OPERATOR_ASSIGN,
|
||||||
};
|
PSYC_C2ARG("_description_presence"),
|
||||||
|
desc, desclen, PSYC_MODIFIER_CHECK_LENGTH);
|
||||||
|
|
||||||
PsycPacket packet = psyc_packet_new(routing, PSYC_NUM_ELEM(routing),
|
PsycPacket packet;
|
||||||
entity, PSYC_NUM_ELEM(entity),
|
psyc_packet_init(&packet, routing, PSYC_NUM_ELEM(routing),
|
||||||
PSYC_C2ARG("_notice_presence"),
|
entity, PSYC_NUM_ELEM(entity),
|
||||||
NULL, 0,
|
PSYC_C2ARG("_notice_presence"),
|
||||||
PSYC_PACKET_CHECK_LENGTH);
|
NULL, 0,
|
||||||
|
PSYC_PACKET_CHECK_LENGTH);
|
||||||
|
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
psyc_render(&packet, buffer, sizeof(buffer));
|
psyc_render(&packet, buffer, sizeof(buffer));
|
||||||
|
@ -39,12 +41,13 @@ int testPresence (const char *avail, int availlen,
|
||||||
|
|
||||||
int testList (const char *rendered, uint8_t verbose)
|
int testList (const char *rendered, uint8_t verbose)
|
||||||
{
|
{
|
||||||
PsycModifier routing[] = {
|
PsycModifier routing[2];
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_source"), PSYC_C2ARG(myUNI),
|
psyc_modifier_init(&routing[0], C_GLYPH_OPERATOR_SET,
|
||||||
PSYC_MODIFIER_ROUTING),
|
PSYC_C2ARG("_source"),
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_context"), PSYC_C2ARG(myUNI),
|
PSYC_C2ARG(myUNI), PSYC_MODIFIER_ROUTING);
|
||||||
PSYC_MODIFIER_ROUTING),
|
psyc_modifier_init(&routing[1], C_GLYPH_OPERATOR_SET,
|
||||||
};
|
PSYC_C2ARG("_context"),
|
||||||
|
PSYC_C2ARG(myUNI), PSYC_MODIFIER_ROUTING);
|
||||||
|
|
||||||
PsycString elems_text[] = {
|
PsycString elems_text[] = {
|
||||||
PSYC_C2STR("foo"),
|
PSYC_C2STR("foo"),
|
||||||
|
@ -59,25 +62,27 @@ int testList (const char *rendered, uint8_t verbose)
|
||||||
};
|
};
|
||||||
|
|
||||||
PsycList list_text, list_bin;
|
PsycList list_text, list_bin;
|
||||||
list_text = psyc_list_new(elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_CHECK_LENGTH);
|
psyc_list_init(&list_text, elems_text, PSYC_NUM_ELEM(elems_text), PSYC_LIST_CHECK_LENGTH);
|
||||||
list_bin = psyc_list_new(elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
psyc_list_init(&list_bin, elems_bin, PSYC_NUM_ELEM(elems_bin), PSYC_LIST_CHECK_LENGTH);
|
||||||
|
|
||||||
char buf_text[32], buf_bin[32];
|
char buf_text[32], buf_bin[32];
|
||||||
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
psyc_render_list(&list_text, buf_text, sizeof(buf_text));
|
||||||
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
psyc_render_list(&list_bin, buf_bin, sizeof(buf_bin));
|
||||||
|
|
||||||
PsycModifier entity[] = {
|
PsycModifier entity[2];
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_list_text"),
|
psyc_modifier_init(&entity[0], C_GLYPH_OPERATOR_SET,
|
||||||
buf_text, list_text.length, list_text.flag),
|
PSYC_C2ARG("_list_text"),
|
||||||
psyc_modifier_new(C_GLYPH_OPERATOR_SET, PSYC_C2ARG("_list_binary"),
|
buf_text, list_text.length, list_text.flag);
|
||||||
buf_bin, list_bin.length, list_bin.flag),
|
psyc_modifier_init(&entity[1], C_GLYPH_OPERATOR_SET,
|
||||||
};
|
PSYC_C2ARG("_list_binary"),
|
||||||
|
buf_bin, list_bin.length, list_bin.flag);
|
||||||
|
|
||||||
PsycPacket packet = psyc_packet_new(routing, PSYC_NUM_ELEM(routing),
|
PsycPacket packet;
|
||||||
entity, PSYC_NUM_ELEM(entity),
|
psyc_packet_init(&packet, routing, PSYC_NUM_ELEM(routing),
|
||||||
PSYC_C2ARG("_test_list"),
|
entity, PSYC_NUM_ELEM(entity),
|
||||||
PSYC_C2ARG("list test"),
|
PSYC_C2ARG("_test_list"),
|
||||||
PSYC_PACKET_CHECK_LENGTH);
|
PSYC_C2ARG("list test"),
|
||||||
|
PSYC_PACKET_CHECK_LENGTH);
|
||||||
|
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
psyc_render(&packet, buffer, sizeof(buffer));
|
psyc_render(&packet, buffer, sizeof(buffer));
|
||||||
|
|
Loading…
Reference in a new issue