diff src/server.c @ 1252:46c09828e929

[gaim-migrate @ 1262] still need to do buddy.c, conversation.c, dialogs.c, prefs.c. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Wed, 13 Dec 2000 22:12:02 +0000
parents b5783215b245
children f44bcae47188
line wrap: on
line diff
--- a/src/server.c	Wed Dec 13 20:23:06 2000 +0000
+++ b/src/server.c	Wed Dec 13 22:12:02 2000 +0000
@@ -47,7 +47,8 @@
 void serv_login(struct aim_user *user)
 {
 	struct prpl *p = find_prpl(user->protocol);
-	if (user->gc != NULL) return;
+	if (user->gc != NULL)
+		return;
 	if (p && p->login) {
 		debug_printf("Logging in using %s\n", (*p->name)());
 		(*p->login)(user);
@@ -67,7 +68,7 @@
 
 	if (gc->idle_timer > 0)
 		gtk_timeout_remove(gc->idle_timer);
-        gc->idle_timer = 0;
+	gc->idle_timer = 0;
 
 	if (gc->keepalive > 0)
 		gtk_timeout_remove(gc->keepalive);
@@ -86,14 +87,14 @@
 	/* Are we idle?  If so, not anymore */
 	if (gc->is_idle > 0) {
 		gc->is_idle = 0;
-                serv_set_idle(gc, 0);
-        }
-        time(&gc->lastsent);
+		serv_set_idle(gc, 0);
+	}
+	time(&gc->lastsent);
 }
 
 void serv_finish_login(struct gaim_connection *gc)
 {
-        char *buf;
+	char *buf;
 
 	if (strlen(gc->user->user_info)) {
 		buf = g_malloc(strlen(gc->user->user_info) * 4);
@@ -102,15 +103,15 @@
 		g_free(buf);
 	}
 
-        if (gc->idle_timer > 0)
-                gtk_timeout_remove(gc->idle_timer);
-        
-        gc->idle_timer = gtk_timeout_add(20000, (GtkFunction)check_idle, gc);
-        serv_touch_idle(gc);
+	if (gc->idle_timer > 0)
+		gtk_timeout_remove(gc->idle_timer);
 
-        time(&gc->login_time);
+	gc->idle_timer = gtk_timeout_add(20000, (GtkFunction)check_idle, gc);
+	serv_touch_idle(gc);
 
-        serv_add_buddy(gc, gc->username);
+	time(&gc->login_time);
+
+	serv_add_buddy(gc, gc->username);
 
 	update_keepalive(gc, gc->options & OPT_USR_KEEPALV);
 }
@@ -122,8 +123,8 @@
 	if (gc->prpl && gc->prpl->send_im)
 		(*gc->prpl->send_im)(gc, name, message, away);
 
-        if (!away)
-                serv_touch_idle(gc);
+	if (!away)
+		serv_touch_idle(gc);
 }
 
 void serv_get_info(struct gaim_connection *g, char *name)
@@ -178,7 +179,8 @@
 		(*g->prpl->set_info)(g, info);
 }
 
-void serv_change_passwd(struct gaim_connection *g, char *orig, char *new) {
+void serv_change_passwd(struct gaim_connection *g, char *orig, char *new)
+{
 	if (g->prpl && g->prpl->change_passwd)
 		(*g->prpl->change_passwd)(g, orig, new);
 }
@@ -189,7 +191,7 @@
 		(*g->prpl->add_buddy)(g, name);
 }
 
