changeset 5752:90eea4997759

[gaim-migrate @ 6177] Trepia connections are a bit better now. People's usernames are now their usernames and not their ID numbers. Some things are faster, I think. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 04 Jun 2003 19:46:48 +0000
parents 2951d2435196
children 96214f5de47c
files src/protocols/trepia/profile.c src/protocols/trepia/profile.h src/protocols/trepia/trepia.c
diffstat 3 files changed, 170 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/trepia/profile.c	Wed Jun 04 18:29:20 2003 +0000
+++ b/src/protocols/trepia/profile.c	Wed Jun 04 19:46:48 2003 +0000
@@ -49,6 +49,14 @@
 }
 
 void
+trepia_profile_set_type(TrepiaProfile *profile, int value)
+{
+	g_return_if_fail(profile != NULL);
+
+	profile->type = value;
+}
+
+void
 trepia_profile_set_id(TrepiaProfile *profile, int value)
 {
 	g_return_if_fail(profile != NULL);
@@ -266,6 +274,14 @@
 }
 
 int
+trepia_profile_get_type(const TrepiaProfile *profile)
+{
+	g_return_val_if_fail(profile != NULL, 0);
+
+	return profile->type;
+}
+
+int
 trepia_profile_get_id(const TrepiaProfile *profile)
 {
 	g_return_val_if_fail(profile != NULL, 0);
--- a/src/protocols/trepia/profile.h	Wed Jun 04 18:29:20 2003 +0000
+++ b/src/protocols/trepia/profile.h	Wed Jun 04 19:46:48 2003 +0000
@@ -27,6 +27,8 @@
 
 typedef struct
 {
+	int type;           /* c */
+
 	int id;             /* a */
 	char *location;     /* p */
 	time_t login_time;  /* b */
@@ -54,6 +56,7 @@
 TrepiaProfile *trepia_profile_new(void);
 void trepia_profile_destroy(TrepiaProfile *profile);
 
+void trepia_profile_set_type(TrepiaProfile *profile, int value);
 void trepia_profile_set_id(TrepiaProfile *profile, int value);
 void trepia_profile_set_location(TrepiaProfile *profile, const char *value);
 void trepia_profile_set_login_time(TrepiaProfile *profile, time_t value);
@@ -76,6 +79,7 @@
 void trepia_profile_set_school(TrepiaProfile *profile, const char *value);
 void trepia_profile_set_company(TrepiaProfile *profile, const char *value);
 
+int trepia_profile_get_type(const TrepiaProfile *profile);
 int trepia_profile_get_id(const TrepiaProfile *profile);
 const char *trepia_profile_get_location(const TrepiaProfile *profile);
 time_t trepia_profile_get_login_time(const TrepiaProfile *profile);
--- a/src/protocols/trepia/trepia.c	Wed Jun 04 18:29:20 2003 +0000
+++ b/src/protocols/trepia/trepia.c	Wed Jun 04 19:46:48 2003 +0000
@@ -61,6 +61,10 @@
 
 	GString *rxqueue;
 
+	GList *pending_users;
+	GHashTable *user_profiles;
+	GHashTable *user_ids;
+
 } TrepiaSession;
 
 typedef struct
@@ -107,10 +111,10 @@
 	}
 }
 
+#if 0
 static char *
 __get_mac_address(const char *ip)
 {
-#if 0
 	char *mac = NULL;
 #ifndef _WIN32
 	struct sockaddr_in sin = { 0 };
@@ -148,10 +152,10 @@
 #endif
 
 	return mac;
-#endif
 
 	return NULL;
 }
