Mercurial > pidgin
annotate src/log.c @ 5528:c72213437829
[gaim-migrate @ 5928]
Dario Sarango (darius_wolfson) writes:
"Patch to fix bug #743397
I added some snity checks when removing a log file, to avoid gai
segfaulting when removing an invalid/non-existing log file."
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Mon, 26 May 2003 04:28:11 +0000 |
| parents | ad445074d239 |
| children | 80e4ba770f97 |
| rev | line source |
|---|---|
| 4184 | 1 /* --------------------------------------------------- |
| 2 * Function to remove a log file entry | |
| 3 * --------------------------------------------------- | |
| 4 */ | |
| 4195 | 5 #ifdef HAVE_CONFIG_H |
| 6 #include <config.h> | |
| 7 #endif | |
| 8 #include <string.h> | |
| 9 | |
| 10 #ifndef _WIN32 | |
| 11 #include <unistd.h> | |
| 12 #endif | |
| 13 | |
| 4184 | 14 #include "gaim.h" |
| 15 #include "core.h" | |
| 16 #include "multi.h" | |
| 17 #include "prpl.h" | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
18 #include "notify.h" |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
19 #include <string.h> |
| 4184 | 20 #include <sys/stat.h> |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
21 #include <unistd.h> |
| 4184 | 22 |
|
4192
17187504bfc2
[gaim-migrate @ 4423]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4184
diff
changeset
|
23 #ifdef _WIN32 |
|
17187504bfc2
[gaim-migrate @ 4423]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4184
diff
changeset
|
24 #include "win32dep.h" |
|
17187504bfc2
[gaim-migrate @ 4423]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4184
diff
changeset
|
25 #endif |
|
17187504bfc2
[gaim-migrate @ 4423]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4184
diff
changeset
|
26 |
| 4184 | 27 void rm_log(struct log_conversation *a) |
| 28 { | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
29 struct gaim_conversation *cnv = gaim_find_conversation(a->name); |
| 4184 | 30 |
| 5528 | 31 /* Added the following if statements for sanity check */ |
| 32 if (!a) | |
| 33 { | |
| 34 gaim_notify_error (NULL, NULL, _("Error in specifying buddy conversation."), NULL); | |
| 35 return; | |
| 36 } | |
| 37 cnv = gaim_find_conversation(a->name); | |
| 38 if (!cnv) | |
| 39 { | |
| 40 gaim_notify_error (NULL, NULL, _("Unable to find conversation log"), NULL); | |
| 41 return; | |
| 42 } | |
| 43 | |
| 4184 | 44 log_conversations = g_list_remove(log_conversations, a); |
| 45 | |
| 46 save_prefs(); | |
| 47 | |
| 48 if (cnv && !(im_options & OPT_IM_ONE_WINDOW)) | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
49 gaim_conversation_autoset_title(cnv); |
| 4184 | 50 } |
| 51 | |
| 52 struct log_conversation *find_log_info(const char *name) | |
| 53 { | |
| 54 char *pname = g_malloc(BUF_LEN); | |
| 55 GList *lc = log_conversations; | |
| 56 struct log_conversation *l; | |
| 57 | |
| 58 | |
| 59 strcpy(pname, normalize(name)); | |
| 60 | |
| 61 while (lc) { | |
| 62 l = (struct log_conversation *)lc->data; | |
| 4793 | 63 if (!gaim_utf8_strcasecmp(pname, normalize(l->name))) { |
| 4184 | 64 g_free(pname); |
| 65 return l; | |
| 66 } | |
| 67 lc = lc->next; | |
| 68 } | |
| 69 g_free(pname); | |
| 70 return NULL; | |
| 71 } | |
| 72 | |
| 73 void update_log_convs() | |
| 74 { | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
75 GList *cnv; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
76 struct gaim_conversation *c; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
77 struct gaim_gtk_conversation *gtkconv; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
78 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
79 for (cnv = gaim_get_conversations(); cnv != NULL; cnv = cnv->next) { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
80 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
81 c = (struct gaim_conversation *)cnv->data; |
| 4184 | 82 |
|
4398
a8249a5250b6
[gaim-migrate @ 4667]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
83 if (!GAIM_IS_GTK_CONVERSATION(c)) |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
84 continue; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
85 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
86 gtkconv = GAIM_GTK_CONVERSATION(c); |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
87 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
88 if (gtkconv->toolbar.log) { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
89 if (gaim_conversation_get_type(c) == GAIM_CONV_CHAT) |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
90 gtk_widget_set_sensitive(GTK_WIDGET(gtkconv->toolbar.log), |
| 4184 | 91 ((logging_options & OPT_LOG_CHATS)) ? FALSE : TRUE); |
| 92 else | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
93 gtk_widget_set_sensitive(GTK_WIDGET(gtkconv->toolbar.log), |
| 4184 | 94 ((logging_options & OPT_LOG_CONVOS)) ? FALSE : TRUE); |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 | |
| 4635 | 99 static void do_save_convo(GObject *obj, GtkWidget *wid) |
| 4184 | 100 { |
| 4635 | 101 struct gaim_conversation *c = g_object_get_data(obj, "gaim_conversation"); |
| 4184 | 102 const char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(wid)); |
| 103 FILE *f; | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
104 |
| 4184 | 105 if (file_is_dir(filename, wid)) |
| 106 return; | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
107 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
108 if (!((gaim_conversation_get_type(c) != GAIM_CONV_CHAT && |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
109 g_list_find(gaim_get_ims(), c)) || |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
110 (gaim_conversation_get_type(c) == GAIM_CONV_CHAT && |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
111 g_list_find(gaim_get_chats(), c)))) |
| 4184 | 112 filename = NULL; |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
113 |
| 4184 | 114 gtk_widget_destroy(wid); |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
115 |
| 4184 | 116 if (!filename) |
| 117 return; | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
118 |
| 4184 | 119 f = fopen(filename, "w+"); |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
120 |
| 4184 | 121 if (!f) |
| 122 return; | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
123 |
| 4184 | 124 fprintf(f, "%s", c->history->str); |
| 125 fclose(f); | |
| 126 } | |
| 127 | |
| 128 | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
129 void save_convo(GtkWidget *save, struct gaim_conversation *c) |
| 4184 | 130 { |
| 131 char buf[BUF_LONG]; | |
| 132 GtkWidget *window = gtk_file_selection_new(_("Gaim - Save Conversation")); | |
| 133 g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S "%s.log", gaim_home_dir(), normalize(c->name)); | |
| 134 gtk_file_selection_set_filename(GTK_FILE_SELECTION(window), buf); | |
| 4635 | 135 g_object_set_data(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button), |
| 136 "gaim_conversation", c); | |
|
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
137 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(window)->ok_button), |
| 4184 | 138 "clicked", G_CALLBACK(do_save_convo), window); |
|
5314
1f901484599d
[gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
139 g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(window)->cancel_button), |
| 4184 | 140 "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer)window); |
| 141 gtk_widget_show(window); | |
| 142 } | |
| 143 | |
| 144 static FILE *open_gaim_log_file(const char *name, int *flag) | |
| 145 { | |
| 146 char *buf; | |
| 147 char *buf2; | |
| 148 char log_all_file[256]; | |
| 149 struct stat st; | |
| 150 FILE *fd; | |
| 151 #ifndef _WIN32 | |
| 152 int res; | |
| 153 #endif | |
| 154 gchar *gaim_dir; | |
| 155 | |
| 156 buf = g_malloc(BUF_LONG); | |
| 157 buf2 = g_malloc(BUF_LONG); | |
| 158 gaim_dir = gaim_user_dir(); | |
| 159 | |
| 160 /* Dont log yourself */ | |
| 161 strncpy(log_all_file, gaim_dir, 256); | |
| 162 | |
| 163 #ifndef _WIN32 | |
| 164 stat(log_all_file, &st); | |
| 165 if (!S_ISDIR(st.st_mode)) | |
| 166 unlink(log_all_file); | |
| 167 | |
| 168 fd = fopen(log_all_file, "r"); | |
| 169 | |
| 170 if (!fd) { | |
| 171 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 172 if (res < 0) { | |
| 173 g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), | |
| 174 log_all_file); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
175 gaim_notify_error(NULL, NULL, buf, NULL); |
| 4184 | 176 g_free(buf); |
| 177 g_free(buf2); | |
| 178 return NULL; | |
| 179 } | |
| 180 } else | |
| 181 fclose(fd); | |
| 182 | |
| 183 g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir); | |
| 184 | |
| 185 if (stat(log_all_file, &st) < 0) | |
| 186 *flag = 1; | |
| 187 if (!S_ISDIR(st.st_mode)) | |
| 188 unlink(log_all_file); | |
| 189 | |
| 190 fd = fopen(log_all_file, "r"); | |
| 191 if (!fd) { | |
| 192 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 193 if (res < 0) { | |
| 194 g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), | |
| 195 log_all_file); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
196 gaim_notify_error(NULL, NULL, buf, NULL); |
| 4184 | 197 g_free(buf); |
| 198 g_free(buf2); | |
| 199 return NULL; | |
| 200 } | |
| 201 } else | |
| 202 fclose(fd); | |
| 203 #else /* _WIN32 */ | |
| 204 g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir); | |
| 205 | |
| 206 if( _mkdir(log_all_file) < 0 && errno != EEXIST ) { | |
| 207 g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), log_all_file); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
208 gaim_notify_error(NULL, NULL, buf, NULL); |
| 4184 | 209 g_free(buf); |
| 210 g_free(buf2); | |
| 211 return NULL; | |
| 212 } | |
| 213 #endif | |
| 214 | |
| 215 g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s", gaim_dir, name); | |
| 216 if (stat(log_all_file, &st) < 0) | |
| 217 *flag = 1; | |
| 218 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
219 gaim_debug(GAIM_DEBUG_INFO, "log", "Logging to: \"%s\"\n", log_all_file); |
| 4184 | 220 |
| 221 fd = fopen(log_all_file, "a"); | |
| 222 | |
| 223 g_free(buf); | |
| 224 g_free(buf2); | |
| 225 return fd; | |
| 226 } | |
| 227 | |
| 228 static FILE *open_system_log_file(char *name) | |
| 229 { | |
| 230 int x; | |
| 231 | |
| 232 if (name) | |
| 233 return open_log_file(name, 2); | |
| 234 else | |
| 235 return open_gaim_log_file("system", &x); | |
| 236 } | |
| 237 | |
| 238 FILE *open_log_file(const char *name, int is_chat) | |
| 239 { | |
| 240 struct stat st; | |
| 241 char realname[256]; | |
| 242 struct log_conversation *l; | |
| 243 FILE *fd; | |
| 244 int flag = 0; | |
| 245 | |
| 246 if (((is_chat == 2) && !(logging_options & OPT_LOG_INDIVIDUAL)) | |
| 247 || ((is_chat == 1) && !(logging_options & OPT_LOG_CHATS)) | |
| 248 || ((is_chat == 0) && !(logging_options & OPT_LOG_CONVOS))) { | |
| 249 | |
| 250 l = find_log_info(name); | |
| 251 if (!l) | |
| 252 return NULL; | |
| 253 | |
| 254 if (stat(l->filename, &st) < 0) | |
| 255 flag = 1; | |
| 256 | |
| 257 fd = fopen(l->filename, "a"); | |
| 258 | |
| 259 if (flag) { /* is a new file */ | |
| 260 if (logging_options & OPT_LOG_STRIP_HTML) { | |
| 261 fprintf(fd, _("IM Sessions with %s\n"), name); | |
| 262 } else { | |
| 263 fprintf(fd, "<HTML><HEAD><TITLE>"); | |
| 264 fprintf(fd, _("IM Sessions with %s"), name); | |
| 5138 | 265 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n"); |
| 4184 | 266 } |
| 267 } | |
| 268 | |
| 269 return fd; | |
| 270 } | |
| 271 | |
| 272 g_snprintf(realname, sizeof(realname), "%s.log", normalize(name)); | |
| 273 fd = open_gaim_log_file(realname, &flag); | |
| 274 | |
| 275 if (fd && flag) { /* is a new file */ | |
| 276 if (logging_options & OPT_LOG_STRIP_HTML) { | |
| 277 fprintf(fd, _("IM Sessions with %s\n"), name); | |
| 278 } else { | |
| 279 fprintf(fd, "<HTML><HEAD><TITLE>"); | |
| 280 fprintf(fd, _("IM Sessions with %s"), name); | |
| 5138 | 281 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n"); |
| 4184 | 282 } |
| 283 } | |
| 284 | |
| 285 return fd; | |
| 286 } | |
| 287 | |
| 288 void system_log(enum log_event what, struct gaim_connection *gc, | |
| 289 struct buddy *who, int why) | |
| 290 { | |
| 291 FILE *fd; | |
| 292 char text[256], html[256]; | |
| 293 | |
| 294 if ((logging_options & why) != why) | |
| 295 return; | |
| 296 | |
| 297 if (logging_options & OPT_LOG_INDIVIDUAL) { | |
| 298 if (why & OPT_LOG_MY_SIGNON) | |
| 299 fd = open_system_log_file(gc ? gc->username : NULL); | |
| 300 else | |
| 301 fd = open_system_log_file(who->name); | |
| 302 } else | |
| 303 fd = open_system_log_file(NULL); | |
| 304 | |
| 305 if (!fd) | |
| 306 return; | |
| 307 | |
| 308 if (why & OPT_LOG_MY_SIGNON) { | |
| 309 switch (what) { | |
| 310 case log_signon: | |
| 4195 | 311 g_snprintf(text, sizeof(text), _("+++ %s (%s) signed on @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
312 gc->username, gc->prpl->info->name, full_date()); |
| 4184 | 313 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
| 314 break; | |
| 315 case log_signoff: | |
| 4195 | 316 g_snprintf(text, sizeof(text), _("+++ %s (%s) signed off @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
317 gc->username, gc->prpl->info->name, full_date()); |
| 4184 | 318 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
| 319 break; | |
| 320 case log_away: | |
| 4195 | 321 g_snprintf(text, sizeof(text), _("+++ %s (%s) changed away state @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
322 gc->username, gc->prpl->info->name, full_date()); |
| 4184 | 323 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
| 324 break; | |
| 325 case log_back: | |
| 4195 | 326 g_snprintf(text, sizeof(text), _("+++ %s (%s) came back @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
327 gc->username, gc->prpl->info->name, full_date()); |
| 4184 | 328 g_snprintf(html, sizeof(html), "%s", text); |
| 329 break; | |
| 330 case log_idle: | |
| 4195 | 331 g_snprintf(text, sizeof(text), _("+++ %s (%s) became idle @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
332 gc->username, gc->prpl->info->name, full_date()); |
| 4184 | 333 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
| 334 break; | |
| 335 case log_unidle: | |
| 4195 | 336 g_snprintf(text, sizeof(text), _("+++ %s (%s) returned from idle @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
337 gc->username, gc->prpl->info->name, full_date()); |
| 4184 | 338 g_snprintf(html, sizeof(html), "%s", text); |
| 339 break; | |
| 340 case log_quit: | |
| 4195 | 341 g_snprintf(text, sizeof(text), _("+++ Program exit @ %s"), full_date()); |
| 4184 | 342 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
| 343 break; | |
| 344 } | |
| 4687 | 345 } else if (gaim_get_buddy_alias_only(who)) { |
| 4184 | 346 switch (what) { |
| 347 case log_signon: | |
| 4195 | 348 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) signed on @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
349 gc->username, gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); |
| 4184 | 350 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
| 351 break; | |
| 352 case log_signoff: | |
| 4195 | 353 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) signed off @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
354 gc->username, gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); |
| 4184 | 355 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
| 356 break; | |
| 357 case log_away: | |
| 4195 | 358 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) went away @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
359 gc->username, gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); |
| 4184 | 360 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
| 361 break; | |
| 362 case log_back: | |
| 4195 | 363 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) came back @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
364 gc->username, gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); |
| 4184 | 365 g_snprintf(html, sizeof(html), "%s", text); |
| 366 break; | |
| 367 case log_idle: | |
| 4195 | 368 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) became idle @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
369 gc->username, gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); |
| 4184 | 370 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
| 371 break; | |
| 372 case log_unidle: | |
| 373 g_snprintf(text, sizeof(text), | |
| 4195 | 374 _("%s (%s) reported that %s (%s) returned from idle @ %s"), gc->username, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
375 gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); |
| 4184 | 376 g_snprintf(html, sizeof(html), "%s", text); |
| 377 break; | |
| 378 default: | |
| 379 fclose(fd); | |
| 380 return; | |
| 381 break; | |
| 382 } | |
| 383 } else { | |
| 384 switch (what) { | |
| 385 case log_signon: | |
| 4195 | 386 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s signed on @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
387 gc->username, gc->prpl->info->name, who->name, full_date()); |
| 4184 | 388 g_snprintf(html, sizeof(html), "<B>%s</B>", text); |
| 389 break; | |
| 390 case log_signoff: | |
| 4195 | 391 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s signed off @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
392 gc->username, gc->prpl->info->name, who->name, full_date()); |
| 4184 | 393 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); |
| 394 break; | |
| 395 case log_away: | |
| 4195 | 396 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s went away @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
397 gc->username, gc->prpl->info->name, who->name, full_date()); |
| 4184 | 398 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); |
| 399 break; | |
| 400 case log_back: | |
| 4195 | 401 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s came back @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
402 gc->username, gc->prpl->info->name, who->name, full_date()); |
| 4184 | 403 g_snprintf(html, sizeof(html), "%s", text); |
| 404 break; | |
| 405 case log_idle: | |
| 4195 | 406 g_snprintf(text, sizeof(text), _("%s (%s) reported that %s became idle @ %s"), |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
407 gc->username, gc->prpl->info->name, who->name, full_date()); |
| 4184 | 408 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); |
| 409 break; | |
| 410 case log_unidle: | |
| 411 g_snprintf(text, sizeof(text), | |
| 4195 | 412 _("%s (%s) reported that %s returned from idle @ %s"), gc->username, |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5138
diff
changeset
|
413 gc->prpl->info->name, who->name, full_date()); |
| 4184 | 414 g_snprintf(html, sizeof(html), "%s", text); |
| 415 break; | |
| 416 default: | |
| 417 fclose(fd); | |
| 418 return; | |
| 419 break; | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 if (logging_options & OPT_LOG_STRIP_HTML) { | |
| 424 fprintf(fd, "---- %s ----\n", text); | |
| 425 } else { | |
| 426 if (logging_options & OPT_LOG_INDIVIDUAL) | |
| 427 fprintf(fd, "<HR>%s<BR><HR><BR>\n", html); | |
| 428 else | |
| 429 fprintf(fd, "%s<BR>\n", html); | |
| 430 } | |
| 431 | |
| 432 fclose(fd); | |
| 433 } | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
434 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
435 char *html_logize(const char *p) |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
436 { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
437 const char *temp_p; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
438 char *buffer_p; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
439 char *buffer_start; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
440 int num_cr = 0; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
441 int char_len = 0; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
442 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
443 for (temp_p = p; *temp_p != '\0'; temp_p++) { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
444 char_len++; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
445 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
446 if ((*temp_p == '\n') || ((*temp_p == '<') && (*(temp_p + 1) == '!'))) |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
447 num_cr++; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
448 } |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
449 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
450 buffer_p = g_malloc(char_len + (4 * num_cr) + 1); |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
451 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
452 for (temp_p = p, buffer_start = buffer_p; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
453 *temp_p != '\0'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
454 temp_p++) { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
455 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
456 if (*temp_p == '\n') { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
457 *buffer_p++ = '<'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
458 *buffer_p++ = 'B'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
459 *buffer_p++ = 'R'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
460 *buffer_p++ = '>'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
461 *buffer_p++ = '\n'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
462 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
463 } else if ((*temp_p == '<') && (*(temp_p + 1) == '!')) { |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
464 *buffer_p++ = '&'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
465 *buffer_p++ = 'l'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
466 *buffer_p++ = 't'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
467 *buffer_p++ = ';'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
468 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
469 } else |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
470 *buffer_p++ = *temp_p; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
471 } |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
472 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
473 *buffer_p = '\0'; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
474 |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
475 return buffer_start; |
|
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
476 } |
