source: logging.c @ db2dd3d

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since db2dd3d was 15283bb, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Updated basic help
  • Property mode set to 100644
File size: 7.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
15  tobuff=owl_malloc(strlen(to)+20);
16  strcpy(tobuff, to);
17
18  /* chop off a local realm */
19  ptr=strchr(tobuff, '@');
[09489b89]20  if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
[7d4fbcd]21    *ptr='\0';
22  }
23
[e1c4636]24  /* expand ~ in path names */
25  logpath = owl_util_substitute(owl_global_get_logpath(&g), "~", 
26                                owl_global_get_homedir(&g));
27
28  snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
[7d4fbcd]29  file=fopen(filename, "a");
30  if (!file) {
[836ea3a3]31    owl_function_error("Unable to open file for outgoing logging");
[e1c4636]32    owl_free(logpath);
[7d4fbcd]33    return;
34  }
35  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
36  if (text[strlen(text)-1]!='\n') {
37    fprintf(file, "\n");
38  }
39  fclose(file);
40
[e1c4636]41  snprintf(filename, MAXPATHLEN, "%s/all", logpath);
42  owl_free(logpath);
[7d4fbcd]43  file=fopen(filename, "a");
44  if (!file) {
[836ea3a3]45    owl_function_error("Unable to open file for outgoing logging");
[7d4fbcd]46    return;
47  }
48  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
49  if (text[strlen(text)-1]!='\n') {
50    fprintf(file, "\n");
51  }
52  fclose(file);
53
54  owl_free(tobuff);
55}
56
[aac889a]57void owl_log_outgoing_aim(char *to, char *text) {
58  FILE *file;
59  char filename[MAXPATHLEN], *logpath;
[d559df9]60  char *tobuff;
[aac889a]61
62  tobuff=owl_sprintf("aim:%s", to);
63
64  /* expand ~ in path names */
65  logpath = owl_util_substitute(owl_global_get_logpath(&g), "~", 
66                                owl_global_get_homedir(&g));
67
68  snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff);
69  file=fopen(filename, "a");
70  if (!file) {
[836ea3a3]71    owl_function_error("Unable to open file for outgoing logging");
[aac889a]72    owl_free(logpath);
73    return;
74  }
75  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
76  if (text[strlen(text)-1]!='\n') {
77    fprintf(file, "\n");
78  }
79  fclose(file);
80
81  snprintf(filename, MAXPATHLEN, "%s/all", logpath);
82  owl_free(logpath);
83  file=fopen(filename, "a");
84  if (!file) {
[836ea3a3]85    owl_function_error("Unable to open file for outgoing logging");
[aac889a]86    return;
87  }
88  fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text);
89  if (text[strlen(text)-1]!='\n') {
90    fprintf(file, "\n");
91  }
92  fclose(file);
93
94  owl_free(tobuff);
95}
96
[15283bb]97void owl_log_incoming(owl_message *m)
98{
[7d4fbcd]99  FILE *file, *allfile;
[e1c4636]100  char filename[MAXPATHLEN], allfilename[MAXPATHLEN], *logpath;
[e6449bc]101  char *frombuff=NULL, *from=NULL, *buff=NULL, *ptr;
[7d4fbcd]102  int len, ch, i, personal;
[d09e5a1]103     
[7d4fbcd]104  /* check for nolog */
105  if (!strcasecmp(owl_message_get_opcode(m), "nolog") ||
106      !strcasecmp(owl_message_get_instance(m), "nolog")) return;
107
[aac889a]108  /* this is kind of a mess */
109  if (owl_message_is_type_zephyr(m)) {
110    if (owl_message_is_personal(m)) {
111      personal=1;
112      if (!owl_global_is_logging(&g)) return;
113    } else {
114      personal=0;
115      if (!owl_global_is_classlogging(&g)) return;
116    }
[7d4fbcd]117  } else {
[79a0e82]118    if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
[aac889a]119      personal=1;
120      if (!owl_global_is_logging(&g)) return;
121    } else {
122      personal=0;
123      if (!owl_global_is_classlogging(&g)) return;
124    }
[7d4fbcd]125  }
126
[aac889a]127  if (owl_message_is_type_zephyr(m)) {
128    /* chop off a local realm for personal zephyr messages */
129    if (personal) {
130      if (owl_message_is_type_zephyr(m)) {
131        from=frombuff=owl_strdup(owl_message_get_sender(m));
132        ptr=strchr(frombuff, '@');
[09489b89]133        if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) {
[aac889a]134          *ptr='\0';
135        }
136      }
137    } else {
138      /* we assume zephyr for now */
139      from=frombuff=owl_strdup(owl_message_get_class(m));
[7d4fbcd]140    }
[aac889a]141  } else if (owl_message_is_type_aim(m)) {
142    /* we do not yet handle chat rooms */
143    from=frombuff=owl_sprintf("aim:%s", owl_message_get_sender(m));
[e6449bc]144  } else {
145    from=frombuff=owl_strdup("unknown");
[7d4fbcd]146  }
147 
148  /* check for malicious sender formats */
149  len=strlen(frombuff);
150  if (len<1 || len>35) from="weird";
151  if (strchr(frombuff, '/')) from="weird";
152
153  ch=frombuff[0];
154  if (!isalnum(ch)) from="weird";
155
156  for (i=0; i<len; i++) {
[e1c4636]157    if (frombuff[i]<'!' || frombuff[i]>='~') from="weird";
[7d4fbcd]158  }
159
160  if (!strcmp(frombuff, ".") || !strcasecmp(frombuff, "..")) from="weird";
161
162  if (!personal) {
163    if (strcmp(from, "weird")) downstr(from);
164  }
165
[e1c4636]166  /* create the filename (expanding ~ in path names) */
[7d4fbcd]167  if (personal) {
[e1c4636]168    logpath = owl_util_substitute(owl_global_get_logpath(&g), "~", 
169                                  owl_global_get_homedir(&g));
170    snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from);
171    snprintf(allfilename, MAXPATHLEN, "%s/all", logpath);
172
[7d4fbcd]173  } else {
[e1c4636]174    logpath = owl_util_substitute(owl_global_get_classlogpath(&g), "~", 
175                                owl_global_get_homedir(&g));
176
177    snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from);
[7d4fbcd]178  }
[e1c4636]179  owl_free(logpath);
[7d4fbcd]180 
181  file=fopen(filename, "a");
182  if (!file) {
[836ea3a3]183    owl_function_error("Unable to open file for incoming logging");
[7d4fbcd]184    return;
185  }
186
187  allfile=NULL;
188  if (personal) {
189    allfile=fopen(allfilename, "a");
190    if (!allfile) {
[836ea3a3]191      owl_function_error("Unable to open file for incoming logging");
[79a0e82]192      fclose(file);
[7d4fbcd]193      return;
194    }
195  }
196
[aac889a]197  /* write to the main file */
198  if (owl_message_is_type_zephyr(m)) {
[e6449bc]199    char *tmp;
200   
[aac889a]201    tmp=short_zuser(owl_message_get_sender(m));
202    fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
203    if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m));
204    fprintf(file, "\n");
205    fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
206    ptr=owl_zephyr_get_zsig(owl_message_get_notice(m), &i);
207    buff=owl_malloc(i+10);
208    memcpy(buff, ptr, i);
209    buff[i]='\0';
210    fprintf(file, "From: %s <%s>\n\n", buff, tmp);
[269ed34]211    fprintf(file, "%s\n\n", owl_message_get_body(m));
[e6449bc]212    owl_free(tmp);
[79a0e82]213  } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) {
[aac889a]214    fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
215    fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
216    fprintf(file, "%s\n\n", owl_message_get_body(m));
[79a0e82]217  } else if (owl_message_is_type_aim(m) && owl_message_is_loginout(m)) {
218    fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
219    fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m));
220    if (owl_message_is_login(m)) fprintf(file, "LOGIN\n\n");
221    if (owl_message_is_logout(m)) fprintf(file, "LOGOUT\n\n");
[aac889a]222  }
[7d4fbcd]223  fclose(file);
224
[aac889a]225  /* if it's a personal message, also write to the 'all' file */
[7d4fbcd]226  if (personal) {
[aac889a]227    if (owl_message_is_type_zephyr(m)) {
[e6449bc]228      char *tmp;
229
230      tmp=short_zuser(owl_message_get_sender(m));
[aac889a]231      fprintf(allfile, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m));
232      if (strcmp(owl_message_get_opcode(m), "")) fprintf(allfile, " Opcode: %s", owl_message_get_opcode(m));
233      fprintf(allfile, "\n");
234      fprintf(allfile, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m));
235      fprintf(allfile, "From: %s <%s>\n\n", buff, tmp);
[269ed34]236      fprintf(allfile, "%s\n\n", owl_message_get_body(m));
[e6449bc]237      owl_free(tmp);
[79a0e82]238    } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) {
239      fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
240      fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m));
241      fprintf(allfile, "%s\n\n", owl_message_get_body(m));
242    } else if (owl_message_is_type_aim(m) && owl_message_is_loginout(m)) {
243      fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m));
244      fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m));
245      if (owl_message_is_login(m)) fprintf(allfile, "LOGIN\n\n");
246      if (owl_message_is_logout(m)) fprintf(allfile, "LOGOUT\n\n");
[aac889a]247    }
[723c427]248    fclose(allfile);
[7d4fbcd]249  }
250
[aac889a]251  if (owl_message_is_type_zephyr(m)) {
252    owl_free(buff);
253  }
[7d4fbcd]254  owl_free(frombuff);
255}
Note: See TracBrowser for help on using the repository browser.