+#endif
 
 /**************************************************************************
  * Protocol Plugin ops
@@ -182,10 +186,6 @@
 	const char *value;
 	char *text = NULL;
 
-	gaim_debug(GAIM_DEBUG_INFO, "trepia", "trepia_status_text\n");
-	gaim_debug(GAIM_DEBUG_MISC, "trepia", "profile = '%s'\n",
-			   trepia_profile_get_profile(profile));
-
 	if ((value = trepia_profile_get_profile(profile)) != NULL)
 		text = g_markup_escape_text(value, -1);
 
@@ -406,12 +406,14 @@
 	GHashTable *info;
 	GaimAccount *account;
 	TrepiaMessageType type = 0;
-	TrepiaProfile *profile;
+	TrepiaProfile *profile = NULL;
 	int ret;
 	char *buffer;
 	struct buddy *b;
-	const char *id = NULL;
+	int id = 0;
 	const char *value;
+	char *username;
+	int *int_p;
 
 	account = gaim_connection_get_account(session->gc);
 
@@ -420,69 +422,68 @@
 	if (ret == 1)
 		return TRUE;
 
-	gaim_debug(GAIM_DEBUG_INFO, "trepia", "Successful parse.\n");
-	gaim_debug(GAIM_DEBUG_INFO, "trepia", "Message type: %c\n",
-			   type);
-
 	if (info != NULL) {
 		switch (type) {
 			case TREPIA_USER_LIST:
-				gaim_debug(GAIM_DEBUG_INFO, "trepia",
-						   "Signon complete. Showing buddy list.\n");
 				gaim_connection_set_state(session->gc, GAIM_CONNECTED);
 				serv_finish_login(session->gc);
 				break;
 
 			case TREPIA_MSG_INCOMING: /* Incoming Message */
-				gaim_debug(GAIM_DEBUG_INFO, "trepia", "Receiving message\n");
+				id = atoi(g_hash_table_lookup(info, "a"));
+
+				profile = g_hash_table_lookup(session->user_profiles, &id);
 				serv_got_im(session->gc,
-						(char *)g_hash_table_lookup(info, "a"),
-						(char *)g_hash_table_lookup(info, "b"),
-						0, time(NULL), -1);
+							trepia_profile_get_login(profile),
+							(char *)g_hash_table_lookup(info, "b"),
+							0, time(NULL), -1);
 				break;
 
 			case TREPIA_MEMBER_UPDATE:
