Permalink
Browse files

Merge branch 'channel_history'

  • Loading branch information...
Vagabond committed Dec 2, 2010
2 parents 67625c2 + ee660c1 commit e117997272788ddc1cafdd0ecb2560c08a42762a
Showing with 380 additions and 12 deletions.
  1. +1 −1 Makefile
  2. +7 −0 bin/ape.conf
  3. +66 −3 modules/libape-spidermonkey.c
  4. +1 −0 modules/plugins.h
  5. +38 −1 src/channel.c
  6. +4 −0 src/channel.h
  7. +160 −0 src/channel_history.c
  8. +57 −0 src/channel_history.h
  9. +5 −0 src/config.h
  10. +1 −0 src/extend.h
  11. +25 −7 src/raw.c
  12. +1 −0 src/users.h
  13. +9 −0 src/utils.c
  14. +5 −0 src/utils.h
View
@@ -4,7 +4,7 @@ prefix = /usr/local
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/transports.c src/servers.c src/dns.c src/sha1.c src/log.c src/parser.c src/md5.c
+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/transports.c src/servers.c src/dns.c src/sha1.c src/log.c src/parser.c src/md5.c src/channel_history.c
CFLAGS = -Wall -O2 -minline-all-stringops -rdynamic -I ./deps/udns-0.0.9/
LFLAGS=-ldl -lm -lpthread
View
@@ -32,6 +32,13 @@ Config {
modules_conf = ../modules/conf/
}
+Channels {
+ # default max size of history. 0 for no history.
+ #history_default_max_size = 10
+ # RAWs you want to be added to history (space is seperator). ALL or comment for all RAWs.
+ #history_default_raw_filter = DATA
+}
+
# Proxy section is used to resolve hostname and allow access to a IP:port (Middleware-TCPSocket feature)
#Proxy {
@@ -572,6 +572,7 @@ APE_JS_NATIVE(apepipe_sm_set_property)
case CHANNEL_PIPE:
/* Set property on directly on the channel (not on the pipe) */
add_property(&((CHANNEL *)(pipe->pipe))->properties, key, valuextend, typextend, EXTEND_ISPUBLIC);
+ update_chan_history_size((CHANNEL *)(pipe->pipe));
break;
case CUSTOM_PIPE:
add_property(&pipe->properties, key, valuextend, typextend, EXTEND_ISPUBLIC);
@@ -756,6 +757,47 @@ APE_JS_NATIVE(apepipe_sm_send_response)
return sm_send_raw(cx, JS_GetPrivate(cx, JSVAL_TO_OBJECT(pipe)), JSVAL_TO_INT(chl), argc, argv, g_ape);
}
+APE_JS_NATIVE(apechannel_sm_ban)
+//{
+ char *ip, *reason;
+ unsigned int expire;
+ USERS *user;
+ JSObject *user_obj;
+ CHANNEL *chan = JS_GetPrivate(cx, obj);
+
+ if ( chan == NULL ||
+ !JSVAL_IS_OBJECT(argv[0]) ||
+ !JSVAL_IS_STRING(argv[1]) ||
+ !JSVAL_IS_STRING(argv[2]) ||
+ !JSVAL_IS_INT(argv[3]) ||
+ !JS_ConvertArguments(cx, 4, argv, "ossu", &user_obj, &ip, &reason, &expire) ||
+ !JS_InstanceOf(cx, user_obj, &user_class, 0) ||
+ (user = JS_GetPrivate(cx, user_obj)) == NULL ||
+ strlen(ip) < 3 /* min. ::1 (localhost) ipv6 */
+ ) {
+ *rval = JSVAL_FALSE;
+ }
+ else {
+ ban(chan, user, ip, reason, expire, g_ape);
+ *rval = JSVAL_TRUE;
+ }
+
+ return JS_TRUE;
+}
+
+APE_JS_NATIVE(apechannel_sm_get_flags)
+//{
+ CHANNEL *chan = JS_GetPrivate(cx, obj);
+
+ if (chan == NULL) {
+ return JS_TRUE;
+ }
+
+ *rval = INT_TO_JSVAL(getflags(chan));
+
+ return JS_TRUE;
+}
+
APE_JS_NATIVE(apechannel_sm_get_property)
//{
const char *property;
@@ -788,6 +830,23 @@ APE_JS_NATIVE(apechannel_sm_get_property)
return JS_TRUE;
}
+APE_JS_NATIVE(apechannel_sm_set_flags)
+//{
+ int flags;
+
+ CHANNEL *chan = JS_GetPrivate(cx, obj);
+
+ if ( chan == NULL ||
+ !JSVAL_IS_INT(argv[1]) ||
+ !JS_ConvertArguments(cx, 1, argv, "i", &flags)
+ ) {
+ return JS_TRUE;
+ }
+
+ setflags(chan, flags);
+ return JS_TRUE;
+}
+
APE_JS_NATIVE(apechannel_sm_set_property)
//{
char *key;
@@ -814,7 +873,8 @@ APE_JS_NATIVE(apechannel_sm_set_property)
add_property(&chan->properties, key, JS_GetStringBytes(property), EXTEND_STR, EXTEND_ISPUBLIC);
}
-
+ update_chan_history_size(chan);
+
return JS_TRUE;
}
@@ -1087,6 +1147,9 @@ static JSFunctionSpec apechannel_funcs[] = {
JS_FS("getProperty", apechannel_sm_get_property, 1, 0, 0),
JS_FS("setProperty", apechannel_sm_set_property, 2, 0, 0),
JS_FS("isInteractive", apechannel_sm_isinteractive, 1, 0, 0),
+ JS_FS("getFlags", apechannel_sm_get_flags, 0, 0, 0),
+ JS_FS("setFlags", apechannel_sm_set_flags, 1, 0, 0),
+ JS_FS("ban", apechannel_sm_ban, 4, 0, 0),
JS_FS_END
};
@@ -1792,7 +1855,7 @@ APE_JS_NATIVE(ape_sm_rmchan)
} else {
return JS_TRUE;
}
-
+
rmchan(chan, g_ape);
return JS_TRUE;
@@ -3103,7 +3166,7 @@ static void ape_cb_rmchan(CHANNEL *chan, acetables *g_ape)
JSContext *gcx = ASMC;
params[0] = OBJECT_TO_JSVAL(APECHAN_TO_JSOBJ(chan));
-
+
APE_JS_EVENT("rmchan", 1, params);
jsobj = get_property(chan->properties, "jsobj");
View
@@ -28,6 +28,7 @@
#include "../src/main.h"
#include "../src/channel.h"
+#include "../src/channel_history.h"
#include "../src/cmd.h"
#include "../src/extend.h"
#include "../src/users.h"
View
@@ -26,6 +26,7 @@
#include "json.h"
#include "raw.h"
#include "plugins.h"
+#include "channel_history.h"
unsigned int isvalidchan(char *name)
{
@@ -65,6 +66,8 @@ CHANNEL *mkchan(char *chan, int flags, acetables *g_ape)
new_chan->properties = NULL;
new_chan->flags = flags | (*new_chan->name == '*' ? CHANNEL_NONINTERACTIVE : 0);
+ new_chan->history = init_channel_history(new_chan, g_ape->srv);
+
//memcpy(new_chan->topic, topic, strlen(topic)+1);
new_chan->pipe = init_pipe(new_chan, CHANNEL_PIPE, g_ape);
@@ -124,6 +127,7 @@ void rmchan(CHANNEL *chan, acetables *g_ape)
destroy_pipe(chan->pipe, g_ape);
+ free_channel_history(chan->history);
free(chan);
chan = NULL;
}
@@ -196,7 +200,8 @@ void join(USERS *user, CHANNEL *chan, acetables *g_ape)
newraw = forge_raw(RAW_CHANNEL, jlist);
post_raw(newraw, user, g_ape);
-
+ post_channel_history(chan, user, g_ape);
+
#if 0
if (user->flags & FLG_AUTOOP) {
setlevel(NULL, user, chan, 3);
@@ -378,6 +383,38 @@ unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsi
return 0;
}
+void setflags(CHANNEL *chan, int flags) {
+ chan->flags = flags;
+}
+
+int getflags(CHANNEL *chan) {
+ return chan->flags;
+}
+
+unsigned int setflags_cmd(USERS *user, CHANNEL *chan, int flags, acetables *g_ape) {
+ RAW *newraw;
+ userslist *list;
+ json_item *jlist;
+
+ list = getuchan(user, chan);
+
+ if (list == NULL || list->level < 3) {
+ send_error(user, "SETFLAGS_ERROR", "112", g_ape);
+ return 0;
+ }
+
+ setflags(chan, flags);
+
+ 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));
+
+ newraw = forge_raw(RAW_SETFLAGS, jlist);
+ post_raw_channel(newraw, chan, g_ape);
+
+ return 1;
+}
+
/*unsigned int settopic(USERS *user, CHANNEL *chan, const char *topic, acetables *g_ape)
{
RAW *newraw;
View
@@ -40,6 +40,7 @@ typedef struct CHANNEL
struct _transpipe *pipe;
struct userslist *head;
+ struct CHANNEL_HISTORY_DEQUE *history;
struct BANNED *banned;
@@ -86,5 +87,8 @@ unsigned int isvalidchan(char *name);
json_item *get_json_object_channel(CHANNEL *chan);
+void setflags(CHANNEL *chan, int flags);
+int getflags(CHANNEL *chan);
+
#endif
Oops, something went wrong.

0 comments on commit e117997

Please sign in to comment.