-void serv_add_buddies(struct gaim_connection *g, GList *buddies)
+void serv_add_buddies(struct gaim_connection *g, GList * buddies)
 {
 	if (g->prpl && g->prpl->add_buddies)
 		(*g->prpl->add_buddies)(g, buddies);
@@ -270,7 +272,8 @@
 {
 	/* i think this is the only one this should be necessary for since this is the
 	 * only thing that could possibly get called after the connection is closed */
-	if (!g_slist_find(connections, g)) return;
+	if (!g_slist_find(connections, g))
+		return;
 
 	if (g->prpl && g->prpl->chat_leave)
 		(*g->prpl->chat_leave)(g, id);
@@ -301,30 +304,31 @@
 	char *angel = g_strdup(name);
 	int plugin_return = plugin_event(event_im_recv, gc, &angel, &buffy, 0);
 	if (!buffy || !angel || plugin_return) {
-		if (buffy) g_free(buffy);
-		if (angel) g_free(angel);
+		if (buffy)
+			g_free(buffy);
+		if (angel)
+			g_free(angel);
 		return;
 	}
 	g_snprintf(message, strlen(message) + 1, "%s", buffy);
 	g_free(buffy);
 	g_snprintf(name, strlen(name) + 1, "%s", angel);
 	g_free(angel);
-	
+
 	if ((general_options & OPT_GEN_TIK_HACK) && awaymessage &&
-	    !strcmp(message, ">>>Automated Message: Getting Away Message<<<"))
-	{
+	    !strcmp(message, ">>>Automated Message: Getting Away Message<<<")) {
 		char *tmpmsg = stylize(awaymessage->message, MSG_LEN);
-	    	serv_send_im(gc, name, tmpmsg, 1);
+		serv_send_im(gc, name, tmpmsg, 1);
 		g_free(tmpmsg);
-	    	return;
+		return;
 	}
-	
-        cnv = find_conversation(name);
+
+	cnv = find_conversation(name);
 
 	if (general_options & OPT_GEN_SEND_LINKS) {
 		linkify_text(message);
 	}
-	
+
 	if (away)
 		away = WFLAG_AUTO;
 
@@ -378,7 +382,7 @@
 
 		/* apply default fonts and colors */
 		tmpmsg = stylize(awaymessage->message, MSG_LEN);
-		
+
 		/* PRPL */
 		if (gc->protocol == PROTO_TOC) {
 			escape_text(tmpmsg);
@@ -390,7 +394,7 @@
 
 		if (is_idle == -1)
 			is_idle = 1;
-		
+
 		if (cnv != NULL)
 			write_to_conv(cnv, away_subs(tmpmsg, alias), WFLAG_SEND | WFLAG_AUTO, NULL);
 		g_free(tmpmsg);
@@ -399,131 +403,132 @@
 
 
 
-void serv_got_update(struct gaim_connection *gc, char *name, int loggedin, int evil, time_t signon, time_t idle, int type, gushort caps)
+void serv_got_update(struct gaim_connection *gc, char *name, int loggedin, int evil, time_t signon,
+		     time_t idle, int type, gushort caps)
 {
-        struct buddy *b = find_buddy(gc, name);
+	struct buddy *b = find_buddy(gc, name);
 	struct gaim_connection *g = find_gaim_conn_by_name(name);
-                     
-        if (g) {
-                gc->correction_time = (int)(signon - g->login_time);
-                if (!b) {
-                        return;
+
+	if (g) {
+		gc->correction_time = (int)(signon - g->login_time);
+		if (!b) {
+			return;
 		}
-        }
-        
-        if (!b) {
-                debug_printf("Error, no such person\n");
-                return;
-        }
+	}
+
+	if (!b) {
+		debug_printf("Error, no such person\n");
+		return;
+	}
 
-        /* This code will 'align' the name from the TOC */
-        /* server with what's in our record.  We want to */
-        /* store things how THEY want it... */
-        if (strcmp(name, b->name)) {
-                GList  *cnv = conversations;
-                struct conversation *cv;
+	/* This code will 'align' the name from the TOC */
+	/* server with what's in our record.  We want to */
+	/* store things how THEY want it... */
+	if (strcmp(name, b->name)) {
+		GList *cnv = conversations;
+		struct conversation *cv;
 
-                char *who = g_malloc(80);
+		char *who = g_malloc(80);
 
-                strcpy(who, normalize(name));
+		strcpy(who, normalize(name));
 
-                while(cnv) {
-                        cv = (struct conversation *)cnv->data;
-                        if (!strcasecmp(who, normalize(cv->name))) {
-                                g_snprintf(cv->name, sizeof(cv->name), "%s", name);
-                                if (find_log_info(name) || (general_options & OPT_GEN_LOG_ALL))
-                                        g_snprintf(who, 63, LOG_CONVERSATION_TITLE, name);
-                                else
-                                        g_snprintf(who, 63, CONVERSATION_TITLE, name);
-                                gtk_window_set_title(GTK_WINDOW(cv->window), who);
+		while (cnv) {
+			cv = (struct conversation *)cnv->data;
+			if (!strcasecmp(who, normalize(cv->name))) {
+				g_snprintf(cv->name, sizeof(cv->name), "%s", name);
+				if (find_log_info(name) || (general_options & OPT_GEN_LOG_ALL))
+					 g_snprintf(who, 63, LOG_CONVERSATION_TITLE, name);
+				else
+					g_snprintf(who, 63, CONVERSATION_TITLE, name);
+				gtk_window_set_title(GTK_WINDOW(cv->window), who);
 				/* was g_free(buf), but break gives us that
 				 * and freeing twice is not good --Sumner */
-                                break;
-                        }
-                        cnv = cnv->next;
-                }
-		g_free(who); 
-                g_snprintf(b->name, sizeof(b->name), "%s", name);
-                /*gtk_label_set_text(GTK_LABEL(b->label), b->name);*/
+				break;
+			}
+			cnv = cnv->next;
+		}
+		g_free(who);
+		g_snprintf(b->name, sizeof(b->name), "%s", name);
+		/*gtk_label_set_text(GTK_LABEL(b->label), b->name); */
 
-                /* okay lets save the new config... */
+		/* okay lets save the new config... */
 
-        }
+	}
 
-	if (!b->idle && idle) plugin_event(event_buddy_idle, gc, b->name, 0, 0);
+	if (!b->idle && idle)
+		plugin_event(event_buddy_idle, gc, b->name, 0, 0);
 	if (b->idle && !idle) {
-                do_pounce(b->name, OPT_POUNCE_UNIDLE);
+		do_pounce(b->name, OPT_POUNCE_UNIDLE);
 		plugin_event(event_buddy_unidle, gc, b->name, 0, 0);
 	}
 
-        b->idle = idle;
-        b->evil = evil;
+	b->idle = idle;
+	b->evil = evil;
 
 	if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) {
-                do_pounce(b->name, OPT_POUNCE_UNAWAY);
+		do_pounce(b->name, OPT_POUNCE_UNAWAY);
 		plugin_event(event_buddy_back, gc, b->name, 0, 0);
 	} else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE)) {
 		plugin_event(event_buddy_away, gc, b->name, 0, 0);
 	}
 
-        b->uc = type;
-	if (caps) b->caps = caps;
-        
-        b->signon = signon;
+	b->uc = type;
+	if (caps)
+		b->caps = caps;
+
+	b->signon = signon;
 
-        if (loggedin) {
-                if (!b->present) {
-                        b->present = 1;
-                        do_pounce(b->name, OPT_POUNCE_SIGNON);
+	if (loggedin) {
+		if (!b->present) {
+			b->present = 1;
+			do_pounce(b->name, OPT_POUNCE_SIGNON);
 			plugin_event(event_buddy_signon, gc, b->name, 0, 0);
-                }
-        } else {
+		}
+	} else {
 		if (b->present)
 			plugin_event(event_buddy_signoff, gc, b->name, 0, 0);
-                b->present = 0;
+		b->present = 0;
 	}
 
-        set_buddy(gc, b);
+	set_buddy(gc, b);
 }
 
 static
 void close_warned(GtkWidget *w, GtkWidget *w2)
 {
-        gtk_widget_destroy(w2);
+	gtk_widget_destroy(w2);
 }
 
 
 
 void serv_got_eviled(struct gaim_connection *gc, char *name, int lev)
 {
-        char *buf2 = g_malloc(1024);
-        GtkWidget *d, *label, *close;
+	char *buf2 = g_malloc(1024);
+	GtkWidget *d, *label, *close;
 
 
 	plugin_event(event_warned, gc, name, (void *)lev, 0);
 
-        g_snprintf(buf2, 1023, "%s have just been warned by %s.\nYour new warning level is %d%%",
-                   gc->username, ((name == NULL) ? "an anonymous person" : name) , lev);
+	g_snprintf(buf2, 1023, "%s have just been warned by %s.\nYour new warning level is %d%%",
+		   gc->username, ((name == NULL)? "an anonymous person" : name), lev);
 
 
-        d = gtk_dialog_new();
-        gtk_widget_realize(d);
-        aol_icon(d->window);
+	d = gtk_dialog_new();
+	gtk_widget_realize(d);
+	aol_icon(d->window);
 
-        label = gtk_label_new(buf2);
-        gtk_widget_show(label);
-        close = gtk_button_new_with_label("Close");
+	label = gtk_label_new(buf2);
+	gtk_widget_show(label);
+	close = gtk_button_new_with_label("Close");
 	if (display_options & OPT_DISP_COOL_LOOK)
 		gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE);
-        gtk_widget_show(close);
-        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox),
-                           label, FALSE, FALSE, 5);
-        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area),
-                           close, FALSE, FALSE, 5);
+	gtk_widget_show(close);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), label, FALSE, FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), close, FALSE, FALSE, 5);
 