-				id  = g_hash_table_lookup(info, "a");
-				b = gaim_find_buddy(account, id);
-
-				if (b == NULL) {
-					struct group *g;
-
-					g = gaim_find_group(_("Local Users"));
+				profile = trepia_profile_new();
 
-					if (g == NULL) {
-						g = gaim_group_new(_("Local Users"));
-						gaim_blist_add_group(g, NULL);
-					}
-
-					b = gaim_buddy_new(account, id, NULL);
-
-					gaim_blist_add_buddy(b, g, NULL);
+				if ((value = g_hash_table_lookup(info, "a")) != NULL) {
+					id = atoi(value);
+					trepia_profile_set_id(profile, id);
 				}
 
-				b->proto_data = trepia_profile_new();
-
-				serv_got_update(session->gc, id, 1, 0, 0, 0, 0);
+				if ((value = g_hash_table_lookup(info, "b")) != NULL)
+					trepia_profile_set_login_time(profile, atoi(value));
 
-				buffer = g_strdup_printf(
-					"<D>\n"
-					"<a>%s</a>\n"
-					"<b>1</b>\n"
-					"</D>",
-					id);
+				if ((value = g_hash_table_lookup(info, "c")) != NULL)
+					trepia_profile_set_type(profile, atoi(value));
+				else
+					trepia_profile_set_type(profile, 2);
+
+				session->pending_users = g_list_append(session->pending_users,
+													   profile);
+
 
-				if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
-					gaim_connection_error(session->gc, _("Write error"));
-					g_free(buffer);
-					return 1;
+#if 0
+				if (trepia_profile_get_type(profile) == 1) {
+					buffer = g_strdup_printf(
+						"<D>"
+						"<a>%d</a>"
+						"<b>1</b>"
+						"</D>",
+						id);
 				}
-
-				buffer = g_strdup_printf(
-					"<D>\n"
-					"<a>%s</a>\n"
-					"<b>2</b>\n"
-					"</D>",
-					id);
+				else {
+#endif
+					buffer = g_strdup_printf(
+						"<D>"
+						"<a>%d</a>"
+						"<b>1</b>"
+						"</D>"
+						"<D>"
+						"<a>%d</a>"
+						"<b>2</b>"
+						"</D>",
+						id,
+						id);
+#if 0
+				}
+#endif
 
 				if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) {
 					gaim_connection_error(session->gc, _("Write error"));
@@ -494,20 +495,29 @@
 				break;
 
 			case TREPIA_MEMBER_PROFILE:
-				id = g_hash_table_lookup(info, "a");
-				b = gaim_find_buddy(account, id);
+				if ((value = g_hash_table_lookup(info, "a")) != NULL) {
+					GList *l;
+
+					id = atoi(value);
+
+					for (l = session->pending_users; l != NULL; l = l->next) {
+						profile = l->data;
 
-				if (b == NULL)
+						if (trepia_profile_get_id(profile) == id)
+							break;
+
+						profile = NULL;
+					}
+				}
+				else
 					break;
 
-				profile = b->proto_data;
+				if (profile == NULL) {
+					profile = g_hash_table_lookup(session->user_profiles, &id);
 
-				/* ID */
-				trepia_profile_set_id(profile, atoi(id));
-
-				/* Login Time */
-				if ((value = g_hash_table_lookup(info, "b")) != NULL)
-					trepia_profile_set_login_time(profile, atoi(value));
+					if (profile == NULL)
+						break;
+				}
 
 				/* Age */
 				if ((value = g_hash_table_lookup(info, "m")) != NULL)
@@ -583,10 +593,47 @@
 
 				/* Login Name */
 				if ((value = g_hash_table_lookup(info, "d")) != NULL) {
-					serv_got_alias(session->gc, id, value);
-					trepia_profile_set_location(profile, value);
+					trepia_profile_set_login(profile, value);
+					username = g_strdup(value);
+				}
+				else if ((value = trepia_profile_get_login(profile)) != NULL) {
+					username = g_strdup(value);
+				}
+				else {
+					username = g_strdup_printf("%d", id);
+					trepia_profile_set_login(profile, username);
 				}
 
+				b = gaim_find_buddy(account, username);
+
+				if (b == NULL) {
+					struct group *g;
+
+					g = gaim_find_group(_("Local Users"));
+
+					if (g == NULL) {
+						g = gaim_group_new(_("Local Users"));
+						gaim_blist_add_group(g, NULL);
+					}
+
+					b = gaim_buddy_new(account, username, NULL);
+
+					gaim_blist_add_buddy(b, g, NULL);
+				}
+
+				b->proto_data = profile;
+
+				session->pending_users = g_list_remove(session->pending_users,
+													   profile);
+
+				int_p = g_new0(int, 1);
+				*int_p = id;
+				g_hash_table_insert(session->user_profiles, int_p, profile);
+
+				serv_got_update(session->gc,
+								username, 1, 0,
+								trepia_profile_get_login_time(profile), 0, 0);
+
 				/* Buddy Icon */
 				if ((value = g_hash_table_lookup(info, "q")) != NULL) {
 					char *icon;
@@ -594,23 +641,35 @@
 
 					frombase64(value, &icon, &icon_len);
 
-					set_icon_data(session->gc, id, icon, icon_len);
+					set_icon_data(session->gc, username, icon, icon_len);
 
 					g_free(icon);
+
+					serv_got_update(session->gc, username, 1, 0, 0, 0, 0);
 				}
 
-				gaim_debug(GAIM_DEBUG_INFO, "trepia", "Calling serv_got_update\n");
-				serv_got_update(session->gc, id, 1, 0,
-								trepia_profile_get_login_time(profile), 0, 0);
+				g_free(username);
+
 				break;
 
 			case TREPIA_MEMBER_OFFLINE:
-				id = g_hash_table_lookup(info, "a");
+				if ((value = g_hash_table_lookup(info, "a")) != NULL)
+					id = atoi(value);
+				else
+					break;
 
-				b = gaim_find_buddy(account, id);
+				profile = g_hash_table_lookup(session->user_profiles, &id);
+
+				if (profile == NULL)
+					break;
+
+				g_hash_table_remove(session->user_profiles, &id);
+				b = gaim_find_buddy(account, trepia_profile_get_login(profile));
 
 				if (b != NULL)
-					serv_got_update(session->gc, id, 0, 0, 0, 0, 0);
+					serv_got_update(session->gc,
+									trepia_profile_get_login(profile),
+									0, 0, 0, 0, 0);
 
 				gaim_blist_remove_buddy(b);
 
@@ -647,8 +706,6 @@
 
 	buf[i] = '\0';
 
-	gaim_debug(GAIM_DEBUG_MISC, "trepia", "__data_cb\n");
-
 	if (session->rxqueue == NULL)
 		session->rxqueue = g_string_new(buf);
 	else
@@ -711,16 +768,11 @@
 
 	mac = g_strdup("01:02:03:04:05:06");
 
-	gaim_debug(GAIM_DEBUG_INFO, "trepia", "__login_cb\n");
-
 	if (source < 0) {
-		gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Write error.\n");
 		gaim_connection_error(session->gc, _("Write error"));
 		return;
 	}
 
-	gaim_debug(GAIM_DEBUG_ERROR, "trepia", "Past the first stage.\n");
-
 	session->fd = source;
 
 	account = gaim_connection_get_account(session->gc);
@@ -771,8 +823,6 @@
 	int port;
 	int i;
 
-	gaim_debug(GAIM_DEBUG_INFO, "trepia", "trepia_login\n");
-
 	server = gaim_account_get_string(account, "server", TREPIA_SERVER);
 	port   = gaim_account_get_int(account,    "port",   TREPIA_PORT);
 
@@ -782,11 +832,11 @@
 	gc->proto_data = session;
 	session->gc = gc;
 	session->fd = -1;
+	session->user_profiles = g_hash_table_new_full(g_int_hash, g_int_equal,
+												   g_free, NULL);
 
 	__clear_user_list(account);
 
-	gaim_debug(GAIM_DEBUG_INFO, "trepia", "connecting to proxy\n");
-
 	i = gaim_proxy_connect(account, server, port, __login_cb, session);
 
 	if (i != 0)
@@ -806,6 +856,9 @@
 	if (session->inpa)
 		gaim_input_remove(session->inpa);
 
+	g_hash_table_destroy(session->user_profiles);
+	g_list_free(session->pending_users);
+
 	close(session->fd);
 
 	g_free(session);
@@ -818,17 +871,29 @@
 			int len, int flags)
 {
 	TrepiaSession *session = gc->proto_data;
+	TrepiaProfile *profile;
+	struct buddy *b;
 	char *escaped_msg;
 	char *buffer;
 
+	b = gaim_find_buddy(gaim_connection_get_account(gc), who);
+
+	if (b == NULL) {
+		gaim_debug(GAIM_DEBUG_ERROR, "trepia",
+				   "Unable to send to buddy not on your list!\n");
+		return 0;
+	}
+
+	profile = b->proto_data;
+
 	escaped_msg = g_markup_escape_text(message, -1);
 
 	buffer = g_strdup_printf(
 		"<F>\n"
-		"<a>%s</a>\n"
+		"<a>%d</a>\n"
 		"<b>%s</b>\n"
 		"</F>",
-		who, escaped_msg);
+		trepia_profile_get_id(profile), escaped_msg);
 
 	g_free(escaped_msg);