[ekg2-commit] r3865 - in trunk: ekg plugins/gg plugins/jabber: trunk/ekg/commands.c trunk/ekg/msgqueue.c trunk/ekg/msgqueue.h trunk/ekg/plugins.h trunk/ekg/protocol.c trunk/ekg/protocol.h trunk/plugins/gg/commands.c trunk/plugins/jabber/commands.c
SVN commit
svn w toxygen.net
Sob, 8 Mar 2008, 21:34:51 CET
Author: peres
Date: 2008-03-08 21:34:51 +0100 (Sat, 08 Mar 2008)
New Revision: 3865
Modified:
trunk/ekg/commands.c
trunk/ekg/msgqueue.c
trunk/ekg/msgqueue.h
trunk/ekg/plugins.h
trunk/ekg/protocol.c
trunk/ekg/protocol.h
trunk/plugins/gg/commands.c
trunk/plugins/jabber/commands.c
Log:
Msg class support in msgqueue, /queue fix and offline msgqueue in jabber (experimental).
Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/ekg/commands.c 2008-03-08 20:34:51 UTC (rev 3865)
@@ -3840,7 +3840,7 @@
*/
static COMMAND(cmd_queue) {
- list_t l;
+ msg_queue_t *m;
int isempty = 1;
const char *queue_list_timestamp_f; /* cached result of format_find("queue_list_timestamp") */
@@ -3864,8 +3864,7 @@
queue_list_timestamp_f = format_find("queue_list_timestamp");
- for (l = msg_queue; l; l = l->next) {
- msg_queue_t *m = l->data;
+ for (m = msg_queue; m; m = m->next) {
struct tm *tm;
char buf[100] = { '\0' }; /* we need to init it to '\0' cause queue_list_timestamp_f can be empty. and if buf was not NUL terminated string, than printq() can do SIGSEGV */
Modified: trunk/ekg/msgqueue.c
===================================================================
--- trunk/ekg/msgqueue.c 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/ekg/msgqueue.c 2008-03-08 20:34:51 UTC (rev 3865)
@@ -31,9 +31,11 @@
#include <string.h>
#include <unistd.h>
+#include "debug.h"
#include "dynstuff.h"
#include "commands.h"
#include "msgqueue.h"
+#include "protocol.h"
#include "sessions.h"
#include "stuff.h"
#include "xmalloc.h"
@@ -52,7 +54,7 @@
*
* 0/-1
*/
-int msg_queue_add(const char *session, const char *rcpts, const char *message, const char *seq)
+int msg_queue_add(const char *session, const char *rcpts, const char *message, const char *seq, msgclass_t class)
{
msg_queue_t *m = xmalloc(sizeof(msg_queue_t));
@@ -61,6 +63,7 @@
m->message = xstrdup(message);
m->seq = xstrdup(seq);
m->time = time(NULL);
+ m->class = class;
return (LIST_ADD2(&msg_queue, m) ? 0 : -1);
}
@@ -164,12 +167,12 @@
for (m = msg_queue; m;) {
session_t *s;
msg_queue_t *next = m->next;
+ char *cmd = "/msg \"%s\" %s";
/* czy wiadomość dodano w trakcie opróżniania kolejki? */
if (!m->mark)
continue;
-
if (session && xstrcmp(m->session, session))
continue;
/* wiadomość wysyłana z nieistniejącej już sesji? usuwamy. */
@@ -178,7 +181,16 @@
continue;
}
- command_exec_format(NULL, s, 1, ("/msg \"%s\" %s"), m->rcpts, m->message);
+ switch (m->class) {
+ case EKG_MSGCLASS_SENT_CHAT:
+ cmd = "/chat \"%s\" %s";
+ break;
+ case EKG_MSGCLASS_SENT:
+ break;
+ default:
+ debug_error("msg_queue_flush(), unsupported message class in query: %d\n", m->class);
+ }
+ command_exec_format(NULL, s, 1, cmd, m->rcpts, m->message);
LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
@@ -238,7 +250,7 @@
continue;
chmod(fn, 0600);
- fprintf(f, "v1\n%s\n%s\n%ld\n%s\n%s", m->session, m->rcpts, m->time, m->seq, m->message);
+ fprintf(f, "v2\n%s\n%s\n%ld\n%s\n%d\n%s", m->session, m->rcpts, m->time, m->seq, m->class, m->message);
fclose(f);
}
@@ -274,6 +286,7 @@
string_t msg;
char *buf;
FILE *f;
+ int filever = 0;
if (!(fn = prepare_pathf("queue/%s", d->d_name)))
continue;
@@ -287,8 +300,10 @@
memset(&m, 0, sizeof(m));
buf = read_file(f, 0);
-
- if (!buf || xstrcmp(buf, "v1")) {
+
+ if (buf && *buf == 'v')
+ filever = atoi(buf+1);
+ if (!filever || filever > 2) {
fclose(f);
continue;
}
@@ -319,7 +334,19 @@
fclose(f);
continue;
}
-
+
+ if (filever == 2) {
+ if (!(buf = read_file(f, 0))) {
+ xfree(m.session);
+ xfree(m.rcpts);
+ fclose(f);
+ continue;
+ }
+
+ m.class = atoi(buf);
+ } else
+ m.class = EKG_MSGCLASS_SENT;
+
msg = string_init(NULL);
buf = read_file(f, 0);
Modified: trunk/ekg/msgqueue.h
===================================================================
--- trunk/ekg/msgqueue.h 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/ekg/msgqueue.h 2008-03-08 20:34:51 UTC (rev 3865)
@@ -25,6 +25,7 @@
#include <time.h>
#include "dynstuff.h"
+#include "protocol.h"
typedef struct msg_queue {
struct msg_queue *next;
@@ -35,11 +36,12 @@
char *seq; /* numer sekwencyjny */
time_t time; /* czas wysłania */
unsigned int mark : 1; /* if added during cleanup */
+ msgclass_t class;
} msg_queue_t;
extern msg_queue_t *msg_queue;
-int msg_queue_add(const char *session, const char *rcpts, const char *message, const char *seq);
+int msg_queue_add(const char *session, const char *rcpts, const char *message, const char *seq, msgclass_t class);
void msg_queue_free();
int msg_queue_count_session(const char *uid);
int msg_queue_remove_uid(const char *uid);
Modified: trunk/ekg/plugins.h
===================================================================
--- trunk/ekg/plugins.h 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/ekg/plugins.h 2008-03-08 20:34:51 UTC (rev 3865)
@@ -26,7 +26,7 @@
#include "dynstuff.h"
#include "sessions.h"
-#define EKG_ABI_VER 3864
+#define EKG_ABI_VER 3865
#define EXPORT __attribute__ ((visibility("default")))
Modified: trunk/ekg/protocol.c
===================================================================
--- trunk/ekg/protocol.c 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/ekg/protocol.c 2008-03-08 20:34:51 UTC (rev 3865)
@@ -280,9 +280,6 @@
else
print("connected", session_name(s));
- if (!msg_queue_flush(session))
- print("queue_flush", session_name(s));
-
if (s) {
int two = 2;
@@ -295,6 +292,9 @@
query_emit_id(NULL, SESSION_EVENT, &s, &two); /* Notify UI */
}
+ if (!msg_queue_flush(session))
+ print("queue_flush", session_name(s));
+
return 0;
}
Modified: trunk/ekg/protocol.h
===================================================================
--- trunk/ekg/protocol.h 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/ekg/protocol.h 2008-03-08 20:34:51 UTC (rev 3865)
@@ -52,18 +52,18 @@
EKG_ACK_MAX /* we don't want to read after array */
};
-enum disconnect_t {
+typedef enum {
EKG_DISCONNECT_USER = 0, /* user-engaged disconnect */
EKG_DISCONNECT_NETWORK, /* network problems */
EKG_DISCONNECT_FORCED, /* server forced to disconnect */
EKG_DISCONNECT_FAILURE, /* connecting failed */
EKG_DISCONNECT_STOPPED /* connecting canceled */
-};
+} disconnect_t;
#define EKG_NO_BEEP 0
#define EKG_TRY_BEEP 1
-enum msgclass_t {
+typedef enum {
/* recv */
EKG_MSGCLASS_MESSAGE = 0, /* single message */
EKG_MSGCLASS_CHAT, /* chat message */
@@ -75,7 +75,7 @@
EKG_MSGCLASS_SENT_LOG, /* old logged message (used by logsqlite 'last_print_on_open') */
/* priv */
EKG_MSGCLASS_PRIV_STATUS= 64 /* used by logs */
-};
+} msgclass_t;
#ifndef EKG2_WIN32_NOFUNCTION
void protocol_init();
Modified: trunk/plugins/gg/commands.c
===================================================================
--- trunk/plugins/gg/commands.c 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/plugins/gg/commands.c 2008-03-08 20:34:51 UTC (rev 3865)
@@ -522,7 +522,8 @@
userlist_t *u;
gg_private_t *g = session_private_get(session);
- chat = (xstrcmp(name, ("msg")));
+ const int chat = (xstrcmp(name, ("msg")));
+ const int class = (chat) ? EKG_MSGCLASS_SENT_CHAT : EKG_MSGCLASS_SENT;
if (!quiet)
session_unidle(session);
@@ -762,7 +763,7 @@
else
seq = "offline";
- msg_queue_add(session_uid_get(session), target, params[1], seq);
+ msg_queue_add(session_uid_get(session), target, params[1], seq, class);
valid++;
xfree(__msg);
}
@@ -786,7 +787,7 @@
else
seq = "offline";
- msg_queue_add(session_uid_get(session), target, params[1], seq);
+ msg_queue_add(session_uid_get(session), target, params[1], seq, class);
valid++;
xfree(uins);
@@ -805,7 +806,6 @@
if (valid && !quiet) {
char **rcpts = xmalloc(sizeof(char *) * 2);
- const int class = (chat) ? EKG_MSGCLASS_SENT_CHAT : EKG_MSGCLASS_SENT;
const int ekgbeep = EKG_TRY_BEEP;
char *me = xstrdup(session_uid_get(session));
const time_t sent = time(NULL);
Modified: trunk/plugins/jabber/commands.c
===================================================================
--- trunk/plugins/jabber/commands.c 2008-03-08 19:00:36 UTC (rev 3864)
+++ trunk/plugins/jabber/commands.c 2008-03-08 20:34:51 UTC (rev 3865)
@@ -61,6 +61,7 @@
#include <ekg/themes.h>
#include <ekg/vars.h>
#include <ekg/log.h>
+#include <ekg/msgqueue.h>
#include <ekg/queries.h>
@@ -276,7 +277,12 @@
} else if (!xstrcmp(name, "msg") && (session_int_get(session, "msg_gen_thread")))
thread = jabber_thread_gen(j, uid); /* we don't return any chars to escape */
- /* message subject, TheNewBetterWay^TM */
+ if (!session_connected_get(session)) {
+ xfree(thread);
+ goto msgdisplay;
+ }
+
+ /* message subject */
if (!j->istlen && config_subject_prefix && !xstrncmp(params[1], config_subject_prefix, subjectlen)) {
char *last = xstrchr(params[1]+subjectlen, 10);
@@ -395,6 +401,7 @@
watch_write(j->send_watch, "</message>");
JABBER_COMMIT_DATA(j->send_watch);
+msgdisplay:
if (!quiet && !ismuc) { /* if (1) ? */
char *me = xstrdup(session_uid_get(session));
char **rcpts = xcalloc(2, sizeof(char *));
@@ -416,6 +423,9 @@
xfree(msg);
xfree(me);
array_free(rcpts);
+
+ if (!session_connected_get(session))
+ return msg_queue_add(session_uid_get(session), uid, params[1], "offline", class);
}
if (!quiet)
@@ -2186,12 +2196,10 @@
{
#define JABBER_ONLY SESSION_MUSTBELONG | SESSION_MUSTHASPRIVATE
#define JABBER_FLAGS JABBER_ONLY | SESSION_MUSTBECONNECTED
- /* XXX: I changed all '* | COMMAND_ENABLEREQPARAMS' to JABBER_FLAGS_REQ,
- * 'cause I don't see any sense in executing connection-requiring commands
- * without SESSION_MUSTBECONNECTED */
#define JABBER_FLAGS_REQ JABBER_FLAGS | COMMAND_ENABLEREQPARAMS
#define JABBER_FLAGS_TARGET JABBER_FLAGS_REQ | COMMAND_PARAMASTARGET
-#define JABBER_FLAGS_TARGET_VALID JABBER_FLAGS_TARGET | COMMAND_TARGET_VALID_UID /* need audit, if it can be used everywhere instead JABBER_FLAGS_TARGET */
+#define JABBER_FLAGS_TARGET_VALID JABBER_FLAGS_TARGET | COMMAND_TARGET_VALID_UID
+#define JABBER_FLAGS_MSG JABBER_ONLY | COMMAND_ENABLEREQPARAMS | COMMAND_PARAMASTARGET
commands_lock = &commands; /* keep it sorted or die */
command_add(&jabber_plugin, "xmpp:", "?", jabber_command_inline_msg, JABBER_ONLY, NULL);
@@ -2212,7 +2220,7 @@
"-c --clear -d --display -g --get -p --put");
command_add(&jabber_plugin, "xmpp:change", "!p ? p ? p ? p ? p ? p ?", jabber_command_change, JABBER_FLAGS_REQ,
"-f --fullname -c --city -b --born -d --description -n --nick -C --country");
- command_add(&jabber_plugin, "xmpp:chat", "!uU !", jabber_command_msg, JABBER_FLAGS_TARGET, NULL);
+ command_add(&jabber_plugin, "xmpp:chat", "!uU !", jabber_command_msg, JABBER_FLAGS_MSG, NULL);
command_add(&jabber_plugin, "xmpp:connect", NULL, jabber_command_connect, JABBER_ONLY, NULL);
command_add(&jabber_plugin, "xmpp:conversations", NULL, jabber_command_conversations, JABBER_FLAGS, NULL);
command_add(&jabber_plugin, "xmpp:del", "!u", jabber_command_del, JABBER_FLAGS_TARGET, NULL);
@@ -2226,7 +2234,7 @@
command_add(&jabber_plugin, "xmpp:lastseen", "!u", jabber_command_lastseen, JABBER_FLAGS_TARGET, NULL);
command_add(&jabber_plugin, "xmpp:modify", "!Uu ?", jabber_command_modify,JABBER_FLAGS_REQ,
"-n --nickname -g --group");
- command_add(&jabber_plugin, "xmpp:msg", "!uU !", jabber_command_msg, JABBER_FLAGS_TARGET, NULL);
+ command_add(&jabber_plugin, "xmpp:msg", "!uU !", jabber_command_msg, JABBER_FLAGS_MSG, NULL);
command_add(&jabber_plugin, "xmpp:part", "! ?", jabber_muc_command_part, JABBER_FLAGS_TARGET, NULL);
command_add(&jabber_plugin, "xmpp:passwd", "?", jabber_command_passwd, JABBER_FLAGS, NULL);
command_add(&jabber_plugin, "xmpp:privacy", "? ? ?", jabber_command_privacy, JABBER_FLAGS, NULL);
@@ -2270,7 +2278,7 @@
command_add(&jabber_plugin, "tlen:invisible", "r", jabber_command_away, JABBER_ONLY, NULL);
command_add(&jabber_plugin, "tlen:modify", "!Uu ?", jabber_command_modify, JABBER_FLAGS_REQ,
"-n --nickname -g --group");
- command_add(&jabber_plugin, "tlen:msg", "!uU !", jabber_command_msg, JABBER_FLAGS_TARGET, NULL);
+ command_add(&jabber_plugin, "tlen:msg", "!uU !", jabber_command_msg, JABBER_FLAGS_MSG, NULL);
command_add(&jabber_plugin, "tlen:reconnect", NULL, jabber_command_reconnect, JABBER_ONLY, NULL);
commands_lock = NULL;
Więcej informacji o liście dyskusyjnej ekg2-commit