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