[ekg2-commit] ekg2: gg.c (HEAD) gg.h (HEAD) pubdir.c (HEAD) [darkjames]
CVS commit
cvs w toxygen.net
Śro, 2 Maj 2007, 17:21:30 CEST
Module name: ekg2
Changes by: darkjames 2007-05-02 17:21:27
Modified files:
gg.c gg.h pubdir.c
Log message:
- use session values for import/export/clear userlist.
(fix race /userlist -p on one session, and /userlist -c on another one)
- copy old userlist_dump() rename to gg_userlist_dump() and use it.
coz our userlist_dump() needs hack, and dump lines without '\r'
Index: gg.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/gg/gg.c,v
diff -d -u -r1.211 -r1.212
--- gg.c 21 Apr 2007 16:59:28 -0000 1.211
+++ gg.c 2 May 2007 15:21:27 -0000 1.212
@@ -595,10 +595,6 @@
xfree(entry[4]);
entry[4] = xstrdup(p->mobile);
}
- if (gg_userlist_put_config == 666) { /* userlist -p hack */
- xfree(entry[6]);
- entry[6] = xstrdup(u->uid+3); /* remove gg: */
- }
break;
}
case EKG_USERLIST_PRIVHANDLER_GETVAR_BYNAME:
@@ -1248,14 +1244,19 @@
config_changed = 1;
}
+ session_int_set(s, "__userlist_get_config", -1);
break;
+
case GG_USERLIST_PUT_REPLY:
- switch (gg_userlist_put_config) {
+ switch (session_int_get(s, "__userlist_put_config")) {
case 0: print("userlist_put_ok"); break;
case 1: print("userlist_config_put_ok"); break;
case 2: print("userlist_clear_ok"); break;
case 3: print("userlist_config_clear_ok"); break;
+ default:
+ debug_error("gg_session_handler_userlist() occur, but __userlist_put_config: %d\n", session_int_get(s, "__userlist_put_config"));
}
+ session_int_set(s, "__userlist_put_config", -1);
break;
}
}
Index: gg.h
===================================================================
RCS file: /home/cvs/ekg2/plugins/gg/gg.h,v
diff -d -u -r1.32 -r1.33
--- gg.h 1 Apr 2007 16:45:12 -0000 1.32
+++ gg.h 2 May 2007 15:21:27 -0000 1.33
@@ -30,7 +30,6 @@
COMMAND(gg_command_image); /* images.c */
extern plugin_t gg_plugin;
-extern int gg_userlist_put_config;
extern char *last_tokenid;
/* variables */
Index: pubdir.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/gg/pubdir.c,v
diff -d -u -r1.37 -r1.38
--- pubdir.c 21 Apr 2007 16:59:28 -0000 1.37
+++ pubdir.c 2 May 2007 15:21:27 -0000 1.38
@@ -41,7 +41,6 @@
int gg_register_done = 0;
char *gg_register_password = NULL;
char *gg_register_email = NULL;
-int gg_userlist_put_config;
static WATCHER(gg_handle_register) /* tymczasowy */
{
@@ -500,25 +499,80 @@
return 0;
}
+/*
+ * gg_userlist_dump()
+ *
+ * zapisuje listÄ kontaktĂłw w postaci tekstowej.
+ *
+ * zwraca zaalokowany bufor, ktĂłry naleĹźy zwolniÄ.
+ */
+static char *gg_userlist_dump(session_t *session)
+{
+ string_t s;
+ list_t l;
+
+ s = string_init(NULL);
+
+ for (l = session->userlist; l; l = l->next) {
+ userlist_t *u = l->data;
+ gg_userlist_private_t *p = u->priv;
+ char *groups;
+
+ groups = group_to_string(u->groups, 1, 0);
+
+ string_append_format(s,
+ "%s;%s;%s;%s;%s;%s;%s%s\r\n",
+ (p && p->first_name) ? p->first_name : "",
+ (p && p->last_name) ? p->last_name : "",
+ (u->nickname) ? u->nickname : "",
+ (u->nickname) ? u->nickname : "",
+ (p && p->mobile) ? p->mobile : "",
+ groups,
+ u->uid + 3 /* skip gg: */,
+ (u->foreign) ? u->foreign : "");
+
+ xfree(groups);
+ }
+
+ return string_free(s, 0);
+}
+
COMMAND(gg_command_list)
{
gg_private_t *g = session_private_get(session);
+
/* list --get */
if (params[0] && match_arg(params[0], 'g', ("get"), 2)) {
+#if 0
+ if (session_int_get(session, "__userlist_get_config") != -1) {
+ printq("generic_error", "Another import userlist operation in progress... Please wait.");
+ return -1;
+ }
+#endif
+
if (gg_userlist_request(g->sess, GG_USERLIST_GET, NULL) == -1) {
printq("userlist_get_error", strerror(errno));
return -1;
}
+
+ session_int_set(session, "__userlist_get_config", 0);
return 0;
}
/* list --clear */
if (params[0] && match_arg(params[0], 'c', ("clear"), 2)) {
+#if 0
+ if (session_int_get(session, "__userlist_put_config") != -1) {
+ printq("generic_error", "Another export/clear userlist operation in progress... Please wait.");
+ return -1;
+ }
+#endif
+
if (gg_userlist_request(g->sess, GG_USERLIST_PUT, NULL) == -1) {
printq("userlist_clear_error", strerror(errno));
return -1;
}
- gg_userlist_put_config = 2;
+ session_int_set(session, "__userlist_put_config", 2);
return 0;
}
@@ -526,9 +580,13 @@
if (params[0] && (match_arg(params[0], 'p', ("put"), 2))) {
char *contacts;
char *cpcontacts;
-
- gg_userlist_put_config = 666; /* special value for userlist_dump magic */
- contacts = userlist_dump(session);
+#if 0
+ if (session_int_get(session, "__userlist_put_config") != -1) {
+ printq("generic_error", "Another export/clear userlist operation in progress... Please wait.");
+ return -1;
+ }
+#endif
+ contacts = gg_userlist_dump(session);
cpcontacts = gg_locale_to_cp(contacts);
if (gg_userlist_request(g->sess, GG_USERLIST_PUT, cpcontacts) == -1) {
@@ -536,7 +594,8 @@
xfree(cpcontacts);
return -1;
}
- gg_userlist_put_config = 0;
+
+ session_int_set(session, "__userlist_put_config", 0);
xfree(cpcontacts);
return 0;
}
Więcej informacji o liście dyskusyjnej ekg2-commit