Skip to content
Browse files

1.2 branch :

- Properties are now dynamic (PROP RAW) (wip)
- Initial work on channel/user SSJS dynamic properties (remote setter)
  • Loading branch information...
1 parent 358ea62 commit ee7c7d04c4ecbb8ac1349bf22326f6f2d26c1c08 @paraboul paraboul committed Jun 16, 2011
Showing with 320 additions and 92 deletions.
  1. +1 −1 Makefile
  2. +1 −1 bin/ape.conf
  3. +60 −10 modules/libape-spidermonkey.c
  4. +1 −0 scripts/main.ape.js
  5. +31 −19 src/channel.c
  6. +1 −1 src/channel.h
  7. +123 −7 src/extend.c
  8. +16 −5 src/extend.h
  9. +5 −4 src/json.c
  10. +1 −1 src/json.h
  11. +23 −13 src/pipe.c
  12. +2 −3 src/pipe.h
  13. +28 −10 src/raw.c
  14. +1 −1 src/raw.h
  15. +24 −14 src/users.c
  16. +2 −2 src/users.h
View
2 Makefile
@@ -6,7 +6,7 @@ bindir = $(prefix)/bin
SRC=src/entry.c src/sock.c src/hash.c src/handle_http.c src/cmd.c src/users.c src/channel.c src/config.c src/json.c src/json_parser.c src/plugins.c src/http.c src/extend.c src/utils.c src/ticks.c src/base64.c src/pipe.c src/raw.c src/events.c src/event_kqueue.c src/event_epoll.c src/event_select.c src/transports.c src/servers.c src/dns.c src/sha1.c src/log.c src/parser.c src/md5.c
-CFLAGS = -Wall -O2 -minline-all-stringops -rdynamic -I ./deps/udns-0.0.9/
+CFLAGS = -Wall -g -minline-all-stringops -rdynamic -I ./deps/udns-0.0.9/
LFLAGS=-ldl -lm -lpthread
CC=gcc -D_GNU_SOURCE
RM=rm -f
View
2 bin/ape.conf
@@ -6,7 +6,7 @@ uid {
Server {
- port = 6969
+ port = 6970
daemon = no
ip_listen = 0.0.0.0
domain = auto
View
70 modules/libape-spidermonkey.c
@@ -21,7 +21,7 @@
/* HOWTO : http://www.ape-project.org/wiki/index.php/How_to_build_a_serverside_JS_module */
#define XP_UNIX
-
+#define DEBUG 1
#include "../src/configure.h"
#ifdef _USE_MYSQL
#include <mysac.h>
@@ -612,7 +612,7 @@ APE_JS_NATIVE(apepipe_sm_to_object)
return JS_TRUE;
}
- pipe_object = get_json_object_pipe(spipe);
+ pipe_object = get_json_object_pipe(spipe, 1);
js_pipe_object = ape_json_to_jsobj(cx, pipe_object->jchild.child, NULL);
@@ -659,15 +659,15 @@ static JSBool sm_send_raw(JSContext *cx, transpipe *to_pipe, int chl, uintN argc
transpipe *from_pipe = JS_GetPrivate(cx, js_pipe);
if (from_pipe != NULL && from_pipe->type == USER_PIPE) {
- json_set_property_objN(jstr, "from", 4, get_json_object_pipe(from_pipe));
+ json_set_property_objN(jstr, "from", 4, get_json_object_pipe(from_pipe, 0));
if (to_pipe->type == USER_PIPE) {
- json_set_property_objN(jstr, "pipe", 4, get_json_object_pipe(from_pipe));
+ json_set_property_objN(jstr, "pipe", 4, get_json_object_pipe(from_pipe, 0));
} else if (to_pipe->type == CHANNEL_PIPE) {
json_item *jcopy = json_item_copy(jstr, NULL);
if (((CHANNEL*)to_pipe->pipe)->head != NULL && ((CHANNEL*)to_pipe->pipe)->head->next != NULL) {
- json_set_property_objN(jstr, "pipe", 4, get_json_object_pipe(to_pipe));
+ json_set_property_objN(jstr, "pipe", 4, get_json_object_pipe(to_pipe, 0));
newraw = forge_raw(raw, jstr);
post_raw_channel_restricted(newraw, to_pipe->pipe, from_pipe->pipe, g_ape);
@@ -676,7 +676,7 @@ static JSBool sm_send_raw(JSContext *cx, transpipe *to_pipe, int chl, uintN argc
JSObject *subjs = JSVAL_TO_OBJECT(vp);
subuser *sub = JS_GetPrivate(cx, subjs);
if (sub != NULL && ((USERS *)from_pipe->pipe)->nsub > 1) {
- json_set_property_objN(jcopy, "pipe", 4, get_json_object_pipe(to_pipe));
+ json_set_property_objN(jcopy, "pipe", 4, get_json_object_pipe(to_pipe, 0));
newraw = forge_raw(raw, jcopy);
post_raw_restricted(newraw, from_pipe->pipe, sub, g_ape);
} else {
@@ -689,7 +689,7 @@ static JSBool sm_send_raw(JSContext *cx, transpipe *to_pipe, int chl, uintN argc
return JS_TRUE;
}
} else if (from_pipe != NULL && from_pipe->type == CUSTOM_PIPE) {
- json_set_property_objN(jstr, "pipe", 4, get_json_object_pipe(from_pipe));
+ json_set_property_objN(jstr, "pipe", 4, get_json_object_pipe(from_pipe, 0));
}
}
@@ -829,7 +829,7 @@ APE_JS_NATIVE(apechannel_sm_set_property)
}
} else { /* Convert to string */
property = JS_ValueToString(cx, argv[1]); /* No needs to be gc-rooted while there is no JSAPI Call after that */
- add_property(&chan->properties, key, JS_GetStringBytes(property), EXTEND_STR, EXTEND_ISPUBLIC);
+ //add_property(&chan->properties, key, JS_GetStringBytes(property), EXTEND_STR, EXTEND_ISPUBLIC);
}
@@ -2941,7 +2941,7 @@ static void init_module(acetables *g_ape) // Called when module is loaded
asc->cx = JS_NewContext(rt, 8192);
- #if 0
+ #if 1
JS_SetGCZeal(asc->cx, 2);
#endif
@@ -3087,6 +3087,52 @@ static void ape_cb_del_user(USERS *user, int istmp, acetables *g_ape)
deluser(user, g_ape);
}
+JSBool ape_channel_prop_setter(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
+{
+ jsval key;
+ JSObject *js_channel;
+ CHANNEL *chan;
+ int erased;
+ acetables *g_ape;
+ ape_sm_compiled *asc;
+
+ asc = JS_GetContextPrivate(cx);
+ g_ape = asc->g_ape;
+
+ if ((js_channel = JS_GetParent(cx, obj)) == NULL ||
+ (chan = JS_GetPrivate(cx, js_channel)) == NULL ||
+ JS_IdToValue(cx, id, &key) == JS_FALSE) {
+ return JS_TRUE;
+ }
+
+ switch(JS_TypeOfValue(cx, *vp)) {
+ case JSTYPE_OBJECT:
+ add_pipe_property(chan->pipe, JS_EncodeString(cx, JSVAL_TO_STRING(key)), jsobj_to_ape_json(cx, JSVAL_TO_OBJECT(*vp)), EXTEND_JSON, &erased, g_ape);
+ break;
+ case JSTYPE_STRING:
+ add_pipe_property(chan->pipe, JS_EncodeString(cx, JSVAL_TO_STRING(key)), JS_EncodeString(cx, JSVAL_TO_STRING(*vp)), EXTEND_STR, &erased, g_ape);
+ break;
+ case JSTYPE_NUMBER:
+ if (JSVAL_IS_INT(*vp)) {
+ int vpint = JSVAL_TO_INT(*vp);
+ add_pipe_property(chan->pipe, JS_EncodeString(cx, JSVAL_TO_STRING(key)), &vpint, EXTEND_INT, &erased, g_ape);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return JS_TRUE;
+}
+
+static JSClass channel_prop = {
+ "channel_prop", JSCLASS_HAS_PRIVATE,
+ JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, ape_channel_prop_setter,
+ JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
+ JSCLASS_NO_OPTIONAL_MEMBERS
+};
+
+
static CHANNEL *ape_cb_mkchan(char *name, int flags, acetables *g_ape)
{
JSObject *js_channel;
@@ -3107,7 +3153,11 @@ static CHANNEL *ape_cb_mkchan(char *name, int flags, acetables *g_ape)
if (js_channel == NULL) {
return NULL;
}
-
+
+ //JS_DefineProperty(gcx, js_channel, "properties", OBJECT_TO_JSVAL(JS_NewObject(gcx, NULL, NULL, NULL)), NULL, ape_channel_pop_setter, JSPROP_ENUMERATE | JSPROP_SHARED);
+
+ JS_DefineObject(gcx, js_channel, "properties", &channel_prop, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
+
jsobj = add_property(&chan->properties, "jsobj", js_channel, EXTEND_POINTER, EXTEND_ISPRIVATE);
JS_AddObjectRoot(gcx, (JSObject **)&jsobj->val);
View
1 scripts/main.ape.js
@@ -10,5 +10,6 @@ Ape.addEvent("init", function() {
include("utils/checkTool.js"); //Just needed for the APE JSF diagnostic tool, once APE is installed you can remove it
//include("examples/ircserver.js");
//include("framework/http_auth.js");
+
});
View
50 src/channel.c
@@ -167,8 +167,8 @@ void join(USERS *user, CHANNEL *chan, acetables *g_ape)
uinfo = json_new_object();
- json_set_property_objN(uinfo, "user", 4, get_json_object_user(user));
- json_set_property_objN(uinfo, "pipe", 4, get_json_object_channel(chan));
+ json_set_property_objN(uinfo, "user", 4, get_json_object_user(user, 1));
+ json_set_property_objN(uinfo, "pipe", 4, get_json_object_channel(chan, 1));
newraw = forge_raw(RAW_JOIN, uinfo);
post_raw_channel_restricted(newraw, chan, user, g_ape);
@@ -177,10 +177,10 @@ void join(USERS *user, CHANNEL *chan, acetables *g_ape)
ulist = chan->head;
while (ulist != NULL) {
- json_item *juser = get_json_object_user(ulist->userinfo);
+ json_item *juser = get_json_object_user(ulist->userinfo, 1);
if (ulist->userinfo != user) {
- //make_link(user, ulist->userinfo);
+ make_link(user, ulist->userinfo);
}
json_set_property_intN(juser, "level", 5, ulist->level);
@@ -192,7 +192,7 @@ void join(USERS *user, CHANNEL *chan, acetables *g_ape)
json_set_property_objN(jlist, "users", 5, user_list);
}
- json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan, 1));
newraw = forge_raw(RAW_CHANNEL, jlist);
post_raw(newraw, user, g_ape);
@@ -262,8 +262,8 @@ void left(USERS *user, CHANNEL *chan, acetables *g_ape) // Vider la liste chain
if (list->userinfo == user) {
jlist = json_new_object();
- json_set_property_objN(jlist, "user", 4, get_json_object_user(user));
- json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
+ json_set_property_objN(jlist, "user", 4, get_json_object_user(user, 0));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan, 0));
newraw = forge_raw(RAW_LEFT, jlist);
post_raw(newraw, user, g_ape);
@@ -278,8 +278,8 @@ void left(USERS *user, CHANNEL *chan, acetables *g_ape) // Vider la liste chain
if (chan->head != NULL && !(chan->flags & CHANNEL_NONINTERACTIVE)) {
jlist = json_new_object();
- json_set_property_objN(jlist, "user", 4, get_json_object_user(user));
- json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
+ json_set_property_objN(jlist, "user", 4, get_json_object_user(user, 0));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan, 0));
newraw = forge_raw(RAW_LEFT, jlist);
post_raw_channel(newraw, chan, g_ape);
@@ -326,6 +326,7 @@ userslist *getuchan(USERS *user, CHANNEL *chan)
return NULL;
}
+#if 0
// TODO : Rewrite this f***g ugly function
unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsigned int lvl, acetables *g_ape)
{
@@ -377,6 +378,7 @@ unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsi
}
return 0;
}
+#endif
/*unsigned int settopic(USERS *user, CHANNEL *chan, const char *topic, acetables *g_ape)
{
@@ -429,8 +431,8 @@ void ban(CHANNEL *chan, USERS *banner, const char *ip, char *reason, unsigned in
jlist = json_new_object();
json_set_property_strZ(jlist, "reason", reason);
- json_set_property_objN(jlist, "banner", 6, get_json_object_user(banner));
- json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
+ json_set_property_objN(jlist, "banner", 6, get_json_object_user(banner, 0));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan, 0));
newraw = forge_raw(RAW_BAN, jlist);
@@ -526,7 +528,7 @@ void rmallban(CHANNEL *chan)
chan->banned = NULL;
}
-json_item *get_json_object_channel(CHANNEL *chan)
+json_item *get_json_object_channel(CHANNEL *chan, int full)
{
json_item *jstr = json_new_object();
json_set_property_strN(jstr, "casttype", 8, "multi", 5);
@@ -537,14 +539,24 @@ json_item *get_json_object_channel(CHANNEL *chan)
extend *eTmp = chan->properties;
- while (eTmp != NULL) {
- if (eTmp->visibility == EXTEND_ISPUBLIC) {
- if (eTmp->type == EXTEND_JSON) {
- json_item *jcopy = json_item_copy(eTmp->val, NULL);
+ while (eTmp != NULL && full) {
+ if (eTmp->visibility == EXTEND_ISPUBLIC && !eTmp->state.deleted) {
+ switch(eTmp->type) {
+ case EXTEND_JSON:
+ {
+ json_item *jcopy = json_item_copy(eTmp->val, NULL);
- json_set_property_objZ(jprop, eTmp->key, jcopy);
- } else {
- json_set_property_strZ(jprop, eTmp->key, eTmp->val);
+ json_set_property_objZ(jprop, eTmp->key, jcopy);
+ break;
+ }
+ case EXTEND_STR:
+ json_set_property_strZ(jprop, eTmp->key, eTmp->val);
+ break;
+ case EXTEND_INT:
+ json_set_property_intZ(jprop, eTmp->key, eTmp->integer);
+ break;
+ default:
+ break;
}
}
View
2 src/channel.h
@@ -84,7 +84,7 @@ unsigned int setlevel(struct USERS *user_actif, struct USERS *user_passif, CHANN
//unsigned int settopic(struct USERS *user, CHANNEL *chan, const char *topic, acetables *g_ape);
unsigned int isvalidchan(char *name);
-json_item *get_json_object_channel(CHANNEL *chan);
+json_item *get_json_object_channel(CHANNEL *chan, int full);
#endif
View
130 src/extend.c
@@ -21,9 +21,118 @@
#include <string.h>
#include <stdio.h>
+#include "pipe.h"
#include "extend.h"
#include "utils.h"
#include "json.h"
+#include "raw.h"
+
+#if 0
+extend *add_pipe_property(transpipe *pipe, const char *key, void *val, EXTEND_TYPE etype, int *erased, acetables *g_ape)
+{
+ extend **entry = NULL;
+ json_item *jprop, *jlist;
+ RAW *newraw;
+ extend *new_property = NULL, *eTmp;
+ int klen;
+
+ if ((klen = strlen(key)) > EXTEND_KEY_LENGTH) {
+ return NULL;
+ }
+
+ *erased = 0;
+
+ switch(pipe->type) {
+ case CHANNEL_PIPE:
+ entry = &((CHANNEL *)pipe->pipe)->properties;
+ break;
+ case USER_PIPE:
+ entry = &((USERS *)pipe->pipe)->properties;
+ break;
+ default:
+ return NULL;
+ }
+
+ jprop = json_new_object();
+
+ *erased = del_property(entry, key);
+
+ eTmp = *entry;
+
+ if (val == NULL) {
+
+ return NULL;
+ }
+
+ jlist = json_new_object();
+
+ new_property = xmalloc(sizeof(*new_property));
+
+ strcpy(new_property->key, key);
+
+ /* TODO if channel is empty, do nothing related to raws */
+ switch(etype) {
+ case EXTEND_STR:
+ {
+ int len = strlen(val);
+ new_property->val = xmalloc(sizeof(char) * (len + 1));
+ memcpy(new_property->val, val, len + 1);
+
+ json_set_property_strN(jlist, key, klen, (char *)val, len);
+ break;
+ }
+ case EXTEND_INT:
+ json_set_property_intN(jlist, key, klen, *(int *)val);
+ new_property->integer = *(int *)val;
+ break;
+ case EXTEND_JSON:
+ ((json_item *)val)->freeonstring = 0;
+ json_set_property_objN(jlist, key, klen, (json_item *)val);
+ new_property->val = val;
+ break;
+ default:
+ return NULL;
+ }
+
+ json_set_property_objN(jprop, (*erased ? "mod" : "set"), 3, jlist);
+ newraw = forge_raw("PROP", jprop);
+
+ new_property->next = eTmp;
+ new_property->type = etype;
+ new_property->visibility = EXTEND_ISPUBLIC;
+
+ *entry = new_property;
+
+ post_raw_pipe(newraw, pipe, g_ape);
+
+ return new_property;
+}
+#endif
+
+extend *add_pipe_property(transpipe *pipe, const char *key, void *val, EXTEND_TYPE etype, int *erased, acetables *g_ape)
+{
+ extend **entry = NULL;
+ extend *new_property = NULL;
+
+ *erased = 0;
+
+ switch(pipe->type) {
+ case CHANNEL_PIPE:
+ entry = &((CHANNEL *)pipe->pipe)->properties;
+ break;
+ case USER_PIPE:
+ entry = &((USERS *)pipe->pipe)->properties;
+ break;
+ default:
+ return NULL;
+ }
+
+ new_property = add_property(entry, key, val, etype, EXTEND_ISPUBLIC);
+ new_property->state.notcommited = 1;
+
+ return new_property;
+}
+
/*
Add a property to an object (user, channel, proxy, acetables)
@@ -36,6 +145,7 @@
EXTEND_ISPUBLIC : The property is added to the json tree sent with get_json_object_*
EXTEND_ISPRIVATE : The property is not shown in get_json_object_*
*/
+
extend *add_property(extend **entry, const char *key, void *val, EXTEND_TYPE etype, EXTEND_PUBLIC visibility)
{
extend *new_property = NULL, *eTmp;
@@ -50,14 +160,16 @@ extend *add_property(extend **entry, const char *key, void *val, EXTEND_TYPE ety
eTmp = *entry;
new_property = xmalloc(sizeof(*new_property));
-
- /* The key cannot be longer than EXTEND_KEY_LENGTH */
+
strcpy(new_property->key, key);
switch(etype) {
case EXTEND_STR:
new_property->val = xstrdup(val);
break;
+ case EXTEND_INT:
+ new_property->integer = *(int *)val;
+ break;
case EXTEND_POINTER:
default:
/* a pointer must be a private property */
@@ -67,7 +179,10 @@ extend *add_property(extend **entry, const char *key, void *val, EXTEND_TYPE ety
new_property->val = val;
break;
}
-
+
+ new_property->state.notcommited = 0;
+ new_property->state.deleted = 0;
+
new_property->next = eTmp;
new_property->type = etype;
new_property->visibility = visibility;
@@ -102,14 +217,14 @@ void *get_property_val(extend *entry, const char *key)
}
-void del_property(extend **entry, const char *key)
+int del_property(extend **entry, const char *key)
{
while (*entry != NULL) {
if (strcmp((*entry)->key, key) == 0) {
extend *pEntry = *entry;
*entry = (*entry)->next;
-
+
switch(pEntry->type) {
case EXTEND_STR:
free(pEntry->val);
@@ -123,11 +238,12 @@ void del_property(extend **entry, const char *key)
free(pEntry);
- return;
+ return 1;
}
entry = &(*entry)->next;
}
-
+
+ return 0;
}
/* TODO : use del_property */
View
21 src/extend.h
@@ -24,10 +24,13 @@
#define EXTEND_KEY_LENGTH 32
+#include "pipe.h"
+
typedef enum {
EXTEND_STR,
EXTEND_JSON,
- EXTEND_POINTER
+ EXTEND_POINTER,
+ EXTEND_INT
} EXTEND_TYPE;
typedef enum {
@@ -39,18 +42,26 @@ typedef struct _extend extend;
struct _extend
{
- void *val;
-
+ char key[EXTEND_KEY_LENGTH+1];
+ union {
+ void *val;
+ int integer;
+ };
EXTEND_TYPE type;
EXTEND_PUBLIC visibility;
struct _extend *next;
- char key[EXTEND_KEY_LENGTH+1];
+
+ struct {
+ unsigned short int notcommited;
+ unsigned short int deleted;
+ } state;
};
extend *get_property(extend *entry, const char *key);
void clear_properties(extend **entry);
-void del_property(extend **entry, const char *key);
+int del_property(extend **entry, const char *key);
//extend *add_property_str(extend **entry, char *key, char *val);
+extend *add_pipe_property(transpipe *pipe, const char *key, void *val, EXTEND_TYPE etype, int *erased, acetables *g_ape);
extend *add_property(extend **entry, const char *key, void *val, EXTEND_TYPE etype, EXTEND_PUBLIC visibility);
#endif
View
9 src/json.c
@@ -256,7 +256,7 @@ struct jsontring *json_to_string(json_item *head, struct jsontring *string, int
string->jstring[string->len++] = '"';
string->jstring[string->len++] = ':';
- if (free_tree) {
+ if (free_tree && head->freeonstring) {
free(head->key.val);
}
}
@@ -267,7 +267,7 @@ struct jsontring *json_to_string(json_item *head, struct jsontring *string, int
string->len += escape_json_string(head->jval.vu.str.value, string->jstring + string->len, head->jval.vu.str.length); /* TODO : Add a "escape" argument to json_to_string */
string->jstring[string->len++] = '"';
- if (free_tree) {
+ if (free_tree && head->freeonstring) {
free(head->jval.vu.str.value);
}
} else if (head->jval.vu.integer_value) {
@@ -317,7 +317,7 @@ struct jsontring *json_to_string(json_item *head, struct jsontring *string, int
default:
break;
}
- json_to_string(head->jchild.child, string, free_tree);
+ json_to_string(head->jchild.child, string, (free_tree & head->freeonstring ? 1 : 0));
}
@@ -337,7 +337,7 @@ struct jsontring *json_to_string(json_item *head, struct jsontring *string, int
}
}
}
- if (free_tree) {
+ if (free_tree && head->freeonstring) {
json_item *jtmp = head->next;
free(head);
head = jtmp;
@@ -369,6 +369,7 @@ static json_item *init_json_item()
jval->jval.vu.float_value = 0.;
jval->type = -1;
+ jval->freeonstring = 1;
return jval;
}
View
2 src/json.h
@@ -88,7 +88,7 @@ typedef struct _json_item {
struct _json_item *next;
int type;
-
+ int freeonstring;
} json_item;
View
36 src/pipe.c
@@ -21,6 +21,7 @@
#include "pipe.h"
#include "utils.h"
+#include "users.h"
const char basic_chars[16] = { 'a', 'b', 'c', 'd', 'e', 'f', '0', '1',
@@ -138,7 +139,7 @@ void post_json_custom(json_item *jstr, USERS *user, transpipe *pipe, acetables *
pipe->on_send(pipe, user, jstr, g_ape);
}
-json_item *get_json_object_pipe_custom(transpipe *pipe)
+json_item *get_json_object_pipe_custom(transpipe *pipe, int full)
{
json_item *jstr = NULL;
@@ -147,7 +148,7 @@ json_item *get_json_object_pipe_custom(transpipe *pipe)
json_set_property_strN(jstr, "casttype", 8, "custom", 6);
json_set_property_strN(jstr, "pubid", 5, pipe->pubid, 32);
- if (pipe->properties != NULL) {
+ if (pipe->properties != NULL && full) {
int has_prop = 0;
json_item *jprop = NULL;
@@ -160,14 +161,23 @@ json_item *get_json_object_pipe_custom(transpipe *pipe)
has_prop = 1;
jprop = json_new_object();
}
- if (eTmp->type == EXTEND_JSON) {
- json_item *jcopy = json_item_copy(eTmp->val, NULL);
+ switch(eTmp->type) {
+ case EXTEND_JSON:
+ {
+ json_item *jcopy = json_item_copy(eTmp->val, NULL);
- json_set_property_objZ(jprop, eTmp->key, jcopy);
- } else {
- json_set_property_strZ(jprop, eTmp->key, eTmp->val);
-
- }
+ json_set_property_objZ(jprop, eTmp->key, jcopy);
+ break;
+ }
+ case EXTEND_STR:
+ json_set_property_strZ(jprop, eTmp->key, eTmp->val);
+ break;
+ case EXTEND_INT:
+ json_set_property_intZ(jprop, eTmp->key, eTmp->integer);
+ break;
+ default:
+ break;
+ }
}
eTmp = eTmp->next;
}
@@ -180,15 +190,15 @@ json_item *get_json_object_pipe_custom(transpipe *pipe)
return jstr;
}
-json_item *get_json_object_pipe(transpipe *pipe)
+json_item *get_json_object_pipe(transpipe *pipe, int full)
{
switch(pipe->type) {
case USER_PIPE:
- return get_json_object_user(pipe->pipe);
+ return get_json_object_user(pipe->pipe, full);
case CHANNEL_PIPE:
- return get_json_object_channel(pipe->pipe);
+ return get_json_object_channel(pipe->pipe, full);
case CUSTOM_PIPE:
- return get_json_object_pipe_custom(pipe);
+ return get_json_object_pipe_custom(pipe, full);
case PROXY_PIPE:
default:
return NULL;
View
5 src/pipe.h
@@ -23,7 +23,6 @@
#define _PIPE_H
#include "main.h"
-#include "users.h"
#include "json.h"
enum {
@@ -66,7 +65,7 @@ transpipe *get_pipe_strict(const char *pubid, struct USERS *user, acetables *g_a
void post_json_custom(json_item *jstr, struct USERS *user, struct _transpipe *pipe, acetables *g_ape);
void gen_sessid_new(char *input, acetables *g_ape);
void unlink_all_pipe(transpipe *origin, acetables *g_ape);
-json_item *get_json_object_pipe(transpipe *pipe);
-json_item *get_json_object_pipe_custom(transpipe *pipe);
+json_item *get_json_object_pipe(transpipe *pipe, int full);
+json_item *get_json_object_pipe_custom(transpipe *pipe, int full);
#endif
View
38 src/raw.c
@@ -47,7 +47,7 @@ RAW *forge_raw(const char *raw, json_item *jlist)
string = json_to_string(jstruct, NULL, 1);
new_raw = xmalloc(sizeof(*new_raw));
- new_raw->len = string->len;
+ new_raw->len = string->len;
new_raw->next = NULL;
new_raw->priority = RAW_PRI_LO;
new_raw->refcount = 0;
@@ -142,6 +142,26 @@ void post_raw_restricted(RAW *raw, USERS *user, subuser *sub, acetables *g_ape)
}
}
+void post_raw_link(RAW *raw, USERS *user, acetables *g_ape)
+{
+ struct _link_list *ulink;
+
+ if (user->links.nlink == 0) {
+ return;
+ }
+
+ ulink = user->links.ulink;
+
+ while (ulink != NULL) {
+
+ post_raw(raw, (ulink->link->a == user ?
+ ulink->link->b :
+ ulink->link->a), g_ape);
+
+ ulink = ulink->next;
+ }
+}
+
/************* Channels related functions ****************/
/* Post raw to a channel and propagate it to all of it's users */
@@ -200,11 +220,9 @@ void proxy_post_raw(RAW *raw, ape_proxy *proxy, acetables *g_ape)
}
/* to manage subuser use post_to_pipe() instead */
-int post_raw_pipe(RAW *raw, const char *pipe, acetables *g_ape)
+int post_raw_pipe(RAW *raw, transpipe *spipe, acetables *g_ape)
{
- transpipe *spipe;
-
- if ((spipe = get_pipe(pipe, g_ape)) != NULL) {
+ if (spipe != NULL) {
if (spipe->type == CHANNEL_PIPE) {
post_raw_channel(raw, spipe->pipe, g_ape);
@@ -229,32 +247,32 @@ int post_to_pipe(json_item *jlist, const char *rawname, const char *pipe, subuse
send_error(sender, "UNKNOWN_PIPE", "109", g_ape);
return 0;
}
- json_set_property_objN(jlist, "from", 4, get_json_object_user(sender));
+ json_set_property_objN(jlist, "from", 4, get_json_object_user(sender, 0));
}
if (sender != NULL && sender->nsub > 1) {
jlist_copy = json_item_copy(jlist, NULL);
- json_set_property_objN(jlist_copy, "pipe", 4, get_json_object_pipe(recver));
+ json_set_property_objN(jlist_copy, "pipe", 4, get_json_object_pipe(recver, 0));
newraw = forge_raw(rawname, jlist_copy);
post_raw_restricted(newraw, sender, from, g_ape);
}
switch(recver->type) {
case USER_PIPE:
- json_set_property_objN(jlist, "pipe", 4, get_json_object_user(sender));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_user(sender, 0));
newraw = forge_raw(rawname, jlist);
post_raw(newraw, recver->pipe, g_ape);
break;
case CHANNEL_PIPE:
if (((CHANNEL*)recver->pipe)->head != NULL && ((CHANNEL*)recver->pipe)->head->next != NULL) {
- json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(recver->pipe));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(recver->pipe, 0));
newraw = forge_raw(rawname, jlist);
post_raw_channel_restricted(newraw, recver->pipe, sender, g_ape);
}
break;
case CUSTOM_PIPE:
- json_set_property_objN(jlist, "pipe", 4, get_json_object_user(sender));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_user(sender, 0));
post_json_custom(jlist, sender, recver, g_ape);
break;
default:
View
2 src/raw.h
@@ -57,7 +57,7 @@ void post_raw_channel(RAW *raw, struct CHANNEL *chan, acetables *g_ape);
void post_raw_restricted(RAW *raw, USERS *user, subuser *sub, acetables *g_ape);
void post_raw_channel_restricted(RAW *raw, struct CHANNEL *chan, USERS *ruser, acetables *g_ape);
void proxy_post_raw(RAW *raw, ape_proxy *proxy, acetables *g_ape);
-int post_raw_pipe(RAW *raw, const char *pipe, acetables *g_ape);
+int post_raw_pipe(RAW *raw, transpipe *spipe, acetables *g_ape);
int post_to_pipe(json_item *jlist, const char *rawname, const char *pipe, subuser *from, acetables *g_ape);
int send_raw_inline(ape_socket *client, transport_t transport, RAW *raw, acetables *g_ape);
View
38 src/users.c
@@ -516,7 +516,7 @@ void subuser_restor(subuser *sub, acetables *g_ape)
while (ulist != NULL) {
- json_item *juser = get_json_object_user(ulist->userinfo);
+ json_item *juser = get_json_object_user(ulist->userinfo, 1);
if (ulist->userinfo != user) {
//make_link(user, ulist->userinfo);
@@ -531,7 +531,7 @@ void subuser_restor(subuser *sub, acetables *g_ape)
json_set_property_objN(jlist, "users", 5, user_list);
}
- json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan));
+ json_set_property_objN(jlist, "pipe", 4, get_json_object_channel(chan, 1));
newraw = forge_raw(RAW_CHANNEL, jlist);
newraw->priority = RAW_PRI_HI;
@@ -540,7 +540,7 @@ void subuser_restor(subuser *sub, acetables *g_ape)
}
jlist = json_new_object();
- json_set_property_objN(jlist, "user", 4, get_json_object_user(user));
+ json_set_property_objN(jlist, "user", 4, get_json_object_user(user, 1));
newraw = forge_raw("IDENT", jlist);
newraw->priority = RAW_PRI_HI;
@@ -641,7 +641,7 @@ void make_link(USERS *a, USERS *b)
struct _users_link *link;
struct _link_list *link_a, *link_b;
- if (are_linked(a, b) != NULL) {
+ if ((link = are_linked(a, b)) == NULL) {
link = xmalloc(sizeof(*link));
link_a = xmalloc(sizeof(*link_a));
@@ -662,9 +662,10 @@ void make_link(USERS *a, USERS *b)
b->links.ulink = link_b;
(b->links.nlink)++;
- link->link_type = 0;
+ link->nlink = 1;
printf("Link etablished between %s and %s\n", a->pipe->pubid, b->pipe->pubid);
} else {
+ link->nlink++;
printf("%s and %s are already linked\n", a->pipe->pubid, b->pipe->pubid);
}
}
@@ -678,7 +679,7 @@ void destroy_link(USERS *a, USERS *b)
}
}
-json_item *get_json_object_user(USERS *user)
+json_item *get_json_object_user(USERS *user, int full)
{
json_item *jstr = NULL;
@@ -687,7 +688,7 @@ json_item *get_json_object_user(USERS *user)
json_set_property_strN(jstr, "casttype", 8, "uni", 3);
json_set_property_strN(jstr, "pubid", 5, user->pipe->pubid, 32);
- if (user->properties != NULL) {
+ if (user->properties != NULL && full) {
int has_prop = 0;
json_item *jprop = NULL;
@@ -700,14 +701,23 @@ json_item *get_json_object_user(USERS *user)
has_prop = 1;
jprop = json_new_object();
}
- if (eTmp->type == EXTEND_JSON) {
- json_item *jcopy = json_item_copy(eTmp->val, NULL);
+ switch(eTmp->type) {
+ case EXTEND_JSON:
+ {
+ json_item *jcopy = json_item_copy(eTmp->val, NULL);
- json_set_property_objZ(jprop, eTmp->key, jcopy);
- } else {
- json_set_property_strZ(jprop, eTmp->key, eTmp->val);
-
- }
+ json_set_property_objZ(jprop, eTmp->key, jcopy);
+ break;
+ }
+ case EXTEND_STR:
+ json_set_property_strZ(jprop, eTmp->key, eTmp->val);
+ break;
+ case EXTEND_INT:
+ json_set_property_intZ(jprop, eTmp->key, eTmp->integer);
+ break;
+ default:
+ break;
+ }
}
eTmp = eTmp->next;
}
View
4 src/users.h
@@ -138,7 +138,7 @@ struct _users_link
USERS *a;
USERS *b;
- int link_type;
+ int nlink;
};
struct _link_list
@@ -228,7 +228,7 @@ void send_msg_channel(struct CHANNEL *chan, const char *msg, const char *type, a
unsigned int isonchannel(USERS *user, struct CHANNEL *chan);
-json_item *get_json_object_user(USERS *user);
+json_item *get_json_object_user(USERS *user, int full);
session *get_session(USERS *user, const char *key);
session *set_session(USERS *user, const char *key, const char *val, int update, acetables *g_ape);

0 comments on commit ee7c7d0

Please sign in to comment.
Something went wrong with that request. Please try again.