- Timestamp:
- Jan 4, 2005, 11:04:52 PM (20 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 180cd15
- Parents:
- 95474d7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
logging.c
rdebb15d r15b34fd 7 7 static const char fileIdent[] = "$Id$"; 8 8 9 void owl_log_outgoing_zephyr(char *to, char *text) 9 /* This is now the one function that should be called to log a 10 * message. It will do all the work necessary by calling the other 11 * functions in this file as necessary. 12 */ 13 void owl_log_message(owl_message *m) { 14 owl_function_debugmsg("owl_log_message: entering"); 15 16 /* should we be logging this message? */ 17 if (!owl_log_shouldlog_message(m)) { 18 owl_function_debugmsg("owl_log_message: not logging message"); 19 return; 20 } 21 22 /* handle incmoing messages */ 23 if (owl_message_is_direction_in(m)) { 24 owl_log_incoming(m); 25 owl_function_debugmsg("owl_log_message: leaving"); 26 return; 27 } 28 29 /* handle outgoing messages */ 30 if (owl_message_is_type_aim(m)) { 31 owl_log_outgoing_aim(m); 32 } else if (owl_message_is_type_zephyr(m)) { 33 owl_log_outgoing_zephyr(m); 34 } else if (owl_message_is_type_loopback(m)) { 35 owl_log_outgoing_loopback(m); 36 } else { 37 owl_function_error("Unknown message type for logging"); 38 } 39 owl_function_debugmsg("owl_log_message: leaving"); 40 } 41 42 /* Return 1 if we should log the given message, otherwise return 0 */ 43 int owl_log_shouldlog_message(owl_message *m) { 44 owl_filter *f; 45 46 /* If there's a logfilter and this message matches it, log */ 47 f=owl_global_get_filter(&g, owl_global_get_logfilter(&g)); 48 if (f && owl_filter_message_match(f, m)) return(1); 49 50 /* otherwise we do things based on the logging variables */ 51 52 /* skip login/logout messages if appropriate */ 53 if (!owl_global_is_loglogins(&g) && owl_message_is_loginout(m)) return(0); 54 55 /* check for nolog */ 56 if (!strcasecmp(owl_message_get_opcode(m), "nolog") || !strcasecmp(owl_message_get_instance(m), "nolog")) return(0); 57 58 /* check direction */ 59 if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) && owl_message_is_direction_out(m)) { 60 return(0); 61 } 62 if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) && owl_message_is_direction_in(m)) { 63 return(0); 64 } 65 66 if (owl_message_is_type_zephyr(m)) { 67 if (owl_message_is_personal(m) && !owl_global_is_logging(&g)) return(0); 68 if (!owl_message_is_personal(m) && !owl_global_is_classlogging(&g)) return(0); 69 } else { 70 if (owl_message_is_private(m) || owl_message_is_loginout(m)) { 71 if (!owl_global_is_logging(&g)) return(0); 72 } else { 73 if (!owl_global_is_classlogging(&g)) return(0); 74 } 75 } 76 return(1); 77 } 78 79 void owl_log_outgoing_zephyr(owl_message *m) 10 80 { 11 81 FILE *file; 12 82 char filename[MAXPATHLEN], *logpath; 13 char *tobuff, *ptr=""; 14 15 if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) return; 16 17 tobuff=owl_malloc(strlen(to)+20); 18 strcpy(tobuff, to); 19 20 /* chop off a local realm */ 21 ptr=strchr(tobuff, '@'); 22 if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) { 23 *ptr='\0'; 24 } 83 char *to, *text; 84 85 /* strip local realm */ 86 to=short_zuser(owl_message_get_recipient(m)); 25 87 26 88 /* expand ~ in path names */ 27 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 28 owl_global_get_homedir(&g)); 29 30 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); 89 logpath=owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); 90 91 text=owl_message_get_body(m); 92 93 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, to); 31 94 file=fopen(filename, "a"); 32 95 if (!file) { 33 96 owl_function_error("Unable to open file for outgoing logging"); 34 97 owl_free(logpath); 35 return; 36 } 37 fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); 98 owl_free(to); 99 return; 100 } 101 fprintf(file, "OUTGOING (owl): %s\n%s\n", to, text); 38 102 if (text[strlen(text)-1]!='\n') { 39 103 fprintf(file, "\n"); … … 46 110 if (!file) { 47 111 owl_function_error("Unable to open file for outgoing logging"); 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); 112 owl_free(to); 113 return; 114 } 115 fprintf(file, "OUTGOING (owl): %s\n%s\n", to, text); 116 if (text[strlen(text)-1]!='\n') { 117 fprintf(file, "\n"); 118 } 119 fclose(file); 120 121 owl_free(to); 57 122 } 58 123 … … 61 126 FILE *file; 62 127 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 } 128 char *tobuff; 129 130 tobuff=short_zuser(to); 73 131 74 132 /* expand ~ in path names */ 75 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 76 owl_global_get_homedir(&g)); 133 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); 77 134 78 135 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); … … 81 138 owl_function_error("Unable to open file for outgoing logging"); 82 139 owl_free(logpath); 140 owl_free(tobuff); 83 141 return; 84 142 } … … 94 152 if (!file) { 95 153 owl_function_error("Unable to open file for outgoing logging"); 154 owl_free(tobuff); 96 155 return; 97 156 } … … 105 164 } 106 165 107 void owl_log_outgoing_aim( char *to, char *text)166 void owl_log_outgoing_aim(owl_message *m) 108 167 { 109 168 FILE *file; 110 169 char filename[MAXPATHLEN], *logpath; 111 char *tobuff, *normalto; 112 113 if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) return; 114 115 normalto=owl_aim_normalize_screenname(to); 170 char *tobuff, *normalto, *text; 171 172 owl_function_debugmsg("owl_log_outgoing_aim: entering"); 173 174 /* normalize and downcase the screenname */ 175 normalto=owl_aim_normalize_screenname(owl_message_get_recipient(m)); 116 176 downstr(normalto); 117 177 tobuff=owl_sprintf("aim:%s", normalto); … … 119 179 120 180 /* expand ~ in path names */ 121 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 122 owl_global_get_homedir(&g)); 123 181 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); 182 183 text=owl_message_get_body(m); 184 124 185 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); 125 186 file=fopen(filename, "a"); … … 127 188 owl_function_error("Unable to open file for outgoing logging"); 128 189 owl_free(logpath); 190 owl_free(tobuff); 129 191 return; 130 192 } … … 140 202 if (!file) { 141 203 owl_function_error("Unable to open file for outgoing logging"); 204 owl_free(tobuff); 142 205 return; 143 206 } … … 151 214 } 152 215 153 void owl_log_outgoing_loopback( char *text)216 void owl_log_outgoing_loopback(owl_message *m) 154 217 { 155 218 FILE *file; 156 219 char filename[MAXPATHLEN], *logpath; 157 char *tobuff; 158 159 if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) return; 220 char *tobuff, *text; 160 221 161 222 tobuff=owl_sprintf("loopback"); 162 223 163 224 /* expand ~ in path names */ 164 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 165 owl_global_get_homedir(&g)); 225 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); 226 227 text=owl_message_get_body(m); 166 228 167 229 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); … … 170 232 owl_function_error("Unable to open file for outgoing logging"); 171 233 owl_free(logpath); 234 owl_free(tobuff); 172 235 return; 173 236 } … … 183 246 if (!file) { 184 247 owl_function_error("Unable to open file for outgoing logging"); 248 owl_free(tobuff); 185 249 return; 186 250 } … … 201 265 int len, ch, i, personal; 202 266 203 if (owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) return; 204 205 /* skip login/logout messages if appropriate */ 206 if (!owl_global_is_loglogins(&g) && owl_message_is_loginout(m)) return; 207 208 /* check for nolog */ 209 if (!strcasecmp(owl_message_get_opcode(m), "nolog") || 210 !strcasecmp(owl_message_get_instance(m), "nolog")) return; 211 212 /* this is kind of a mess */ 267 /* figure out if it's a "personal" message or not */ 213 268 if (owl_message_is_type_zephyr(m)) { 214 269 if (owl_message_is_personal(m)) { 215 270 personal=1; 216 if (!owl_global_is_logging(&g)) return;217 271 } else { 218 272 personal=0; 219 if (!owl_global_is_classlogging(&g)) return;220 273 } 221 274 } else { 222 275 if (owl_message_is_private(m) || owl_message_is_loginout(m)) { 223 276 personal=1; 224 if (!owl_global_is_logging(&g)) return;225 277 } else { 226 278 personal=0; 227 if (!owl_global_is_classlogging(&g)) return;228 279 } 229 280 } 230 281 231 282 if (owl_message_is_type_zephyr(m)) { 232 /* chop off a local realm for personal zephyr messages */233 283 if (personal) { 234 284 if (owl_message_is_type_zephyr(m)) { 235 from=frombuff=owl_strdup(owl_message_get_sender(m)); 236 ptr=strchr(frombuff, '@'); 237 if (ptr && !strncmp(ptr+1, owl_zephyr_get_realm(), strlen(owl_zephyr_get_realm()))) { 238 *ptr='\0'; 239 } 285 from=frombuff=short_zuser(owl_message_get_sender(m)); 240 286 } 241 287 } else { 242 /* we assume zephyr for now */243 288 from=frombuff=owl_strdup(owl_message_get_class(m)); 244 289 } … … 276 321 /* create the filename (expanding ~ in path names) */ 277 322 if (personal) { 278 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", 279 owl_global_get_homedir(&g)); 323 logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); 280 324 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from); 281 325 snprintf(allfilename, MAXPATHLEN, "%s/all", logpath); 282 326 283 327 } else { 284 logpath = owl_text_substitute(owl_global_get_classlogpath(&g), "~", 285 owl_global_get_homedir(&g)); 286 328 logpath = owl_text_substitute(owl_global_get_classlogpath(&g), "~", owl_global_get_homedir(&g)); 287 329 snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from); 288 330 } … … 292 334 if (!file) { 293 335 owl_function_error("Unable to open file for incoming logging"); 336 owl_free(frombuff); 294 337 return; 295 338 } … … 300 343 if (!allfile) { 301 344 owl_function_error("Unable to open file for incoming logging"); 345 owl_free(frombuff); 302 346 fclose(file); 303 347 return;
Note: See TracChangeset
for help on using the changeset viewer.