source: logging.c @ dd0edbf

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since dd0edbf was 2b86d14, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Log when outgoing personal message fails
  • Property mode set to 100644
File size: 10.9 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2#include <stdlib.h>
3#include <string.h>
4#include <ctype.h>
5#include <sys/param.h>
6
[1aee7d9]7static const char fileIdent[] = "$Id$";
8
[15283bb]9void owl_log_outgoing_zephyr(char *to, char *text)
10{
[7d4fbcd]11  FILE *file;
[e1c4636]12  char filename[MAXPATHLEN], *logpath;
[e6449bc]13  char *tobuff, *ptr="";
[7d4fbcd]14
[12c35df]15  if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) return;
16
[7d4fbcd]17  tobuff=owl_malloc(strlen(to)+20);
18  strcpy(tobuff, to);
19
20  /* chop off a local realm */
21  ptr=strchr(tobuff, '@');
[09489b89]22  if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
[7d4fbcd]23    *ptr='\0';
24  }
25
[e1c4636]26  /* expand ~ in path names */
[e3d9c77]27  logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 
[e1c4636]28                                owl_global_get_homedir(&g));
29
30  snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
[7d4fbcd]31  file=fopen(filename, "a");
32  if (!file) {
[836ea3a3]33    owl_function_error("Unable to open file for outgoing logging");
[e1c4636]34    owl_free(logpath);
[7d4fbcd]35    return;
36  }
37  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
38  if (text[strlen(text)-1]!='\n') {
39    fprintf(file, "\n");
40  }
41  fclose(file);
42
[e1c4636]43  snprintf(filename, MAXPATHLEN, "%s/all", logpath);
44  owl_free(logpath);
[7d4fbcd]45  file=fopen(filename, "a");
46  if (!file) {
[836ea3a3]47    owl_function_error("Unable to open file for outgoing logging");
[7d4fbcd]48    return;
49  }
50  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
51  if (text[strlen(text)-1]!='\n') {
52    fprintf(file, "\n");
53  }
54  fclose(file);
55
56  owl_free(tobuff);
57}
58
[2b86d14]59void owl_log_outgoing_zephyr_error(char *to, char *text)
60{
61  FILE *file;
62  char filename[MAXPATHLEN], *logpath;
63  char *tobuff, *ptr="";
64
65  tobuff=owl_malloc(strlen(to)+20);
66  strcpy(tobuff, to);
67
68  /* chop off a local realm */
69  ptr=strchr(tobuff, '@');
70  if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
71    *ptr='\0';
72  }
73
74  /* expand ~ in path names */
75  logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 
76                                owl_global_get_homedir(&g));
77
78  snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
79  file=fopen(filename, "a");
80  if (!file) {
81    owl_function_error("Unable to open file for outgoing logging");
82    owl_free(logpath);
83    return;
84  }
85  fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text);
86  if (text[strlen(text)-1]!='\n') {
87    fprintf(file, "\n");
88  }
89  fclose(file);
90
91  snprintf(filename, MAXPATHLEN, "%s/all", logpath);
92  owl_free(logpath);
93  file=fopen(filename, "a");
94  if (!file) {
95    owl_function_error("Unable to open file for outgoing logging");
96    return;
97  }
98  fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text);
99  if (text[strlen(text)-1]!='\n') {
100    fprintf(file, "\n");
101  }
102  fclose(file);
103
104  owl_free(tobuff);
105}
106
[37eab7f]107void owl_log_outgoing_aim(char *to, char *text)
108{
[aac889a]109  FILE *file;
110  char filename[MAXPATHLEN], *logpath;
[d559df9]111  char *tobuff;
[aac889a]112
[12c35df]113  if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) return;
114
[aac889a]115  tobuff=owl_sprintf("aim:%s", to);
116
117  /* expand ~ in path names */
[e3d9c77]118  logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 
[aac889a]119                                owl_global_get_homedir(&g));
120
121  snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
122  file=fopen(filename, "a");
123  if (!file) {
[836ea3a3]124    owl_function_error("Unable to open file for outgoing logging");
[aac889a]125    owl_free(logpath);
126    return;
127  }
128  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
129  if (text[strlen(text)-1]!='\n') {
130    fprintf(file, "\n");
131  }
132  fclose(file);
133
134  snprintf(filename, MAXPATHLEN, "%s/all", logpath);
135  owl_free(logpath);
136  file=fopen(filename, "a");
137  if (!file) {
[836ea3a3]138    owl_function_error("Unable to open file for outgoing logging");
[aac889a]139    return;
140  }
141  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
142  if (text[strlen(text)-1]!='\n') {
143    fprintf(file, "\n");
144  }
145  fclose(file);
146
147  owl_free(tobuff);
148}
149
[37eab7f]150void owl_log_outgoing_loopback(char *text)
151{
152  FILE *file;
153  char filename[MAXPATHLEN], *logpath;
154  char *tobuff;
155
[12c35df]156  if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) return;
157
158  tobuff=owl_sprintf("loopback");
[37eab7f]159
160  /* expand ~ in path names */
[e3d9c77]161  logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 
[37eab7f]162                                owl_global_get_homedir(&g));
163
164  snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
165  file=fopen(filename, "a");
166  if (!file) {
167    owl_function_error("Unable to open file for outgoing logging");
168    owl_free(logpath);
169    return;
170  }
171  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
172  if (text[strlen(text)-1]!='\n') {
173    fprintf(file, "\n");
174  }
175  fclose(file);
176
177  snprintf(filename, MAXPATHLEN, "%s/all", logpath);
178  owl_free(logpath);
179  file=fopen(filename, "a");
180  if (!file) {
181    owl_function_error("Unable to open file for outgoing logging");
182    return;
183  }
184  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
185  if (text[strlen(text)-1]!='\n') {
186    fprintf(file, "\n");
187  }
188  fclose(file);
189
190  owl_free(tobuff);
191}
192
[15283bb]193void owl_log_incoming(owl_message *m)
194{
[7d4fbcd]195  FILE *file, *allfile;
[e1c4636]196  char filename[MAXPATHLEN], allfilename[MAXPATHLEN], *logpath;
[e6449bc]197  char *frombuff=NULL, *from=NULL, *buff=NULL, *ptr;
[7d4fbcd]198  int len, ch, i, personal;
[12c35df]199
200  if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) return;
[d09e5a1]201     
[7d4fbcd]202  /* check for nolog */
203  if (!strcasecmp(owl_message_get_opcode(m), "nolog") ||
204      !strcasecmp(owl_message_get_instance(m), "nolog")) return;
205
[aac889a]206  /* this is kind of a mess */
207  if (owl_message_is_type_zephyr(m)) {
208    if (owl_message_is_personal(m)) {
209      personal=1;
210      if (!owl_global_is_logging(&g)) return;
211    } else {
212      personal=0;
213      if (!owl_global_is_classlogging(&g)) return;
214    }
[7d4fbcd]215  } else {
[79a0e82]216    if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
[aac889a]217      personal=1;
218      if (!owl_global_is_logging(&g)) return;
219    } else {
220      personal=0;
221      if (!owl_global_is_classlogging(&g)) return;
222    }
[7d4fbcd]223  }
224
[aac889a]225  if (owl_message_is_type_zephyr(m)) {
226    /* chop off a local realm for personal zephyr messages */
227    if (personal) {
228      if (owl_message_is_type_zephyr(m)) {
229        from=frombuff=owl_strdup(owl_message_get_sender(m));
230        ptr=strchr(frombuff, '@');
[09489b89]231        if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
[aac889a]232          *ptr='\0';
233        }
234      }
235    } else {
236      /* we assume zephyr for now */
237      from=frombuff=owl_strdup(owl_message_get_class(m));
[7d4fbcd]238    }
[aac889a]239  } else if (owl_message_is_type_aim(m)) {
240    /* we do not yet handle chat rooms */
241    from=frombuff=owl_sprintf("aim:%s", owl_message_get_sender(m));
[37eab7f]242  } else if (owl_message_is_type_loopback(m)) {
243    from=frombuff=owl_strdup("loopback");
[e6449bc]244  } else {
245    from=frombuff=owl_strdup("unknown");
[7d4fbcd]246  }
247 
248  /* check for malicious sender formats */
249  len=strlen(frombuff);
250  if (len<1 || len>35) from="weird";
251  if (strchr(frombuff, '/')) from="weird";
252
253  ch=frombuff[0];
254  if (!isalnum(ch)) from="weird";
255
256  for (i=0; i<len; i++) {
[e1c4636]257    if (frombuff[i]<'!' || frombuff[i]>='~') from="weird";
[7d4fbcd]258  }
259
260  if (!strcmp(frombuff, ".") || !strcasecmp(frombuff, "..")) from="weird";
261
262  if (!personal) {
263    if (strcmp(from, "weird")) downstr(from);
264  }
265
[e1c4636]266  /* create the filename (expanding ~ in path names) */
[7d4fbcd]267  if (personal) {
[e3d9c77]268    logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 
[e1c4636]269                                  owl_global_get_homedir(&g));
270    snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from);
271    snprintf(allfilename, MAXPATHLEN, "%s/all", logpath);
272
[7d4fbcd]273  } else {
[e3d9c77]274    logpath = owl_text_substitute(owl_global_get_classlogpath(&g), "~", 
[e1c4636]275                                owl_global_get_homedir(&g));
276
277    snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from);
[7d4fbcd]278  }
[e1c4636]279  owl_free(logpath);
[7d4fbcd]280 
281  file=fopen(filename, "a");
282  if (!file) {
[836ea3a3]283    owl_function_error("Unable to open file for incoming logging");
[7d4fbcd]284    return;
285  }
286
287  allfile=NULL;
288  if (personal) {
289    allfile=fopen(allfilename, "a");
290    if (!allfile) {
[836ea3a3]291      owl_function_error("Unable to open file for incoming logging");
[79a0e82]292      fclose(file);
[7d4fbcd]293      return;
294    }
295  }
296
[aac889a]297  /* write to the main file */
298  if (owl_message_is_type_zephyr(m)) {
[e6449bc]299    char *tmp;
300   
[aac889a]301    tmp=short_zuser(owl_message_get_sender(m));
302    fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
303    if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m));
304    fprintf(file, "\n");
305    fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
306    ptr=owl_zephyr_get_zsig(owl_message_get_notice(m), &i);
307    buff=owl_malloc(i+10);
308    memcpy(buff, ptr, i);
309    buff[i]='\0';
310    fprintf(file, "From: %s <%s>\n\n", buff, tmp);
[269ed34]311    fprintf(file, "%s\n\n", owl_message_get_body(m));
[e6449bc]312    owl_free(tmp);
[79a0e82]313  } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) {
[aac889a]314    fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
315    fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
316    fprintf(file, "%s\n\n", owl_message_get_body(m));
[79a0e82]317  } else if (owl_message_is_type_aim(m) && owl_message_is_loginout(m)) {
318    fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
319    fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
320    if (owl_message_is_login(m)) fprintf(file, "LOGIN\n\n");
321    if (owl_message_is_logout(m)) fprintf(file, "LOGOUT\n\n");
[37eab7f]322  } else {
323    fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
324    fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
325    fprintf(file, "%s\n\n", owl_message_get_body(m));
[aac889a]326  }
[37eab7f]327
[7d4fbcd]328  fclose(file);
329
[aac889a]330  /* if it's a personal message, also write to the 'all' file */
[7d4fbcd]331  if (personal) {
[aac889a]332    if (owl_message_is_type_zephyr(m)) {
[e6449bc]333      char *tmp;
334
335      tmp=short_zuser(owl_message_get_sender(m));
[aac889a]336      fprintf(allfile, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
337      if (strcmp(owl_message_get_opcode(m), "")) fprintf(allfile, " Opcode: %s", owl_message_get_opcode(m));
338      fprintf(allfile, "\n");
339      fprintf(allfile, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
340      fprintf(allfile, "From: %s <%s>\n\n", buff, tmp);
[269ed34]341      fprintf(allfile, "%s\n\n", owl_message_get_body(m));
[e6449bc]342      owl_free(tmp);
[79a0e82]343    } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) {
344      fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
345      fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m));
346      fprintf(allfile, "%s\n\n", owl_message_get_body(m));
347    } else if (owl_message_is_type_aim(m) && owl_message_is_loginout(m)) {
348      fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
349      fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m));
350      if (owl_message_is_login(m)) fprintf(allfile, "LOGIN\n\n");
351      if (owl_message_is_logout(m)) fprintf(allfile, "LOGOUT\n\n");
[37eab7f]352    } else {
[eec69e1]353      fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
354      fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m));
355      fprintf(allfile, "%s\n\n", owl_message_get_body(m));
[aac889a]356    }
[723c427]357    fclose(allfile);
[7d4fbcd]358  }
359
[aac889a]360  if (owl_message_is_type_zephyr(m)) {
361    owl_free(buff);
362  }
[7d4fbcd]363  owl_free(frombuff);
364}
Note: See TracBrowser for help on using the repository browser.