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