-        gtk_window_set_title(GTK_WINDOW(d), "Warned");
-        gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(close_warned), d);
-        gtk_widget_show(d);
+	gtk_window_set_title(GTK_WINDOW(d), "Warned");
+	gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(close_warned), d);
+	gtk_widget_show(d);
 }
 
 
@@ -536,10 +541,10 @@
 static void chat_invite_callback(GtkWidget *w, GtkWidget *w2)
 {
 	struct gaim_connection *g = (struct gaim_connection *)
-					gtk_object_get_user_data(GTK_OBJECT(GTK_DIALOG(w2)->vbox));
+	    gtk_object_get_user_data(GTK_OBJECT(GTK_DIALOG(w2)->vbox));
 	if (g->protocol == PROTO_TOC) {
-	        int i = (int)gtk_object_get_user_data(GTK_OBJECT(w2));
-	        serv_accept_chat(g, i);
+		int i = (int)gtk_object_get_user_data(GTK_OBJECT(w2));
+		serv_accept_chat(g, i);
 		gtk_widget_destroy(w2);
 	} else if (g->protocol == PROTO_OSCAR) {
 		char *i = (char *)gtk_object_get_user_data(GTK_OBJECT(w2));
@@ -554,41 +559,40 @@
 
 void serv_got_chat_invite(struct gaim_connection *g, char *name, int id, char *who, char *message)
 {
-        GtkWidget *d;
-        GtkWidget *label;
-        GtkWidget *yesbtn;
-        GtkWidget *nobtn;
+	GtkWidget *d;
+	GtkWidget *label;
+	GtkWidget *yesbtn;
+	GtkWidget *nobtn;
 
-        char buf2[BUF_LONG];
+	char buf2[BUF_LONG];
 
 
 	plugin_event(event_chat_invited, g, who, name, message);
 
 	if (message)
-		g_snprintf(buf2, sizeof(buf2), "User '%s' invites %s to buddy chat room: '%s'\n%s", who, g->username, name, message);
+		g_snprintf(buf2, sizeof(buf2), "User '%s' invites %s to buddy chat room: '%s'\n%s", who,
+			   g->username, name, message);
 	else
-		g_snprintf(buf2, sizeof(buf2), "User '%s' invites %s to buddy chat room: '%s'\n", who, g->username, name);
+		g_snprintf(buf2, sizeof(buf2), "User '%s' invites %s to buddy chat room: '%s'\n", who,
+			   g->username, name);
 
-        d = gtk_dialog_new();
-        gtk_widget_realize(d);
-        aol_icon(d->window);
+	d = gtk_dialog_new();
+	gtk_widget_realize(d);
+	aol_icon(d->window);
 
 
-        label = gtk_label_new(buf2);
-        gtk_widget_show(label);
-        yesbtn = picture_button(d, _("Yes"), ok_xpm);
-        nobtn = picture_button(d, _("No"), cancel_xpm);
-        gtk_widget_show(nobtn);
-        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox),
-                           label, FALSE, FALSE, 5);
-        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area),
-                           yesbtn, FALSE, FALSE, 5);
-        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area),
-                           nobtn, FALSE, FALSE, 5);
+	label = gtk_label_new(buf2);
+	gtk_widget_show(label);
+	yesbtn = picture_button(d, _("Yes"), ok_xpm);
+	nobtn = picture_button(d, _("No"), cancel_xpm);
+	gtk_widget_show(nobtn);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->vbox), label, FALSE, FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), yesbtn, FALSE, FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), nobtn, FALSE, FALSE, 5);
 
 	gtk_object_set_user_data(GTK_OBJECT(GTK_DIALOG(d)->vbox), g);
 	if (g->protocol == PROTO_TOC) {
-	        gtk_object_set_user_data(GTK_OBJECT(d), (void *)id);
+		gtk_object_set_user_data(GTK_OBJECT(d), (void *)id);
 		gtk_object_set_user_data(GTK_OBJECT(GTK_DIALOG(d)->vbox), g);
 	} else if (g->protocol == PROTO_OSCAR) {
 		gtk_object_set_user_data(GTK_OBJECT(d), (void *)g_strdup(name));
@@ -596,29 +600,29 @@
 	}
 
 
