[ekg2-commit] ekg2: jabber.h (HEAD) misc.c (HEAD) [peres]
CVS commit
cvs w toxygen.net
Czw, 3 Maj 2007, 17:57:51 CEST
Module name: ekg2
Changes by: peres 2007-05-03 17:57:49
Modified files:
jabber.h misc.c
Log message:
First step in porting conversations (formerly threads) from ekg2-peres.
Index: jabber.h
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/jabber.h,v
diff -d -u -r1.69 -r1.70
--- jabber.h 2 May 2007 22:00:28 -0000 1.69
+++ jabber.h 3 May 2007 15:57:48 -0000 1.70
@@ -104,33 +104,44 @@
} jabber_iq_privacy_t;
typedef struct {
- int fd; /* deskryptor połączenia */
- int istlen; /* czy to tlen? */
+ char *thread;
+ char *uid;
+ char *subject;
+ void *next;
+} jabber_conversation_t;
- enum jabber_compression_method using_compress; /* czy kompresujemy polaczenie */
+/**
+ * jabber_private_t contains private data of jabber/tlen session.
+ */
+typedef struct {
+ int fd; /**< connection's fd */
+ int istlen; /**< whether this is a tlen session */
+
+ enum jabber_compression_method using_compress; /**< whether we're using compressed connection, and what method */
#ifdef JABBER_HAVE_SSL
- char using_ssl; /* czy polaczono uzywajac ssl */ /* 1 - tak, uzywamy SSL, 2 - tak, uzywamy TLS */
- SSL_SESSION ssl_session; /* sesja ssla */
+ char using_ssl; /**< 1 if we're using SSL, 2 if we're using TLS, else 0 */
+ SSL_SESSION ssl_session; /**< SSL session */
#ifdef JABBER_HAVE_GNUTLS
- gnutls_certificate_credentials xcred;
+ gnutls_certificate_credentials xcred; /**< gnutls credentials (?) */
#endif
#endif
- int id; /* id zapytań */
- XML_Parser parser; /* instancja parsera expata */
- char *server; /* nazwa serwera */
- int port; /* numer portu */
- int connecting; /* czy się właśnie łączymy? */ /* 1 - normalne laczenie, 2 - laczenie po SASLu */
- char *resource; /* resource jakie uzylismy przy laczeniu sie do jabberd */
+ int id; /**< queries ID */
+ XML_Parser parser; /**< expat instance */
+ char *server; /**< server name */
+ int port; /**< server's port number */
+ int connecting; /**< whether we're connecting, 2 if connecting over SASL */
+ char *resource; /**< resource used when connecting to daemon */
#ifdef GMAIL_MAIL_NOTIFY
- char *last_gmail_result_time; /* last time we've checked mail, this seems not to work correctly ;/ */
- char *last_gmail_tid;
+ char *last_gmail_result_time; /**< last time we're checking mail (this seems not to work correctly ;/) */
+ char *last_gmail_tid; /**< lastseen mail thread-id */
#endif
- list_t privacy; /* for jabber:iq:privacy */
- list_t bookmarks; /* for jabber:iq:private <storage xmlns='storage:bookmarks'> */
+ list_t privacy; /**< for jabber:iq:privacy */
+ list_t bookmarks; /**< for jabber:iq:private <storage xmlns='storage:bookmarks'> */
watch_t *send_watch;
- xmlnode_t *node; /* aktualna gałąź xmla */
+ xmlnode_t *node; /**< current XML branch */
+ jabber_conversation_t *conversations; /**< known conversations */
} jabber_private_t;
typedef struct {
@@ -203,6 +214,10 @@
jabber_userlist_private_t *jabber_userlist_priv_get(userlist_t *u);
+int jabber_conversation_find(jabber_private_t *j, char *uid, char *subject, char *thread, jabber_conversation_t **result, int can_add);
+jabber_conversation_t *jabber_conversation_get(jabber_private_t *j, int n);
+char *jabber_thread_gen(jabber_private_t *j, char *uid);
+
#endif /* __EKG_JABBER_JABBER_H */
/*
Index: misc.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/misc.c,v
diff -d -u -r1.50 -r1.51
--- misc.c 12 Apr 2007 13:33:50 -0000 1.50
+++ misc.c 3 May 2007 15:57:49 -0000 1.51
@@ -499,6 +499,97 @@
return 0;
}
+/* conversations */
+
+/**
+ * jabber_conversation_find() searches session's conversation list for matching one.
+ *
+ * @param j - private data of session.
+ * @param uid - UID of recipient.
+ * @param subject - message subject (for non-threaded conversations).
+ * @param thread - jabber thread ID, if threaded.
+ * @param result - place to write address of jabber_conversation_t or NULL, if not needed.
+ * @param can_add - if nonzero, we can create new conversation, if none match.
+ *
+ * @return Reply-ID of conversation.
+ */
+int jabber_conversation_find(jabber_private_t *j, char *uid, char *subject, char *thread, jabber_conversation_t **result, int can_add) {
+ /* XXX: it's kinda ol' function, need to take a third look at it */
+ jabber_conversation_t *thr, *prev;
+ char *resubject;
+ int i, l;
+
+ if (!thread && subject && !xstrncmp(subject, config_subject_reply_prefix, (l = xstrlen(config_subject_reply_prefix))))
+ resubject = subject + l;
+
+ /* XXX: take a closer look at this monster */
+ for (thr = j->conversations, prev = NULL, i = 1;
+ thr && ((thread ? xstrcmp(thr->thread, thread)
+ : (subject ? xstrcmp(thr->subject, subject) && xstrcmp(thr->subject, resubject)
+ && (xstrncmp(thr->subject, config_subject_reply_prefix, l) || xstrcmp(thr->subject+l, subject)) : thr->subject))
+ || (uid ? xstrcmp(thr->uid, uid) : 1));
+ prev = thr, thr = thr->next, i++);
+ if (!thr && can_add) {
+ thr = xmalloc(sizeof(jabber_conversation_t));
+ thr->thread = xstrdup(thread);
+ thr->uid = xstrdup(uid);
+ thr->subject = xstrdup(resubject ? resubject : subject); /* XXX, why I haven't added this earlier? */
+ if (prev)
+ prev->next = thr;
+ else
+ j->conversations = thr;
+ }
+
+ if (result)
+ *result = thr;
+ return i;
+}
+
+/**
+ * jabber_conversation_get() is used to get conversation by its Reply-ID.
+ *
+ * @param j - private data of session.
+ * @param n - Reply-ID.
+ *
+ * @return Pointer to jabber_conversation_t or NULL, when no conversation found.
+ */
+jabber_conversation_t *jabber_conversation_get(jabber_private_t *j, int n) {
+ jabber_conversation_t *thr;
+ int i;
+
+ for (thr = j->conversations, i = 1;
+ thr && (i < n);
+ thr = thr->next, i++);
+
+ return thr;
+}
+
+/**
+ * jabber_thread_gen() generates new thread-ID for outgoing messages.
+ *
+ * @bug Currently used method does generate TID-s, that are only unique-per-session. Something more random needed?
+ *
+ * @param j - private data of session.
+ * @param uid - recipient UID.
+ *
+ * @return New, session-unique thread-ID.
+ */
+char *jabber_thread_gen(jabber_private_t *j, char *uid) {
+ int i, k, n = 0;
+ char *thread = NULL;
+
+ /* don't ask me now, why it is like that...
+ * why I haven't used comments?! */
+ for (i = jabber_conversation_find(j, NULL, NULL, NULL, NULL, 0), k = i; n != k; i++) {
+ xfree(thread);
+ thread = saprintf("thr%d", i);
+ n = jabber_conversation_find(j, thread, NULL, uid, NULL, 0);
+ debug("[jabber,thread_gen] i = %d, k = %d, n = %d, t = %s\n", i, n, k, thread);
+ }
+
+ return thread;
+}
+
/*
* Local Variables:
* mode: c
Więcej informacji o liście dyskusyjnej ekg2-commit