about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2013-07-14 13:49:50 +0300
committerDmitry Podgorny <pasis.ua@gmail.com>2013-07-14 13:49:50 +0300
commit034cf730cc89210e9d423b015968938b9f291d60 (patch)
tree90a1c9c4e4cb5d02be9aff15591ba08bc37b4ddf
parent2837c4054f0c46f9cbbd0f09571e7d91501f2253 (diff)
downloadprofani-tty-034cf730cc89210e9d423b015968938b9f291d60.tar.gz
use get_unique_id for bookmarks
-rw-r--r--src/common.c9
-rw-r--r--src/xmpp/bookmark.c18
-rw-r--r--src/xmpp/connection.c13
-rw-r--r--src/xmpp/connection.h1
4 files changed, 15 insertions, 26 deletions
diff --git a/src/common.c b/src/common.c
index 2d1ac3d7..e2ff0171 100644
--- a/src/common.c
+++ b/src/common.c
@@ -37,9 +37,6 @@
 // and page size is at least 4KB
 #define READ_BUF_SIZE 4088
 
-// for generating ids
-static int unique_id = 0;
-
 struct curl_data_t
 {
     char *buffer;
@@ -400,10 +397,12 @@ xdg_get_data_home(void)
 char *
 get_unique_id(void)
 {
+    static unsigned long unique_id;
     char *result = NULL;
-    unique_id++;
     GString *result_str = g_string_new("");
-    g_string_printf(result_str, "prof%d", unique_id);
+
+    unique_id++;
+    g_string_printf(result_str, "prof%lu", unique_id);
     result = result_str->str;
     g_string_free(result_str, FALSE);
 
diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c
index e6d5efe3..dd4cebe1 100644
--- a/src/xmpp/bookmark.c
+++ b/src/xmpp/bookmark.c
@@ -18,21 +18,25 @@ static int _bookmark_handle_result(xmpp_conn_t * const conn,
 void
 bookmark_request(void)
 {
-    int id;
-    char id_str[10];
+    char *id;
     xmpp_conn_t * const conn = connection_get_conn();
     xmpp_ctx_t * const ctx = connection_get_ctx();
-    xmpp_stanza_t *iq = stanza_create_storage_bookmarks(ctx);
+    xmpp_stanza_t *iq;
 
-    id = jabber_get_id();
-    snprintf(id_str, sizeof(id_str), "%u", id);
+    id = get_unique_id();
+    if (!id) {
+        return;
+    }
 
     /* TODO: timed handler to remove this id_handler */
-    xmpp_id_handler_add(conn, _bookmark_handle_result, id_str, ctx);
+    xmpp_id_handler_add(conn, _bookmark_handle_result, id, ctx);
 
-    xmpp_stanza_set_id(iq, id_str);
+    iq = stanza_create_storage_bookmarks(ctx);
+    xmpp_stanza_set_id(iq, id);
     xmpp_send(conn, iq);
     xmpp_stanza_release(iq);
+
+    g_free(id);
 }
 
 static int
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 600e813a..5040aa91 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -232,19 +232,6 @@ jabber_set_autoping(const int seconds)
     }
 }
 
-int
-jabber_get_id(void)
-{
-    static int xmpp_id;
-
-    ++xmpp_id;
-    if (xmpp_id < 0) {
-        xmpp_id = 1;
-    }
-
-    return xmpp_id;
-}
-
 GList *
 jabber_get_available_resources(void)
 {
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index 81a6e3b3..b5701252 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -31,7 +31,6 @@ xmpp_conn_t *connection_get_conn(void);
 xmpp_ctx_t *connection_get_ctx(void);
 int connection_error_handler(xmpp_conn_t * const conn,
     xmpp_stanza_t * const stanza, void * const userdata);
-int jabber_get_id(void);
 void connection_set_priority(int priority);
 void connection_set_presence_message(const char * const message);
 void connection_add_available_resource(Resource *resource);