-        gtk_window_set_title(GTK_WINDOW(d), "Buddy chat invite");
-        gtk_signal_connect(GTK_OBJECT(nobtn), "clicked", GTK_SIGNAL_FUNC(close_invite), d);
-        gtk_signal_connect(GTK_OBJECT(yesbtn), "clicked", GTK_SIGNAL_FUNC(chat_invite_callback), d);
+	gtk_window_set_title(GTK_WINDOW(d), "Buddy chat invite");
+	gtk_signal_connect(GTK_OBJECT(nobtn), "clicked", GTK_SIGNAL_FUNC(close_invite), d);
+	gtk_signal_connect(GTK_OBJECT(yesbtn), "clicked", GTK_SIGNAL_FUNC(chat_invite_callback), d);
 
 
-        gtk_widget_show(d);
+	gtk_widget_show(d);
 }
 
 void serv_got_joined_chat(struct gaim_connection *gc, int id, char *name)
 {
-        struct conversation *b;
+	struct conversation *b;
 
 	plugin_event(event_chat_join, gc, name, 0, 0);
 
-        b = (struct conversation *)g_new0(struct conversation, 1);
-        gc->buddy_chats = g_slist_append(gc->buddy_chats, b);
+	b = (struct conversation *)g_new0(struct conversation, 1);
+	gc->buddy_chats = g_slist_append(gc->buddy_chats, b);
 
 	b->is_chat = TRUE;
-        b->ignored = NULL;
-        b->in_room = NULL;
-        b->id = id;
+	b->ignored = NULL;
+	b->in_room = NULL;
+	b->id = id;
 	b->gc = gc;
-        g_snprintf(b->name, 80, "%s", name);
+	g_snprintf(b->name, 80, "%s", name);
 
 	if ((general_options & OPT_GEN_LOG_ALL) || find_log_info(b->name)) {
 		FILE *fd;
@@ -626,43 +630,45 @@
 
 		filename = (char *)malloc(100);
 		g_snprintf(filename, 100, "%s.chat", b->name);
-		
+
 		fd = open_log_file(filename);
 		if (!(general_options & OPT_GEN_STRIP_HTML))
-			fprintf(fd, "<HR><BR><H3 Align=Center> ---- New Conversation @ %s ----</H3><BR>\n", full_date());
+			fprintf(fd,
+				"<HR><BR><H3 Align=Center> ---- New Conversation @ %s ----</H3><BR>\n",
+				full_date());
 		else
 			fprintf(fd, "---- New Conversation @ %s ----\n", full_date());
-		
+
 		fclose(fd);
 		free(filename);
 	}
-	
-        show_new_buddy_chat(b);
+
+	show_new_buddy_chat(b);
 }
 
 void serv_got_chat_left(struct gaim_connection *g, int id)
 {
-        GSList *bcs = g->buddy_chats;
-        struct conversation *b = NULL;
+	GSList *bcs = g->buddy_chats;
+	struct conversation *b = NULL;
 
 
-        while(bcs) {
-                b = (struct conversation *)bcs->data;
-                if (id == b->id) {
-                        break;
-                        }
-                b = NULL;
-                bcs = bcs->next;
-        }
+	while (bcs) {
+		b = (struct conversation *)bcs->data;
+		if (id == b->id) {
+			break;
+		}
+		b = NULL;
+		bcs = bcs->next;
+	}
 
-        if (!b)
-                return;
+	if (!b)
+		return;
 
 	plugin_event(event_chat_leave, g, b->name, 0, 0);
 
 	debug_printf("Leaving room %s.\n", b->name);
 
-        g->buddy_chats = g_slist_remove(g->buddy_chats, b);
+	g->buddy_chats = g_slist_remove(g->buddy_chats, b);
 
 	while (b->in_room) {
 		char *tmp = b->in_room->data;
@@ -670,44 +676,46 @@
 		g_free(tmp);
 	}
 
-        g_free(b);
+	g_free(b);
 }
 
 void serv_got_chat_in(struct gaim_connection *g, int id, char *who, int whisper, char *message)
 {
-        int w;
-        GSList *bcs = g->buddy_chats;
-        struct conversation *b = NULL;
+	int w;
+	GSList *bcs = g->buddy_chats;
+	struct conversation *b = NULL;
 
-        while(bcs) {
-                b = (struct conversation *)bcs->data;
-                if (id == b->id)
-                        break;
-                bcs = bcs->next;
-                b = NULL;
+	while (bcs) {
+		b = (struct conversation *)bcs->data;
+		if (id == b->id)
+			break;
+		bcs = bcs->next;
+		b = NULL;
 
-        }
-        if (!b)
-                return;
-        
-	if (plugin_event(event_chat_recv, g, b->name, who, message))
+	}
+	if (!b)
 		return;
 
-        if (whisper)
-                w = WFLAG_WHISPER;
-        else
-                w = 0;
+	if (plugin_event(event_chat_recv, g, b->name, who, message))
+		 return;
 
-        chat_write(b, who, w, message);
+	if (whisper)
+		w = WFLAG_WHISPER;
+	else
+		w = 0;
+
+	chat_write(b, who, w, message);
 }
 
-void send_keepalive(gpointer d) {
+void send_keepalive(gpointer d)
+{
 	struct gaim_connection *gc = (struct gaim_connection *)d;
 	if (gc->prpl && gc->prpl->keepalive)
 		(*gc->prpl->keepalive)(gc);
 }
 
-void update_keepalive(struct gaim_connection *gc, gboolean on) {
+void update_keepalive(struct gaim_connection *gc, gboolean on)
+{
 	if (on && !gc->keepalive && blist) {
 		debug_printf("allowing NOP\n");
 		gc->keepalive = gtk_timeout_add(60000, (GtkFunction)send_keepalive, gc);