[7d4fbcd] | 1 | #include <zephyr/zephyr.h> |
---|
| 2 | #include <stdlib.h> |
---|
[b45293f] | 3 | #include <unistd.h> |
---|
[7d4fbcd] | 4 | #include <string.h> |
---|
| 5 | #include <sys/socket.h> |
---|
| 6 | #include <netdb.h> |
---|
| 7 | #include <sys/types.h> |
---|
| 8 | #include <sys/socket.h> |
---|
| 9 | #include <netinet/in.h> |
---|
| 10 | #include <arpa/inet.h> |
---|
| 11 | #include <time.h> |
---|
| 12 | #include "owl.h" |
---|
| 13 | |
---|
[1aee7d9] | 14 | static const char fileIdent[] = "$Id$"; |
---|
| 15 | |
---|
[d0d65df] | 16 | void owl_message_init(owl_message *m) { |
---|
[7d4fbcd] | 17 | time_t t; |
---|
| 18 | |
---|
| 19 | m->id=owl_global_get_nextmsgid(&g); |
---|
[4b464a4] | 20 | m->type=OWL_MESSAGE_TYPE_GENERIC; |
---|
| 21 | owl_message_set_direction_none(m); |
---|
[7d4fbcd] | 22 | m->delete=0; |
---|
| 23 | strcpy(m->hostname, ""); |
---|
| 24 | m->zwriteline=strdup(""); |
---|
| 25 | |
---|
[d0d65df] | 26 | owl_list_create(&(m->attributes)); |
---|
| 27 | |
---|
[7d4fbcd] | 28 | /* save the time */ |
---|
| 29 | t=time(NULL); |
---|
| 30 | m->time=owl_strdup(ctime(&t)); |
---|
| 31 | m->time[strlen(m->time)-1]='\0'; |
---|
[4b464a4] | 32 | } |
---|
| 33 | |
---|
[d0d65df] | 34 | void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue) { |
---|
| 35 | /* add the named attribute to the message. If an attribute with the |
---|
| 36 | name already exists, replace the old value with the new value */ |
---|
| 37 | |
---|
| 38 | int i, j; |
---|
| 39 | owl_pair *p; |
---|
| 40 | |
---|
| 41 | /* look for an existing pair with this key, and nuke the entry if |
---|
| 42 | found */ |
---|
| 43 | j=owl_list_get_size(&(m->attributes)); |
---|
| 44 | for (i=0; i<j; i++) { |
---|
| 45 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 46 | if (!strcmp(owl_pair_get_key(p), attrname)) { |
---|
| 47 | owl_free(owl_pair_get_key(p)); |
---|
| 48 | owl_free(owl_pair_get_value(p)); |
---|
| 49 | owl_free(p); |
---|
| 50 | owl_list_remove_element(&(m->attributes), i); |
---|
| 51 | break; |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | p=owl_malloc(sizeof(owl_pair)); |
---|
| 56 | owl_pair_create(p, owl_strdup(attrname), owl_strdup(attrvalue)); |
---|
| 57 | owl_list_append_element(&(m->attributes), p); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | char *owl_message_get_attribute_value(owl_message *m, char *attrname) { |
---|
| 61 | /* return the value associated with the named attribute, or NULL if |
---|
| 62 | the attribute does not exist */ |
---|
| 63 | int i, j; |
---|
| 64 | owl_pair *p; |
---|
| 65 | |
---|
| 66 | j=owl_list_get_size(&(m->attributes)); |
---|
| 67 | for (i=0; i<j; i++) { |
---|
| 68 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 69 | if (!strcmp(owl_pair_get_key(p), attrname)) { |
---|
| 70 | return(owl_pair_get_value(p)); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | owl_function_debugmsg("No attribute %s found", attrname); |
---|
| 74 | return(NULL); |
---|
| 75 | } |
---|
| 76 | |
---|
[4b464a4] | 77 | |
---|
| 78 | owl_fmtext *owl_message_get_fmtext(owl_message *m) { |
---|
| 79 | return(&(m->fmtext)); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void owl_message_set_class(owl_message *m, char *class) { |
---|
[d0d65df] | 83 | owl_message_set_attribute(m, "class", class); |
---|
[4b464a4] | 84 | } |
---|
| 85 | |
---|
| 86 | char *owl_message_get_class(owl_message *m) { |
---|
[d0d65df] | 87 | char *class; |
---|
| 88 | |
---|
| 89 | class=owl_message_get_attribute_value(m, "class"); |
---|
| 90 | if (!class) return(""); |
---|
| 91 | return(class); |
---|
[4b464a4] | 92 | } |
---|
| 93 | |
---|
| 94 | void owl_message_set_instance(owl_message *m, char *inst) { |
---|
[d0d65df] | 95 | owl_message_set_attribute(m, "instance", inst); |
---|
[4b464a4] | 96 | } |
---|
| 97 | |
---|
| 98 | char *owl_message_get_instance(owl_message *m) { |
---|
[d0d65df] | 99 | char *instance; |
---|
| 100 | |
---|
| 101 | instance=owl_message_get_attribute_value(m, "instance"); |
---|
| 102 | if (!instance) return(""); |
---|
| 103 | return(instance); |
---|
[4b464a4] | 104 | } |
---|
| 105 | |
---|
| 106 | void owl_message_set_sender(owl_message *m, char *sender) { |
---|
[d0d65df] | 107 | owl_message_set_attribute(m, "sender", sender); |
---|
[4b464a4] | 108 | } |
---|
| 109 | |
---|
| 110 | char *owl_message_get_sender(owl_message *m) { |
---|
[d0d65df] | 111 | char *sender; |
---|
| 112 | |
---|
| 113 | sender=owl_message_get_attribute_value(m, "sender"); |
---|
| 114 | if (!sender) return(""); |
---|
| 115 | return(sender); |
---|
[4b464a4] | 116 | } |
---|
| 117 | |
---|
[b45293f] | 118 | void owl_message_set_zsig(owl_message *m, char *zsig) { |
---|
[d0d65df] | 119 | owl_message_set_attribute(m, "zsig", zsig); |
---|
[b45293f] | 120 | } |
---|
| 121 | |
---|
| 122 | char *owl_message_get_zsig(owl_message *m) { |
---|
[d0d65df] | 123 | char *zsig; |
---|
| 124 | |
---|
| 125 | zsig=owl_message_get_attribute_value(m, "zsig"); |
---|
| 126 | if (!zsig) return(""); |
---|
| 127 | return(zsig); |
---|
[b45293f] | 128 | } |
---|
| 129 | |
---|
[4b464a4] | 130 | void owl_message_set_recipient(owl_message *m, char *recip) { |
---|
[d0d65df] | 131 | owl_message_set_attribute(m, "recipient", recip); |
---|
[4b464a4] | 132 | } |
---|
| 133 | |
---|
| 134 | char *owl_message_get_recipient(owl_message *m) { |
---|
| 135 | /* this is stupid for outgoing messages, we need to fix it. */ |
---|
[d0d65df] | 136 | |
---|
| 137 | char *recip; |
---|
[4b464a4] | 138 | |
---|
| 139 | if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) { |
---|
[d0d65df] | 140 | recip=owl_message_get_attribute_value(m, "recipient"); |
---|
[4b464a4] | 141 | } else if (owl_message_is_direction_out(m)) { |
---|
[d0d65df] | 142 | recip=m->zwriteline; |
---|
[4b464a4] | 143 | } else { |
---|
[d0d65df] | 144 | recip=owl_message_get_attribute_value(m, "recipient"); |
---|
[4b464a4] | 145 | } |
---|
[d0d65df] | 146 | if (!recip) return(""); |
---|
| 147 | return(recip); |
---|
[4b464a4] | 148 | } |
---|
| 149 | |
---|
| 150 | void owl_message_set_realm(owl_message *m, char *realm) { |
---|
[d0d65df] | 151 | owl_message_set_attribute(m, "realm", realm); |
---|
[4b464a4] | 152 | } |
---|
| 153 | |
---|
| 154 | char *owl_message_get_realm(owl_message *m) { |
---|
[d0d65df] | 155 | char *realm; |
---|
| 156 | |
---|
| 157 | realm=owl_message_get_attribute_value(m, "realm"); |
---|
| 158 | if (!realm) return(""); |
---|
| 159 | return(realm); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void owl_message_set_body(owl_message *m, char *body) { |
---|
| 163 | owl_message_set_attribute(m, "body", body); |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | char *owl_message_get_body(owl_message *m) { |
---|
| 167 | char *body; |
---|
| 168 | |
---|
| 169 | body=owl_message_get_attribute_value(m, "body"); |
---|
| 170 | if (!body) return(""); |
---|
| 171 | return(body); |
---|
[4b464a4] | 172 | } |
---|
| 173 | |
---|
[d0d65df] | 174 | |
---|
[4b464a4] | 175 | void owl_message_set_opcode(owl_message *m, char *opcode) { |
---|
[d0d65df] | 176 | owl_message_set_attribute(m, "opcode", opcode); |
---|
[4b464a4] | 177 | } |
---|
| 178 | |
---|
| 179 | char *owl_message_get_opcode(owl_message *m) { |
---|
[d0d65df] | 180 | char *opcode; |
---|
| 181 | |
---|
| 182 | opcode=owl_message_get_attribute_value(m, "opcode"); |
---|
| 183 | if (!opcode) return(""); |
---|
| 184 | return(opcode); |
---|
[4b464a4] | 185 | } |
---|
| 186 | |
---|
| 187 | char *owl_message_get_timestr(owl_message *m) { |
---|
| 188 | return(m->time); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | void owl_message_set_type_admin(owl_message *m) { |
---|
| 192 | m->type=OWL_MESSAGE_TYPE_ADMIN; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void owl_message_set_type_zephyr(owl_message *m) { |
---|
| 196 | m->type=OWL_MESSAGE_TYPE_ZEPHYR; |
---|
| 197 | } |
---|
[d09e5a1] | 198 | |
---|
| 199 | void owl_message_set_type_aim(owl_message *m) { |
---|
| 200 | m->type=OWL_MESSAGE_TYPE_AIM; |
---|
| 201 | } |
---|
[4b464a4] | 202 | |
---|
| 203 | int owl_message_is_type_admin(owl_message *m) { |
---|
| 204 | if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1); |
---|
| 205 | return(0); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | int owl_message_is_type_zephyr(owl_message *m) { |
---|
| 209 | if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1); |
---|
| 210 | return(0); |
---|
| 211 | } |
---|
| 212 | |
---|
[d09e5a1] | 213 | int owl_message_is_type_aim(owl_message *m) { |
---|
| 214 | if (m->type==OWL_MESSAGE_TYPE_AIM) return(1); |
---|
| 215 | return(0); |
---|
| 216 | } |
---|
| 217 | |
---|
[4b464a4] | 218 | int owl_message_is_type_generic(owl_message *m) { |
---|
| 219 | if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1); |
---|
| 220 | return(0); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | char *owl_message_get_text(owl_message *m) { |
---|
| 224 | return(owl_fmtext_get_text(&(m->fmtext))); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | void owl_message_set_direction_in(owl_message *m) { |
---|
| 228 | m->direction=OWL_MESSAGE_DIRECTION_IN; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | void owl_message_set_direction_out(owl_message *m) { |
---|
| 232 | m->direction=OWL_MESSAGE_DIRECTION_OUT; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | void owl_message_set_direction_none(owl_message *m) { |
---|
| 236 | m->direction=OWL_MESSAGE_DIRECTION_NONE; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | int owl_message_is_direction_in(owl_message *m) { |
---|
| 240 | if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1); |
---|
| 241 | return(0); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | int owl_message_is_direction_out(owl_message *m) { |
---|
| 245 | if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1); |
---|
| 246 | return(0); |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | int owl_message_is_direction_none(owl_message *m) { |
---|
| 250 | if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1); |
---|
| 251 | return(0); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | int owl_message_get_numlines(owl_message *m) { |
---|
| 255 | if (m == NULL) return(0); |
---|
| 256 | return(owl_fmtext_num_lines(&(m->fmtext))); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | void owl_message_mark_delete(owl_message *m) { |
---|
| 260 | if (m == NULL) return; |
---|
| 261 | m->delete=1; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | void owl_message_unmark_delete(owl_message *m) { |
---|
| 265 | if (m == NULL) return; |
---|
| 266 | m->delete=0; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | char *owl_message_get_zwriteline(owl_message *m) { |
---|
| 270 | return(m->zwriteline); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | void owl_message_set_zwriteline(owl_message *m, char *line) { |
---|
| 274 | m->zwriteline=strdup(line); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | int owl_message_is_delete(owl_message *m) { |
---|
| 278 | if (m == NULL) return(0); |
---|
| 279 | if (m->delete==1) return(1); |
---|
| 280 | return(0); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | ZNotice_t *owl_message_get_notice(owl_message *m) { |
---|
| 284 | return(&(m->notice)); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | char *owl_message_get_hostname(owl_message *m) { |
---|
| 288 | return(m->hostname); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) { |
---|
| 293 | owl_fmtext a, b; |
---|
| 294 | |
---|
[af2ca19] | 295 | owl_fmtext_init_null(&a); |
---|
| 296 | owl_fmtext_init_null(&b); |
---|
| 297 | |
---|
[4b464a4] | 298 | owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a); |
---|
| 299 | owl_fmtext_truncate_cols(&a, acol, bcol, &b); |
---|
| 300 | if (color!=OWL_COLOR_DEFAULT) { |
---|
| 301 | owl_fmtext_colorize(&b, color); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | if (owl_global_is_search_active(&g)) { |
---|
| 305 | owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g)); |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | owl_fmtext_curs_waddstr(&b, win); |
---|
| 309 | |
---|
| 310 | owl_fmtext_free(&a); |
---|
| 311 | owl_fmtext_free(&b); |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | int owl_message_is_personal(owl_message *m) { |
---|
| 315 | if (strcasecmp(owl_message_get_class(m), "message")) return(0); |
---|
| 316 | if (strcasecmp(owl_message_get_instance(m), "personal")) return(0); |
---|
[a2641cd9] | 317 | if (!strcasecmp(owl_message_get_recipient(m), ZGetSender()) || |
---|
| 318 | !strcasecmp(owl_message_get_sender(m), ZGetSender())) { |
---|
[4b464a4] | 319 | return(1); |
---|
| 320 | } |
---|
| 321 | return(0); |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | int owl_message_is_private(owl_message *m) { |
---|
[a2641cd9] | 325 | if (!strcasecmp(owl_message_get_recipient(m), ZGetSender())) return(1); |
---|
[4b464a4] | 326 | return(0); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | int owl_message_is_mail(owl_message *m) { |
---|
| 330 | if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) { |
---|
| 331 | return(1); |
---|
| 332 | } |
---|
| 333 | return(0); |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | int owl_message_is_ping(owl_message *m) { |
---|
| 337 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1); |
---|
| 338 | return(0); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | int owl_message_is_login(owl_message *m) { |
---|
| 342 | if (!strcasecmp(owl_message_get_class(m), "login")) return(1); |
---|
| 343 | return(0); |
---|
| 344 | /* is this good enough? */ |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | int owl_message_is_burningears(owl_message *m) { |
---|
| 348 | /* we should add a global to cache the short zsender */ |
---|
| 349 | char sender[LINE], *ptr; |
---|
| 350 | |
---|
| 351 | /* if the message is from us or to us, it doesn't count */ |
---|
| 352 | if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0); |
---|
| 353 | if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0); |
---|
| 354 | |
---|
| 355 | strcpy(sender, ZGetSender()); |
---|
| 356 | ptr=strchr(sender, '@'); |
---|
| 357 | if (ptr) *ptr='\0'; |
---|
| 358 | |
---|
| 359 | if (stristr(owl_message_get_body(m), sender)) { |
---|
| 360 | return(1); |
---|
| 361 | } |
---|
| 362 | return(0); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /* caller must free return value. */ |
---|
| 366 | char *owl_message_get_cc(owl_message *m) { |
---|
| 367 | char *cur, *out, *end; |
---|
| 368 | |
---|
| 369 | cur = owl_message_get_body(m); |
---|
| 370 | while (*cur && *cur==' ') cur++; |
---|
[985f85b] | 371 | if (strncasecmp(cur, "cc:", 3)) return(NULL); |
---|
[4b464a4] | 372 | cur+=3; |
---|
| 373 | while (*cur && *cur==' ') cur++; |
---|
| 374 | out = owl_strdup(cur); |
---|
| 375 | end = strchr(out, '\n'); |
---|
| 376 | if (end) end[0] = '\0'; |
---|
| 377 | return(out); |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | int owl_message_get_id(owl_message *m) { |
---|
| 381 | return(m->id); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | int owl_message_search(owl_message *m, char *string) { |
---|
| 385 | /* return 1 if the message contains "string", 0 otherwise. This is |
---|
| 386 | * case insensitive because the functions it uses are */ |
---|
| 387 | |
---|
| 388 | return (owl_fmtext_search(&(m->fmtext), string)); |
---|
| 389 | } |
---|
| 390 | |
---|
| 391 | void owl_message_create(owl_message *m, char *header, char *text) { |
---|
| 392 | char *indent; |
---|
| 393 | |
---|
[d0d65df] | 394 | owl_message_init(m); |
---|
| 395 | owl_message_set_body(m, text); |
---|
[4b464a4] | 396 | |
---|
| 397 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 398 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 399 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 400 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 401 | owl_fmtext_append_ztext(&(m->fmtext), header); |
---|
| 402 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 403 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 404 | if (text[strlen(text)-1]!='\n') { |
---|
| 405 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | owl_free(indent); |
---|
| 409 | } |
---|
| 410 | |
---|
[440ce01] | 411 | void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text) { |
---|
[d09e5a1] | 412 | char *indent; |
---|
| 413 | |
---|
| 414 | owl_message_init(m); |
---|
| 415 | owl_message_set_body(m, text); |
---|
| 416 | owl_message_set_sender(m, sender); |
---|
[440ce01] | 417 | owl_message_set_recipient(m, recipient); |
---|
[d09e5a1] | 418 | owl_message_set_type_aim(m); |
---|
| 419 | |
---|
| 420 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 421 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 422 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 423 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 424 | owl_fmtext_append_normal(&(m->fmtext), "AIM: "); |
---|
| 425 | owl_fmtext_append_normal(&(m->fmtext), sender); |
---|
[440ce01] | 426 | owl_fmtext_append_normal(&(m->fmtext), " -> "); |
---|
| 427 | owl_fmtext_append_normal(&(m->fmtext), recipient); |
---|
[d09e5a1] | 428 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 429 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 430 | if (text[strlen(text)-1]!='\n') { |
---|
| 431 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | owl_free(indent); |
---|
| 435 | } |
---|
| 436 | |
---|
[4b464a4] | 437 | void owl_message_create_admin(owl_message *m, char *header, char *text) { |
---|
| 438 | char *indent; |
---|
| 439 | |
---|
[d0d65df] | 440 | owl_message_init(m); |
---|
[4b464a4] | 441 | owl_message_set_type_admin(m); |
---|
[7d4fbcd] | 442 | |
---|
[d0d65df] | 443 | owl_message_set_body(m, text); |
---|
[7d4fbcd] | 444 | |
---|
| 445 | /* do something to make it clear the notice shouldn't be used for now */ |
---|
| 446 | |
---|
| 447 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 448 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 449 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 450 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 451 | owl_fmtext_append_bold(&(m->fmtext), "OWL ADMIN "); |
---|
| 452 | owl_fmtext_append_ztext(&(m->fmtext), header); |
---|
| 453 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 454 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 455 | if (text[strlen(text)-1]!='\n') { |
---|
| 456 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | owl_free(indent); |
---|
| 460 | } |
---|
| 461 | |
---|
[b45293f] | 462 | void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) { |
---|
[7d4fbcd] | 463 | struct hostent *hent; |
---|
[c269e22] | 464 | int k; |
---|
[d0d65df] | 465 | char *ptr, *tmp, *tmp2; |
---|
[7d4fbcd] | 466 | |
---|
[d0d65df] | 467 | owl_message_init(m); |
---|
| 468 | |
---|
[4b464a4] | 469 | owl_message_set_type_zephyr(m); |
---|
| 470 | owl_message_set_direction_in(m); |
---|
[7d4fbcd] | 471 | |
---|
| 472 | /* first save the full notice */ |
---|
| 473 | memcpy(&(m->notice), n, sizeof(ZNotice_t)); |
---|
| 474 | |
---|
| 475 | /* a little gross, we'll reaplace \r's with ' ' for now */ |
---|
| 476 | owl_zephyr_hackaway_cr(&(m->notice)); |
---|
| 477 | |
---|
| 478 | m->delete=0; |
---|
| 479 | |
---|
| 480 | /* set other info */ |
---|
[d0d65df] | 481 | owl_message_set_sender(m, n->z_sender); |
---|
| 482 | owl_message_set_class(m, n->z_class); |
---|
| 483 | owl_message_set_instance(m, n->z_class_inst); |
---|
| 484 | owl_message_set_recipient(m, n->z_recipient); |
---|
[7d4fbcd] | 485 | if (n->z_opcode) { |
---|
[d0d65df] | 486 | owl_message_set_opcode(m, n->z_opcode); |
---|
[7d4fbcd] | 487 | } else { |
---|
[d0d65df] | 488 | owl_message_set_opcode(m, ""); |
---|
[7d4fbcd] | 489 | } |
---|
[d0d65df] | 490 | owl_message_set_zsig(m, n->z_message); |
---|
[7d4fbcd] | 491 | |
---|
| 492 | if ((ptr=strchr(n->z_recipient, '@'))!=NULL) { |
---|
[d0d65df] | 493 | owl_message_set_realm(m, ptr+1); |
---|
[7d4fbcd] | 494 | } else { |
---|
[d0d65df] | 495 | owl_message_set_realm(m, ZGetRealm()); |
---|
[7d4fbcd] | 496 | } |
---|
| 497 | |
---|
| 498 | m->zwriteline=strdup(""); |
---|
| 499 | |
---|
[b45293f] | 500 | /* set the body */ |
---|
[7d4fbcd] | 501 | ptr=owl_zephyr_get_message(n, &k); |
---|
[7e3e00a] | 502 | tmp=owl_malloc(k+10); |
---|
| 503 | memcpy(tmp, ptr, k); |
---|
| 504 | tmp[k]='\0'; |
---|
| 505 | if (owl_global_is_newlinestrip(&g)) { |
---|
[d0d65df] | 506 | tmp2=owl_util_stripnewlines(tmp); |
---|
| 507 | owl_message_set_body(m, tmp2); |
---|
| 508 | owl_free(tmp2); |
---|
[7e3e00a] | 509 | } else { |
---|
[d0d65df] | 510 | owl_message_set_body(m, tmp); |
---|
[7e3e00a] | 511 | } |
---|
[ecd5dc5] | 512 | owl_free(tmp); |
---|
[7d4fbcd] | 513 | |
---|
[c86a35c] | 514 | #ifdef OWL_ENABLE_ZCRYPT |
---|
[d309eb3] | 515 | /* if zcrypt is enabled try to decrypt the message */ |
---|
| 516 | if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) { |
---|
| 517 | char *out; |
---|
[c269e22] | 518 | int ret; |
---|
[d309eb3] | 519 | |
---|
[d0d65df] | 520 | out=owl_malloc(strlen(owl_message_get_body(m))*16+20); |
---|
| 521 | ret=zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m)); |
---|
[a15a84f] | 522 | if (ret==0) { |
---|
[d0d65df] | 523 | owl_message_set_body(m, out); |
---|
[a15a84f] | 524 | } else { |
---|
| 525 | owl_free(out); |
---|
| 526 | } |
---|
[d309eb3] | 527 | } |
---|
[c269e22] | 528 | #endif |
---|
[d309eb3] | 529 | |
---|
[7d4fbcd] | 530 | /* save the hostname */ |
---|
[3a2daac] | 531 | owl_function_debugmsg("About to do gethostbyaddr"); |
---|
[7d4fbcd] | 532 | hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); |
---|
| 533 | if (hent && hent->h_name) { |
---|
| 534 | strcpy(m->hostname, hent->h_name); |
---|
| 535 | } else { |
---|
| 536 | strcpy(m->hostname, inet_ntoa(n->z_sender_addr)); |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | /* save the time */ |
---|
| 540 | m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec)); |
---|
| 541 | m->time[strlen(m->time)-1]='\0'; |
---|
| 542 | |
---|
| 543 | /* create the formatted message */ |
---|
| 544 | if (owl_global_is_config_format(&g)) { |
---|
| 545 | _owl_message_make_text_from_config(m); |
---|
| 546 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 547 | _owl_message_make_text_from_notice_standard(m); |
---|
| 548 | } else { |
---|
| 549 | _owl_message_make_text_from_notice_simple(m); |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | } |
---|
| 553 | |
---|
[b45293f] | 554 | void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) { |
---|
| 555 | owl_zwrite z; |
---|
| 556 | int ret; |
---|
| 557 | |
---|
[d0d65df] | 558 | owl_message_init(m); |
---|
[b45293f] | 559 | |
---|
| 560 | /* create a zwrite for the purpose of filling in other message fields */ |
---|
| 561 | owl_zwrite_create_from_line(&z, line); |
---|
| 562 | |
---|
| 563 | /* set things */ |
---|
| 564 | owl_message_set_direction_out(m); |
---|
| 565 | owl_message_set_type_zephyr(m); |
---|
[8fec514] | 566 | owl_message_set_sender(m, ZGetSender()); |
---|
| 567 | owl_message_set_class(m, owl_zwrite_get_class(&z)); |
---|
| 568 | owl_message_set_instance(m, owl_zwrite_get_instance(&z)); |
---|
[d0d65df] | 569 | owl_message_set_recipient(m, |
---|
| 570 | long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */ |
---|
[8fec514] | 571 | owl_message_set_opcode(m, owl_zwrite_get_opcode(&z)); |
---|
[d0d65df] | 572 | owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */ |
---|
[b45293f] | 573 | m->zwriteline=owl_strdup(line); |
---|
[d0d65df] | 574 | owl_message_set_body(m, body); |
---|
[8fec514] | 575 | owl_message_set_zsig(m, zsig); |
---|
[b45293f] | 576 | |
---|
| 577 | /* save the hostname */ |
---|
| 578 | ret=gethostname(m->hostname, MAXHOSTNAMELEN); |
---|
| 579 | if (ret) { |
---|
| 580 | strcpy(m->hostname, "localhost"); |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | /* create the formatted message */ |
---|
| 584 | if (owl_global_is_config_format(&g)) { |
---|
| 585 | _owl_message_make_text_from_config(m); |
---|
| 586 | } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 587 | _owl_message_make_text_from_zwriteline_standard(m); |
---|
| 588 | } else { |
---|
| 589 | _owl_message_make_text_from_zwriteline_simple(m); |
---|
| 590 | } |
---|
| 591 | |
---|
| 592 | owl_zwrite_free(&z); |
---|
| 593 | } |
---|
[7d4fbcd] | 594 | |
---|
| 595 | void _owl_message_make_text_from_config(owl_message *m) { |
---|
| 596 | char *body, *indent; |
---|
[d0d65df] | 597 | |
---|
[7d4fbcd] | 598 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 599 | |
---|
| 600 | /* get body from the config */ |
---|
| 601 | body=owl_config_getmsg(m, 1); |
---|
| 602 | |
---|
| 603 | /* indent */ |
---|
| 604 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10); |
---|
| 605 | owl_text_indent(indent, body, OWL_TAB); |
---|
| 606 | |
---|
| 607 | /* fmtext_append. This needs to change */ |
---|
| 608 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 609 | |
---|
| 610 | owl_free(indent); |
---|
| 611 | owl_free(body); |
---|
| 612 | } |
---|
| 613 | |
---|
[b45293f] | 614 | void _owl_message_make_text_from_zwriteline_standard(owl_message *m) { |
---|
[be97670] | 615 | char *indent, *text, *zsigbuff, *foo; |
---|
[b45293f] | 616 | |
---|
| 617 | text=owl_message_get_body(m); |
---|
| 618 | |
---|
| 619 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 620 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 621 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 622 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 623 | owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to "); |
---|
[be97670] | 624 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
| 625 | owl_fmtext_append_normal(&(m->fmtext), foo); |
---|
| 626 | owl_free(foo); |
---|
[b45293f] | 627 | owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); |
---|
| 628 | |
---|
[8fec514] | 629 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 630 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 631 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 632 | owl_free(zsigbuff); |
---|
| 633 | |
---|
| 634 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
| 635 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 636 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 637 | if (text[strlen(text)-1]!='\n') { |
---|
| 638 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | owl_free(indent); |
---|
| 642 | } |
---|
| 643 | |
---|
| 644 | void _owl_message_make_text_from_zwriteline_simple(owl_message *m) { |
---|
[b12c219] | 645 | char *indent, *text, *zsigbuff, *foo; |
---|
| 646 | |
---|
| 647 | text=owl_message_get_body(m); |
---|
| 648 | |
---|
| 649 | indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); |
---|
| 650 | owl_text_indent(indent, text, OWL_MSGTAB); |
---|
| 651 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 652 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 653 | owl_fmtext_append_normal(&(m->fmtext), "To: "); |
---|
| 654 | foo=short_zuser(owl_message_get_recipient(m)); |
---|
| 655 | owl_fmtext_append_normal(&(m->fmtext), foo); |
---|
| 656 | owl_free(foo); |
---|
| 657 | owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); |
---|
| 658 | |
---|
[a3ba748] | 659 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b12c219] | 660 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 661 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 662 | owl_free(zsigbuff); |
---|
| 663 | |
---|
| 664 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
| 665 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 666 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 667 | if (text[strlen(text)-1]!='\n') { |
---|
| 668 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | owl_free(indent); |
---|
[b45293f] | 672 | } |
---|
| 673 | |
---|
[7d4fbcd] | 674 | void _owl_message_make_text_from_notice_standard(owl_message *m) { |
---|
[b45293f] | 675 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
[7d4fbcd] | 676 | ZNotice_t *n; |
---|
| 677 | |
---|
| 678 | n=&(m->notice); |
---|
[d309eb3] | 679 | |
---|
| 680 | /* get the body */ |
---|
[d0d65df] | 681 | body=owl_malloc(strlen(owl_message_get_body(m))+30); |
---|
| 682 | strcpy(body, owl_message_get_body(m)); |
---|
[7d4fbcd] | 683 | |
---|
| 684 | /* add a newline if we need to */ |
---|
| 685 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
| 686 | strcat(body, "\n"); |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | /* do the indenting into indent */ |
---|
| 690 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
| 691 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
| 692 | |
---|
| 693 | /* edit the from addr for printing */ |
---|
[d0d65df] | 694 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
[7d4fbcd] | 695 | ptr=strchr(frombuff, '@'); |
---|
| 696 | if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) { |
---|
| 697 | *ptr='\0'; |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | /* set the message for printing */ |
---|
| 701 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 702 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 703 | |
---|
[d0d65df] | 704 | if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) { |
---|
[7d4fbcd] | 705 | owl_fmtext_append_bold(&(m->fmtext), "PING"); |
---|
| 706 | owl_fmtext_append_normal(&(m->fmtext), " from "); |
---|
| 707 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 708 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 709 | } else if (!strcasecmp(n->z_class, "login")) { |
---|
| 710 | char *ptr, host[LINE], tty[LINE]; |
---|
| 711 | int len; |
---|
| 712 | |
---|
| 713 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
| 714 | strncpy(host, ptr, len); |
---|
| 715 | host[len]='\0'; |
---|
| 716 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
| 717 | strncpy(tty, ptr, len); |
---|
| 718 | tty[len]='\0'; |
---|
| 719 | |
---|
| 720 | if (!strcasecmp(n->z_opcode, "user_login")) { |
---|
| 721 | owl_fmtext_append_bold(&(m->fmtext), "LOGIN"); |
---|
| 722 | } else if (!strcasecmp(n->z_opcode, "user_logout")) { |
---|
| 723 | owl_fmtext_append_bold(&(m->fmtext), "LOGOUT"); |
---|
| 724 | } |
---|
| 725 | owl_fmtext_append_normal(&(m->fmtext), " for "); |
---|
[4b464a4] | 726 | ptr=short_zuser(n->z_class_inst); |
---|
[7d4fbcd] | 727 | owl_fmtext_append_bold(&(m->fmtext), ptr); |
---|
| 728 | owl_free(ptr); |
---|
| 729 | owl_fmtext_append_normal(&(m->fmtext), " at "); |
---|
| 730 | owl_fmtext_append_normal(&(m->fmtext), host); |
---|
| 731 | owl_fmtext_append_normal(&(m->fmtext), " "); |
---|
| 732 | owl_fmtext_append_normal(&(m->fmtext), tty); |
---|
| 733 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 734 | } else { |
---|
[d0d65df] | 735 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m)); |
---|
[7d4fbcd] | 736 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
[d0d65df] | 737 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 738 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
| 739 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 740 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
| 741 | owl_fmtext_append_normal(&(m->fmtext), " {"); |
---|
| 742 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m)); |
---|
| 743 | owl_fmtext_append_normal(&(m->fmtext), "} "); |
---|
| 744 | } |
---|
| 745 | if (n->z_opcode[0]!='\0') { |
---|
| 746 | owl_fmtext_append_normal(&(m->fmtext), " ["); |
---|
[d0d65df] | 747 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_opcode(m)); |
---|
[7d4fbcd] | 748 | owl_fmtext_append_normal(&(m->fmtext), "] "); |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | /* stick on the zsig */ |
---|
[a3ba748] | 752 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 753 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 754 | owl_fmtext_append_normal(&(m->fmtext), " ("); |
---|
| 755 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 756 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
[7d4fbcd] | 757 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[b45293f] | 758 | owl_free(zsigbuff); |
---|
| 759 | |
---|
| 760 | /* then the indented message */ |
---|
[7d4fbcd] | 761 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 762 | |
---|
| 763 | /* make personal messages bold for smaat users */ |
---|
| 764 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 765 | if (owl_message_is_personal(m)) { |
---|
| 766 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
| 767 | } |
---|
| 768 | } |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | owl_free(body); |
---|
| 772 | owl_free(indent); |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | void _owl_message_make_text_from_notice_simple(owl_message *m) { |
---|
[b45293f] | 776 | char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; |
---|
[7d4fbcd] | 777 | ZNotice_t *n; |
---|
| 778 | |
---|
| 779 | n=&(m->notice); |
---|
[d309eb3] | 780 | |
---|
| 781 | /* get the body */ |
---|
[ecd5dc5] | 782 | body=owl_strdup(owl_message_get_body(m)); |
---|
| 783 | body=realloc(body, strlen(body)+30); |
---|
[7d4fbcd] | 784 | |
---|
| 785 | /* add a newline if we need to */ |
---|
| 786 | if (body[0]!='\0' && body[strlen(body)-1]!='\n') { |
---|
| 787 | strcat(body, "\n"); |
---|
| 788 | } |
---|
| 789 | |
---|
| 790 | /* do the indenting into indent */ |
---|
| 791 | indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10); |
---|
| 792 | owl_text_indent(indent, body, OWL_MSGTAB); |
---|
| 793 | |
---|
| 794 | /* edit the from addr for printing */ |
---|
[d0d65df] | 795 | strcpy(frombuff, owl_message_get_sender(m)); |
---|
[7d4fbcd] | 796 | ptr=strchr(frombuff, '@'); |
---|
| 797 | if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) { |
---|
| 798 | *ptr='\0'; |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | /* set the message for printing */ |
---|
| 802 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 803 | owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); |
---|
| 804 | |
---|
[d0d65df] | 805 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) { |
---|
[7d4fbcd] | 806 | owl_fmtext_append_bold(&(m->fmtext), "PING"); |
---|
| 807 | owl_fmtext_append_normal(&(m->fmtext), " from "); |
---|
| 808 | owl_fmtext_append_bold(&(m->fmtext), frombuff); |
---|
| 809 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[d0d65df] | 810 | } else if (!strcasecmp(owl_message_get_class(m), "login")) { |
---|
[7d4fbcd] | 811 | char *ptr, host[LINE], tty[LINE]; |
---|
| 812 | int len; |
---|
| 813 | |
---|
| 814 | ptr=owl_zephyr_get_field(n, 1, &len); |
---|
| 815 | strncpy(host, ptr, len); |
---|
| 816 | host[len]='\0'; |
---|
| 817 | ptr=owl_zephyr_get_field(n, 3, &len); |
---|
| 818 | strncpy(tty, ptr, len); |
---|
| 819 | tty[len]='\0'; |
---|
| 820 | |
---|
[d0d65df] | 821 | if (!strcasecmp(owl_message_get_opcode(m), "user_login")) { |
---|
[7d4fbcd] | 822 | owl_fmtext_append_bold(&(m->fmtext), "LOGIN"); |
---|
[d0d65df] | 823 | } else if (!strcasecmp(owl_message_get_opcode(m), "user_logout")) { |
---|
[7d4fbcd] | 824 | owl_fmtext_append_bold(&(m->fmtext), "LOGOUT"); |
---|
| 825 | } |
---|
| 826 | owl_fmtext_append_normal(&(m->fmtext), " for "); |
---|
[d0d65df] | 827 | ptr=short_zuser(owl_message_get_instance(m)); |
---|
[7d4fbcd] | 828 | owl_fmtext_append_bold(&(m->fmtext), ptr); |
---|
| 829 | owl_free(ptr); |
---|
| 830 | owl_fmtext_append_normal(&(m->fmtext), " at "); |
---|
| 831 | owl_fmtext_append_normal(&(m->fmtext), host); |
---|
| 832 | owl_fmtext_append_normal(&(m->fmtext), " "); |
---|
| 833 | owl_fmtext_append_normal(&(m->fmtext), tty); |
---|
| 834 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
| 835 | } else { |
---|
| 836 | owl_fmtext_append_normal(&(m->fmtext), "From: "); |
---|
[d0d65df] | 837 | if (strcasecmp(owl_message_get_class(m), "message")) { |
---|
[7d4fbcd] | 838 | owl_fmtext_append_normal(&(m->fmtext), "Class "); |
---|
[d0d65df] | 839 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m)); |
---|
[7d4fbcd] | 840 | owl_fmtext_append_normal(&(m->fmtext), " / Instance "); |
---|
[d0d65df] | 841 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 842 | owl_fmtext_append_normal(&(m->fmtext), " / "); |
---|
| 843 | } |
---|
| 844 | owl_fmtext_append_normal(&(m->fmtext), frombuff); |
---|
| 845 | if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) { |
---|
| 846 | owl_fmtext_append_normal(&(m->fmtext), " {"); |
---|
| 847 | owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m)); |
---|
| 848 | owl_fmtext_append_normal(&(m->fmtext), "} "); |
---|
| 849 | } |
---|
| 850 | |
---|
| 851 | /* stick on the zsig */ |
---|
[a3ba748] | 852 | zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30); |
---|
[b45293f] | 853 | owl_message_pretty_zsig(m, zsigbuff); |
---|
| 854 | owl_fmtext_append_normal(&(m->fmtext), " ("); |
---|
| 855 | owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); |
---|
| 856 | owl_fmtext_append_normal(&(m->fmtext), ")"); |
---|
[7d4fbcd] | 857 | owl_fmtext_append_normal(&(m->fmtext), "\n"); |
---|
[b45293f] | 858 | owl_free(zsigbuff); |
---|
| 859 | |
---|
| 860 | /* then the indented message */ |
---|
[7d4fbcd] | 861 | owl_fmtext_append_ztext(&(m->fmtext), indent); |
---|
| 862 | |
---|
| 863 | /* make personal messages bold for smaat users */ |
---|
| 864 | if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { |
---|
| 865 | if (owl_message_is_personal(m)) { |
---|
| 866 | owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD); |
---|
| 867 | } |
---|
| 868 | } |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | owl_free(body); |
---|
| 872 | owl_free(indent); |
---|
| 873 | } |
---|
| 874 | |
---|
[b45293f] | 875 | void owl_message_pretty_zsig(owl_message *m, char *buff) { |
---|
| 876 | /* stick a one line version of the zsig in buff */ |
---|
[7d4fbcd] | 877 | char *ptr; |
---|
| 878 | |
---|
[d0d65df] | 879 | strcpy(buff, owl_message_get_zsig(m)); |
---|
[b45293f] | 880 | ptr=strchr(buff, '\n'); |
---|
| 881 | if (ptr) ptr[0]='\0'; |
---|
[7d4fbcd] | 882 | } |
---|
| 883 | |
---|
| 884 | void owl_message_free(owl_message *m) { |
---|
[d0d65df] | 885 | int i, j; |
---|
| 886 | owl_pair *p; |
---|
| 887 | |
---|
[4b464a4] | 888 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
[7d4fbcd] | 889 | ZFreeNotice(&(m->notice)); |
---|
| 890 | } |
---|
| 891 | if (m->time) owl_free(m->time); |
---|
| 892 | if (m->zwriteline) owl_free(m->zwriteline); |
---|
[d0d65df] | 893 | |
---|
| 894 | /* free all the attributes */ |
---|
| 895 | j=owl_list_get_size(&(m->attributes)); |
---|
| 896 | for (i=0; i<j; i++) { |
---|
| 897 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 898 | owl_free(owl_pair_get_key(p)); |
---|
| 899 | owl_free(owl_pair_get_value(p)); |
---|
| 900 | owl_free(p); |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | owl_list_free_simple(&(m->attributes)); |
---|
[7d4fbcd] | 904 | |
---|
| 905 | owl_fmtext_free(&(m->fmtext)); |
---|
| 906 | } |
---|