[7d4fbcd] | 1 | #include <stdlib.h> |
---|
[b45293f] | 2 | #include <unistd.h> |
---|
[7d4fbcd] | 3 | #include <string.h> |
---|
| 4 | #include <sys/socket.h> |
---|
| 5 | #include <netdb.h> |
---|
| 6 | #include <sys/types.h> |
---|
| 7 | #include <sys/socket.h> |
---|
| 8 | #include <netinet/in.h> |
---|
| 9 | #include <arpa/inet.h> |
---|
| 10 | #include <time.h> |
---|
| 11 | #include "owl.h" |
---|
| 12 | |
---|
[1aee7d9] | 13 | static const char fileIdent[] = "$Id$"; |
---|
| 14 | |
---|
[0ff8fb57] | 15 | void owl_message_init(owl_message *m) |
---|
| 16 | { |
---|
[7d4fbcd] | 17 | m->id=owl_global_get_nextmsgid(&g); |
---|
[4b464a4] | 18 | owl_message_set_direction_none(m); |
---|
[7d4fbcd] | 19 | m->delete=0; |
---|
| 20 | m->zwriteline=strdup(""); |
---|
[bd3f232] | 21 | m->invalid_format=1; |
---|
[7d4fbcd] | 22 | |
---|
[d0d65df] | 23 | owl_list_create(&(m->attributes)); |
---|
| 24 | |
---|
[7d4fbcd] | 25 | /* save the time */ |
---|
[25dd31a] | 26 | m->time=time(NULL); |
---|
| 27 | m->timestr=owl_strdup(ctime(&(m->time))); |
---|
| 28 | m->timestr[strlen(m->timestr)-1]='\0'; |
---|
| 29 | |
---|
| 30 | /* initialize the fmtext */ |
---|
[bd3f232] | 31 | owl_fmtext_init_null(&(m->fmtext)); |
---|
[4b464a4] | 32 | } |
---|
| 33 | |
---|
[5a95b69] | 34 | /* add the named attribute to the message. If an attribute with the |
---|
| 35 | * name already exists, replace the old value with the new value |
---|
| 36 | */ |
---|
[0ff8fb57] | 37 | void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue) |
---|
| 38 | { |
---|
[d0d65df] | 39 | int i, j; |
---|
[e849734] | 40 | owl_pair *p = NULL, *pair = NULL; |
---|
[d0d65df] | 41 | |
---|
[e849734] | 42 | /* look for an existing pair with this key, */ |
---|
[d0d65df] | 43 | j=owl_list_get_size(&(m->attributes)); |
---|
| 44 | for (i=0; i<j; i++) { |
---|
| 45 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 46 | if (!strcmp(owl_pair_get_key(p), attrname)) { |
---|
| 47 | owl_free(owl_pair_get_value(p)); |
---|
[e849734] | 48 | pair = p; |
---|
[d0d65df] | 49 | break; |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
[e849734] | 53 | if(pair == NULL) { |
---|
| 54 | pair = owl_malloc(sizeof(owl_pair)); |
---|
| 55 | owl_pair_create(pair, owl_global_intern(&g, attrname), NULL); |
---|
| 56 | owl_list_append_element(&(m->attributes), pair); |
---|
| 57 | } |
---|
| 58 | owl_pair_set_value(pair, owl_strdup(attrvalue)); |
---|
[d0d65df] | 59 | } |
---|
| 60 | |
---|
[5a95b69] | 61 | /* return the value associated with the named attribute, or NULL if |
---|
| 62 | * the attribute does not exist |
---|
| 63 | */ |
---|
[0ff8fb57] | 64 | char *owl_message_get_attribute_value(owl_message *m, char *attrname) |
---|
| 65 | { |
---|
[d0d65df] | 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 | } |
---|
[f4d0975] | 76 | |
---|
| 77 | /* |
---|
| 78 | owl_function_debugmsg("No attribute %s found for message %i", |
---|
| 79 | attrname, |
---|
| 80 | owl_message_get_id(m)); |
---|
| 81 | */ |
---|
[d0d65df] | 82 | return(NULL); |
---|
| 83 | } |
---|
| 84 | |
---|
[5789230] | 85 | /* We cheat and indent it for now, since we really want this for |
---|
| 86 | * the 'info' function. Later there should just be a generic |
---|
| 87 | * function to indent fmtext. |
---|
| 88 | */ |
---|
| 89 | void owl_message_attributes_tofmtext(owl_message *m, owl_fmtext *fm) { |
---|
| 90 | int i, j; |
---|
| 91 | owl_pair *p; |
---|
| 92 | char *buff; |
---|
| 93 | |
---|
| 94 | owl_fmtext_init_null(fm); |
---|
| 95 | |
---|
| 96 | j=owl_list_get_size(&(m->attributes)); |
---|
| 97 | for (i=0; i<j; i++) { |
---|
| 98 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 99 | buff=owl_sprintf(" %-15.15s: %-35.35s\n", owl_pair_get_key(p), owl_pair_get_value(p)); |
---|
| 100 | owl_fmtext_append_normal(fm, buff); |
---|
| 101 | owl_free(buff); |
---|
| 102 | } |
---|
| 103 | } |
---|
[4b464a4] | 104 | |
---|
[bd3f232] | 105 | void owl_message_invalidate_format(owl_message *m) |
---|
| 106 | { |
---|
| 107 | m->invalid_format=1; |
---|
| 108 | } |
---|
| 109 | |
---|
[0ff8fb57] | 110 | owl_fmtext *owl_message_get_fmtext(owl_message *m) |
---|
| 111 | { |
---|
[f14a7ee] | 112 | owl_message_format(m); |
---|
| 113 | return(&(m->fmtext)); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void owl_message_format(owl_message *m) |
---|
| 117 | { |
---|
[bd3f232] | 118 | owl_style *s; |
---|
[ef56a67] | 119 | owl_view *v; |
---|
[bd3f232] | 120 | |
---|
| 121 | if (m->invalid_format) { |
---|
[421c8ef7] | 122 | /* for now we assume there's just the one view and use that style */ |
---|
[ef56a67] | 123 | v=owl_global_get_current_view(&g); |
---|
| 124 | s=owl_view_get_style(v); |
---|
| 125 | |
---|
[bd3f232] | 126 | owl_fmtext_free(&(m->fmtext)); |
---|
| 127 | owl_fmtext_init_null(&(m->fmtext)); |
---|
| 128 | owl_style_get_formattext(s, &(m->fmtext), m); |
---|
| 129 | m->invalid_format=0; |
---|
| 130 | } |
---|
[4b464a4] | 131 | } |
---|
| 132 | |
---|
[0ff8fb57] | 133 | void owl_message_set_class(owl_message *m, char *class) |
---|
| 134 | { |
---|
[d0d65df] | 135 | owl_message_set_attribute(m, "class", class); |
---|
[4b464a4] | 136 | } |
---|
| 137 | |
---|
[0ff8fb57] | 138 | char *owl_message_get_class(owl_message *m) |
---|
| 139 | { |
---|
[d0d65df] | 140 | char *class; |
---|
| 141 | |
---|
| 142 | class=owl_message_get_attribute_value(m, "class"); |
---|
| 143 | if (!class) return(""); |
---|
| 144 | return(class); |
---|
[4b464a4] | 145 | } |
---|
| 146 | |
---|
[0ff8fb57] | 147 | void owl_message_set_instance(owl_message *m, char *inst) |
---|
| 148 | { |
---|
[d0d65df] | 149 | owl_message_set_attribute(m, "instance", inst); |
---|
[4b464a4] | 150 | } |
---|
| 151 | |
---|
[0ff8fb57] | 152 | char *owl_message_get_instance(owl_message *m) |
---|
| 153 | { |
---|
[d0d65df] | 154 | char *instance; |
---|
| 155 | |
---|
| 156 | instance=owl_message_get_attribute_value(m, "instance"); |
---|
| 157 | if (!instance) return(""); |
---|
| 158 | return(instance); |
---|
[4b464a4] | 159 | } |
---|
| 160 | |
---|
[0ff8fb57] | 161 | void owl_message_set_sender(owl_message *m, char *sender) |
---|
| 162 | { |
---|
[d0d65df] | 163 | owl_message_set_attribute(m, "sender", sender); |
---|
[4b464a4] | 164 | } |
---|
| 165 | |
---|
[0ff8fb57] | 166 | char *owl_message_get_sender(owl_message *m) |
---|
| 167 | { |
---|
[d0d65df] | 168 | char *sender; |
---|
| 169 | |
---|
| 170 | sender=owl_message_get_attribute_value(m, "sender"); |
---|
| 171 | if (!sender) return(""); |
---|
| 172 | return(sender); |
---|
[4b464a4] | 173 | } |
---|
| 174 | |
---|
[0ff8fb57] | 175 | void owl_message_set_zsig(owl_message *m, char *zsig) |
---|
| 176 | { |
---|
[d0d65df] | 177 | owl_message_set_attribute(m, "zsig", zsig); |
---|
[b45293f] | 178 | } |
---|
| 179 | |
---|
[0ff8fb57] | 180 | char *owl_message_get_zsig(owl_message *m) |
---|
| 181 | { |
---|
[d0d65df] | 182 | char *zsig; |
---|
| 183 | |
---|
| 184 | zsig=owl_message_get_attribute_value(m, "zsig"); |
---|
| 185 | if (!zsig) return(""); |
---|
| 186 | return(zsig); |
---|
[b45293f] | 187 | } |
---|
| 188 | |
---|
[0ff8fb57] | 189 | void owl_message_set_recipient(owl_message *m, char *recip) |
---|
| 190 | { |
---|
[d0d65df] | 191 | owl_message_set_attribute(m, "recipient", recip); |
---|
[4b464a4] | 192 | } |
---|
| 193 | |
---|
[0ff8fb57] | 194 | char *owl_message_get_recipient(owl_message *m) |
---|
| 195 | { |
---|
[4b464a4] | 196 | /* this is stupid for outgoing messages, we need to fix it. */ |
---|
[d0d65df] | 197 | |
---|
| 198 | char *recip; |
---|
[0ff8fb57] | 199 | |
---|
| 200 | recip=owl_message_get_attribute_value(m, "recipient"); |
---|
[d0d65df] | 201 | if (!recip) return(""); |
---|
| 202 | return(recip); |
---|
[4b464a4] | 203 | } |
---|
| 204 | |
---|
[0ff8fb57] | 205 | void owl_message_set_realm(owl_message *m, char *realm) |
---|
| 206 | { |
---|
[d0d65df] | 207 | owl_message_set_attribute(m, "realm", realm); |
---|
[4b464a4] | 208 | } |
---|
| 209 | |
---|
[0ff8fb57] | 210 | char *owl_message_get_realm(owl_message *m) |
---|
| 211 | { |
---|
[d0d65df] | 212 | char *realm; |
---|
| 213 | |
---|
| 214 | realm=owl_message_get_attribute_value(m, "realm"); |
---|
| 215 | if (!realm) return(""); |
---|
| 216 | return(realm); |
---|
| 217 | } |
---|
| 218 | |
---|
[0ff8fb57] | 219 | void owl_message_set_body(owl_message *m, char *body) |
---|
| 220 | { |
---|
[d0d65df] | 221 | owl_message_set_attribute(m, "body", body); |
---|
| 222 | } |
---|
| 223 | |
---|
[0ff8fb57] | 224 | char *owl_message_get_body(owl_message *m) |
---|
| 225 | { |
---|
[d0d65df] | 226 | char *body; |
---|
| 227 | |
---|
| 228 | body=owl_message_get_attribute_value(m, "body"); |
---|
| 229 | if (!body) return(""); |
---|
| 230 | return(body); |
---|
[4b464a4] | 231 | } |
---|
| 232 | |
---|
[d0d65df] | 233 | |
---|
[0ff8fb57] | 234 | void owl_message_set_opcode(owl_message *m, char *opcode) |
---|
| 235 | { |
---|
[d0d65df] | 236 | owl_message_set_attribute(m, "opcode", opcode); |
---|
[4b464a4] | 237 | } |
---|
| 238 | |
---|
[0ff8fb57] | 239 | char *owl_message_get_opcode(owl_message *m) |
---|
| 240 | { |
---|
[d0d65df] | 241 | char *opcode; |
---|
| 242 | |
---|
| 243 | opcode=owl_message_get_attribute_value(m, "opcode"); |
---|
| 244 | if (!opcode) return(""); |
---|
| 245 | return(opcode); |
---|
[4b464a4] | 246 | } |
---|
| 247 | |
---|
[5789230] | 248 | |
---|
[d559df9] | 249 | void owl_message_set_islogin(owl_message *m) |
---|
[5789230] | 250 | { |
---|
[d559df9] | 251 | owl_message_set_attribute(m, "loginout", "login"); |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | void owl_message_set_islogout(owl_message *m) |
---|
| 256 | { |
---|
| 257 | owl_message_set_attribute(m, "loginout", "logout"); |
---|
[5789230] | 258 | } |
---|
| 259 | |
---|
| 260 | int owl_message_is_loginout(owl_message *m) |
---|
| 261 | { |
---|
| 262 | char *res; |
---|
| 263 | |
---|
[d559df9] | 264 | res=owl_message_get_attribute_value(m, "loginout"); |
---|
[5789230] | 265 | if (!res) return(0); |
---|
| 266 | return(1); |
---|
| 267 | } |
---|
| 268 | |
---|
[d559df9] | 269 | int owl_message_is_login(owl_message *m) |
---|
| 270 | { |
---|
| 271 | char *res; |
---|
| 272 | |
---|
| 273 | res=owl_message_get_attribute_value(m, "loginout"); |
---|
| 274 | if (!res) return(0); |
---|
| 275 | if (!strcmp(res, "login")) return(1); |
---|
| 276 | return(0); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | int owl_message_is_logout(owl_message *m) |
---|
| 281 | { |
---|
| 282 | char *res; |
---|
| 283 | |
---|
| 284 | res=owl_message_get_attribute_value(m, "loginout"); |
---|
| 285 | if (!res) return(0); |
---|
| 286 | if (!strcmp(res, "logout")) return(1); |
---|
| 287 | return(0); |
---|
| 288 | } |
---|
| 289 | |
---|
[5789230] | 290 | void owl_message_set_isprivate(owl_message *m) |
---|
| 291 | { |
---|
[312675c] | 292 | owl_message_set_attribute(m, "isprivate", "true"); |
---|
[5789230] | 293 | } |
---|
| 294 | |
---|
| 295 | int owl_message_is_private(owl_message *m) |
---|
| 296 | { |
---|
| 297 | char *res; |
---|
| 298 | |
---|
| 299 | res=owl_message_get_attribute_value(m, "isprivate"); |
---|
| 300 | if (!res) return(0); |
---|
| 301 | return(1); |
---|
| 302 | } |
---|
| 303 | |
---|
[0ff8fb57] | 304 | char *owl_message_get_timestr(owl_message *m) |
---|
| 305 | { |
---|
[25dd31a] | 306 | if (m->timestr) return(m->timestr); |
---|
| 307 | return(""); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | /* caller must free the return */ |
---|
| 311 | char *owl_message_get_shorttimestr(owl_message *m) |
---|
| 312 | { |
---|
| 313 | struct tm *tmstruct; |
---|
| 314 | char *out; |
---|
| 315 | |
---|
| 316 | tmstruct=localtime(&(m->time)); |
---|
| 317 | out=owl_sprintf("%2.2i:%2.2i", tmstruct->tm_hour, tmstruct->tm_min); |
---|
| 318 | if (out) return(out); |
---|
| 319 | return("??:??"); |
---|
[4b464a4] | 320 | } |
---|
| 321 | |
---|
[0ff8fb57] | 322 | void owl_message_set_type_admin(owl_message *m) |
---|
| 323 | { |
---|
[30678ae] | 324 | owl_message_set_attribute(m, "type", "admin"); |
---|
[4b464a4] | 325 | } |
---|
| 326 | |
---|
[37eab7f] | 327 | void owl_message_set_type_loopback(owl_message *m) |
---|
| 328 | { |
---|
[30678ae] | 329 | owl_message_set_attribute(m, "type", "loopback"); |
---|
[37eab7f] | 330 | } |
---|
| 331 | |
---|
[0ff8fb57] | 332 | void owl_message_set_type_zephyr(owl_message *m) |
---|
| 333 | { |
---|
[30678ae] | 334 | owl_message_set_attribute(m, "type", "zephyr"); |
---|
[4b464a4] | 335 | } |
---|
[d09e5a1] | 336 | |
---|
[0ff8fb57] | 337 | void owl_message_set_type_aim(owl_message *m) |
---|
| 338 | { |
---|
[e363375] | 339 | owl_message_set_attribute(m, "type", "AIM"); |
---|
[d09e5a1] | 340 | } |
---|
[dd16bdd] | 341 | |
---|
[30678ae] | 342 | void owl_message_set_type(owl_message *m, char* type) |
---|
[dd16bdd] | 343 | { |
---|
[30678ae] | 344 | owl_message_set_attribute(m, "type", type); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | int owl_message_is_type(owl_message *m, char *type) { |
---|
| 348 | char * t = owl_message_get_attribute_value(m, "type"); |
---|
| 349 | if(!t) return 0; |
---|
[e363375] | 350 | return !strcasecmp(t, type); |
---|
[dd16bdd] | 351 | } |
---|
[4b464a4] | 352 | |
---|
[0ff8fb57] | 353 | int owl_message_is_type_admin(owl_message *m) |
---|
| 354 | { |
---|
[30678ae] | 355 | return owl_message_is_type(m, "admin"); |
---|
[4b464a4] | 356 | } |
---|
| 357 | |
---|
[421c8ef7] | 358 | int owl_message_is_type_generic(owl_message *m) |
---|
[37eab7f] | 359 | { |
---|
[30678ae] | 360 | char * t = owl_message_get_attribute_value(m, "type"); |
---|
| 361 | return (t == NULL); |
---|
[37eab7f] | 362 | } |
---|
| 363 | |
---|
[0ff8fb57] | 364 | int owl_message_is_type_zephyr(owl_message *m) |
---|
| 365 | { |
---|
[30678ae] | 366 | return owl_message_is_type(m, "zephyr"); |
---|
[4b464a4] | 367 | } |
---|
| 368 | |
---|
[0ff8fb57] | 369 | int owl_message_is_type_aim(owl_message *m) |
---|
| 370 | { |
---|
[30678ae] | 371 | return owl_message_is_type(m, "aim"); |
---|
[d09e5a1] | 372 | } |
---|
| 373 | |
---|
[30678ae] | 374 | /* XXX TODO: deprecate this */ |
---|
[421c8ef7] | 375 | int owl_message_is_type_jabber(owl_message *m) |
---|
[5a95b69] | 376 | { |
---|
[30678ae] | 377 | return owl_message_is_type(m, "jabber"); |
---|
[421c8ef7] | 378 | } |
---|
| 379 | |
---|
| 380 | int owl_message_is_type_loopback(owl_message *m) |
---|
| 381 | { |
---|
[30678ae] | 382 | return owl_message_is_type(m, "loopback"); |
---|
[421c8ef7] | 383 | } |
---|
| 384 | |
---|
| 385 | int owl_message_is_pseudo(owl_message *m) |
---|
| 386 | { |
---|
| 387 | if (owl_message_get_attribute_value(m, "pseudo")) return(1); |
---|
[4b464a4] | 388 | return(0); |
---|
| 389 | } |
---|
| 390 | |
---|
[0ff8fb57] | 391 | char *owl_message_get_text(owl_message *m) |
---|
| 392 | { |
---|
[4b464a4] | 393 | return(owl_fmtext_get_text(&(m->fmtext))); |
---|
| 394 | } |
---|
| 395 | |
---|
[0ff8fb57] | 396 | void owl_message_set_direction_in(owl_message *m) |
---|
| 397 | { |
---|
[4b464a4] | 398 | m->direction=OWL_MESSAGE_DIRECTION_IN; |
---|
| 399 | } |
---|
| 400 | |
---|
[0ff8fb57] | 401 | void owl_message_set_direction_out(owl_message *m) |
---|
| 402 | { |
---|
[4b464a4] | 403 | m->direction=OWL_MESSAGE_DIRECTION_OUT; |
---|
| 404 | } |
---|
| 405 | |
---|
[0ff8fb57] | 406 | void owl_message_set_direction_none(owl_message *m) |
---|
| 407 | { |
---|
[4b464a4] | 408 | m->direction=OWL_MESSAGE_DIRECTION_NONE; |
---|
| 409 | } |
---|
| 410 | |
---|
[dd16bdd] | 411 | void owl_message_set_direction(owl_message *m, int direction) |
---|
| 412 | { |
---|
| 413 | m->direction=direction; |
---|
| 414 | } |
---|
| 415 | |
---|
[0ff8fb57] | 416 | int owl_message_is_direction_in(owl_message *m) |
---|
| 417 | { |
---|
[4b464a4] | 418 | if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1); |
---|
| 419 | return(0); |
---|
| 420 | } |
---|
| 421 | |
---|
[0ff8fb57] | 422 | int owl_message_is_direction_out(owl_message *m) |
---|
| 423 | { |
---|
[4b464a4] | 424 | if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1); |
---|
| 425 | return(0); |
---|
| 426 | } |
---|
| 427 | |
---|
[0ff8fb57] | 428 | int owl_message_is_direction_none(owl_message *m) |
---|
| 429 | { |
---|
[4b464a4] | 430 | if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1); |
---|
| 431 | return(0); |
---|
| 432 | } |
---|
| 433 | |
---|
[0ff8fb57] | 434 | int owl_message_get_numlines(owl_message *m) |
---|
| 435 | { |
---|
[4b464a4] | 436 | if (m == NULL) return(0); |
---|
[f14a7ee] | 437 | owl_message_format(m); |
---|
[4b464a4] | 438 | return(owl_fmtext_num_lines(&(m->fmtext))); |
---|
| 439 | } |
---|
| 440 | |
---|
[0ff8fb57] | 441 | void owl_message_mark_delete(owl_message *m) |
---|
| 442 | { |
---|
[4b464a4] | 443 | if (m == NULL) return; |
---|
| 444 | m->delete=1; |
---|
| 445 | } |
---|
| 446 | |
---|
[0ff8fb57] | 447 | void owl_message_unmark_delete(owl_message *m) |
---|
| 448 | { |
---|
[4b464a4] | 449 | if (m == NULL) return; |
---|
| 450 | m->delete=0; |
---|
| 451 | } |
---|
| 452 | |
---|
[0ff8fb57] | 453 | char *owl_message_get_zwriteline(owl_message *m) |
---|
| 454 | { |
---|
[4b464a4] | 455 | return(m->zwriteline); |
---|
| 456 | } |
---|
| 457 | |
---|
[0ff8fb57] | 458 | void owl_message_set_zwriteline(owl_message *m, char *line) |
---|
| 459 | { |
---|
[4b464a4] | 460 | m->zwriteline=strdup(line); |
---|
| 461 | } |
---|
| 462 | |
---|
[0ff8fb57] | 463 | int owl_message_is_delete(owl_message *m) |
---|
| 464 | { |
---|
[4b464a4] | 465 | if (m == NULL) return(0); |
---|
| 466 | if (m->delete==1) return(1); |
---|
| 467 | return(0); |
---|
| 468 | } |
---|
| 469 | |
---|
[be0a79f] | 470 | #ifdef HAVE_LIBZEPHYR |
---|
[0ff8fb57] | 471 | ZNotice_t *owl_message_get_notice(owl_message *m) |
---|
| 472 | { |
---|
[4b464a4] | 473 | return(&(m->notice)); |
---|
| 474 | } |
---|
[09489b89] | 475 | #else |
---|
| 476 | void *owl_message_get_notice(owl_message *m) |
---|
| 477 | { |
---|
| 478 | return(NULL); |
---|
| 479 | } |
---|
[be0a79f] | 480 | #endif |
---|
[4b464a4] | 481 | |
---|
[8298425] | 482 | void owl_message_set_hostname(owl_message *m, char *hostname) |
---|
| 483 | { |
---|
[e849734] | 484 | m->hostname=owl_global_intern(&g, hostname); |
---|
[8298425] | 485 | } |
---|
| 486 | |
---|
[0ff8fb57] | 487 | char *owl_message_get_hostname(owl_message *m) |
---|
| 488 | { |
---|
[4b464a4] | 489 | return(m->hostname); |
---|
| 490 | } |
---|
| 491 | |
---|
[8fa9562] | 492 | void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int fgcolor, int bgcolor) |
---|
[0ff8fb57] | 493 | { |
---|
[4b464a4] | 494 | owl_fmtext a, b; |
---|
| 495 | |
---|
[bd3f232] | 496 | /* this will ensure that our cached copy is up to date */ |
---|
[f14a7ee] | 497 | owl_message_format(m); |
---|
[bd3f232] | 498 | |
---|
[af2ca19] | 499 | owl_fmtext_init_null(&a); |
---|
| 500 | owl_fmtext_init_null(&b); |
---|
| 501 | |
---|
[4b464a4] | 502 | owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a); |
---|
| 503 | owl_fmtext_truncate_cols(&a, acol, bcol, &b); |
---|
[8fa9562] | 504 | if (fgcolor!=OWL_COLOR_DEFAULT) { |
---|
| 505 | owl_fmtext_colorize(&b, fgcolor); |
---|
| 506 | } |
---|
| 507 | if (bgcolor!=OWL_COLOR_DEFAULT) { |
---|
| 508 | owl_fmtext_colorizebg(&b, bgcolor); |
---|
[4b464a4] | 509 | } |
---|
| 510 | |
---|
| 511 | if (owl_global_is_search_active(&g)) { |
---|
| 512 | owl_fmtext_search_and_highlight(&b, owl_global_get_search_string(&g)); |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | owl_fmtext_curs_waddstr(&b, win); |
---|
| 516 | |
---|
| 517 | owl_fmtext_free(&a); |
---|
| 518 | owl_fmtext_free(&b); |
---|
| 519 | } |
---|
| 520 | |
---|
[0ff8fb57] | 521 | int owl_message_is_personal(owl_message *m) |
---|
| 522 | { |
---|
| 523 | if (owl_message_is_type_zephyr(m)) { |
---|
| 524 | if (strcasecmp(owl_message_get_class(m), "message")) return(0); |
---|
| 525 | if (strcasecmp(owl_message_get_instance(m), "personal")) return(0); |
---|
[09489b89] | 526 | if (!strcasecmp(owl_message_get_recipient(m), owl_zephyr_get_sender()) || |
---|
| 527 | !strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) { |
---|
[0ff8fb57] | 528 | return(1); |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | return(0); |
---|
| 532 | } |
---|
| 533 | |
---|
[f4d32cd] | 534 | int owl_message_is_question(owl_message *m) |
---|
| 535 | { |
---|
| 536 | if(!owl_message_is_type_admin(m)) return 0; |
---|
| 537 | if(owl_message_get_attribute_value(m, "question") != NULL) return 1; |
---|
| 538 | return 0; |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | int owl_message_is_answered(owl_message *m) { |
---|
| 542 | if(!owl_message_is_question(m)) return 0; |
---|
| 543 | char * q = owl_message_get_attribute_value(m, "question"); |
---|
| 544 | if(!q) return 0; |
---|
| 545 | return !strcmp(q, "answered"); |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | void owl_message_set_isanswered(owl_message *m) { |
---|
| 549 | owl_message_set_attribute(m, "question", "answered"); |
---|
| 550 | } |
---|
| 551 | |
---|
[0ff8fb57] | 552 | int owl_message_is_from_me(owl_message *m) |
---|
| 553 | { |
---|
| 554 | if (owl_message_is_type_zephyr(m)) { |
---|
[09489b89] | 555 | if (!strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) { |
---|
[0ff8fb57] | 556 | return(1); |
---|
| 557 | } else { |
---|
| 558 | return(0); |
---|
| 559 | } |
---|
| 560 | } else if (owl_message_is_type_aim(m)) { |
---|
| 561 | if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) { |
---|
| 562 | return(1); |
---|
| 563 | } else { |
---|
| 564 | return(0); |
---|
| 565 | } |
---|
| 566 | } else if (owl_message_is_type_admin(m)) { |
---|
| 567 | return(0); |
---|
| 568 | } |
---|
[4b464a4] | 569 | return(0); |
---|
| 570 | } |
---|
| 571 | |
---|
[0ff8fb57] | 572 | int owl_message_is_mail(owl_message *m) |
---|
| 573 | { |
---|
| 574 | if (owl_message_is_type_zephyr(m)) { |
---|
[5789230] | 575 | if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) { |
---|
[0ff8fb57] | 576 | return(1); |
---|
| 577 | } else { |
---|
| 578 | return(0); |
---|
| 579 | } |
---|
[4b464a4] | 580 | } |
---|
| 581 | return(0); |
---|
| 582 | } |
---|
| 583 | |
---|
[0ff8fb57] | 584 | int owl_message_is_ping(owl_message *m) |
---|
| 585 | { |
---|
| 586 | if (owl_message_is_type_zephyr(m)) { |
---|
| 587 | if (!strcasecmp(owl_message_get_opcode(m), "ping")) { |
---|
| 588 | return(1); |
---|
| 589 | } else { |
---|
| 590 | return(0); |
---|
| 591 | } |
---|
| 592 | } |
---|
[4b464a4] | 593 | return(0); |
---|
| 594 | } |
---|
| 595 | |
---|
[0ff8fb57] | 596 | int owl_message_is_burningears(owl_message *m) |
---|
| 597 | { |
---|
[4b464a4] | 598 | /* we should add a global to cache the short zsender */ |
---|
| 599 | char sender[LINE], *ptr; |
---|
| 600 | |
---|
| 601 | /* if the message is from us or to us, it doesn't count */ |
---|
[5789230] | 602 | if (owl_message_is_from_me(m) || owl_message_is_private(m)) return(0); |
---|
[0ff8fb57] | 603 | |
---|
| 604 | if (owl_message_is_type_zephyr(m)) { |
---|
[09489b89] | 605 | strcpy(sender, owl_zephyr_get_sender()); |
---|
[0ff8fb57] | 606 | ptr=strchr(sender, '@'); |
---|
| 607 | if (ptr) *ptr='\0'; |
---|
| 608 | } else if (owl_message_is_type_aim(m)) { |
---|
| 609 | strcpy(sender, owl_global_get_aim_screenname(&g)); |
---|
| 610 | } else { |
---|
| 611 | return(0); |
---|
| 612 | } |
---|
[4b464a4] | 613 | |
---|
| 614 | if (stristr(owl_message_get_body(m), sender)) { |
---|
| 615 | return(1); |
---|
| 616 | } |
---|
| 617 | return(0); |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | /* caller must free return value. */ |
---|
[0ff8fb57] | 621 | char *owl_message_get_cc(owl_message *m) |
---|
| 622 | { |
---|
[4b464a4] | 623 | char *cur, *out, *end; |
---|
| 624 | |
---|
| 625 | cur = owl_message_get_body(m); |
---|
| 626 | while (*cur && *cur==' ') cur++; |
---|
[985f85b] | 627 | if (strncasecmp(cur, "cc:", 3)) return(NULL); |
---|
[4b464a4] | 628 | cur+=3; |
---|
| 629 | while (*cur && *cur==' ') cur++; |
---|
| 630 | out = owl_strdup(cur); |
---|
| 631 | end = strchr(out, '\n'); |
---|
| 632 | if (end) end[0] = '\0'; |
---|
| 633 | return(out); |
---|
| 634 | } |
---|
| 635 | |
---|
[0ff8fb57] | 636 | int owl_message_get_id(owl_message *m) |
---|
| 637 | { |
---|
[4b464a4] | 638 | return(m->id); |
---|
| 639 | } |
---|
[bd3f232] | 640 | |
---|
[f1e629d] | 641 | char *owl_message_get_type(owl_message *m) { |
---|
[30678ae] | 642 | char * type = owl_message_get_attribute_value(m, "type"); |
---|
| 643 | if(!type) { |
---|
| 644 | return "generic"; |
---|
[dd16bdd] | 645 | } |
---|
[30678ae] | 646 | return type; |
---|
[dd16bdd] | 647 | } |
---|
| 648 | |
---|
[f1e629d] | 649 | char *owl_message_get_direction(owl_message *m) { |
---|
| 650 | switch (m->direction) { |
---|
| 651 | case OWL_MESSAGE_DIRECTION_IN: |
---|
| 652 | return("in"); |
---|
| 653 | case OWL_MESSAGE_DIRECTION_OUT: |
---|
| 654 | return("out"); |
---|
| 655 | case OWL_MESSAGE_DIRECTION_NONE: |
---|
| 656 | return("none"); |
---|
| 657 | default: |
---|
| 658 | return("unknown"); |
---|
| 659 | } |
---|
| 660 | } |
---|
| 661 | |
---|
[dd16bdd] | 662 | int owl_message_parse_direction(char *d) { |
---|
| 663 | if(!strcmp(d, "in")) { |
---|
| 664 | return OWL_MESSAGE_DIRECTION_IN; |
---|
| 665 | } else if(!strcmp(d, "out")) { |
---|
| 666 | return OWL_MESSAGE_DIRECTION_OUT; |
---|
| 667 | } else { |
---|
| 668 | return OWL_MESSAGE_DIRECTION_NONE; |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | |
---|
| 672 | |
---|
[f1e629d] | 673 | char *owl_message_get_login(owl_message *m) { |
---|
| 674 | if (owl_message_is_login(m)) { |
---|
| 675 | return "login"; |
---|
| 676 | } else if (owl_message_is_logout(m)) { |
---|
| 677 | return "logout"; |
---|
| 678 | } else { |
---|
| 679 | return "none"; |
---|
| 680 | } |
---|
| 681 | } |
---|
| 682 | |
---|
[dd16bdd] | 683 | |
---|
[f1e629d] | 684 | char *owl_message_get_header(owl_message *m) { |
---|
| 685 | return owl_message_get_attribute_value(m, "adminheader"); |
---|
| 686 | } |
---|
| 687 | |
---|
[bd3f232] | 688 | /* return 1 if the message contains "string", 0 otherwise. This is |
---|
| 689 | * case insensitive because the functions it uses are |
---|
| 690 | */ |
---|
[0ff8fb57] | 691 | int owl_message_search(owl_message *m, char *string) |
---|
| 692 | { |
---|
[4b464a4] | 693 | |
---|
[f14a7ee] | 694 | owl_message_format(m); /* is this necessary? */ |
---|
[bd3f232] | 695 | |
---|
[4b464a4] | 696 | return (owl_fmtext_search(&(m->fmtext), string)); |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | |
---|
[d559df9] | 700 | /* if loginout == -1 it's a logout message |
---|
| 701 | * 0 it's not a login/logout message |
---|
| 702 | * 1 it's a login message |
---|
| 703 | */ |
---|
| 704 | void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text, int direction, int loginout) |
---|
[0ff8fb57] | 705 | { |
---|
[d09e5a1] | 706 | owl_message_init(m); |
---|
| 707 | owl_message_set_body(m, text); |
---|
| 708 | owl_message_set_sender(m, sender); |
---|
[440ce01] | 709 | owl_message_set_recipient(m, recipient); |
---|
[d09e5a1] | 710 | owl_message_set_type_aim(m); |
---|
[3abf28b] | 711 | |
---|
[d559df9] | 712 | if (direction==OWL_MESSAGE_DIRECTION_IN) { |
---|
| 713 | owl_message_set_direction_in(m); |
---|
| 714 | } else if (direction==OWL_MESSAGE_DIRECTION_OUT) { |
---|
| 715 | owl_message_set_direction_out(m); |
---|
[3abf28b] | 716 | } |
---|
| 717 | |
---|
[d559df9] | 718 | /* for now all messages that aren't loginout are private */ |
---|
| 719 | if (!loginout) { |
---|
| 720 | owl_message_set_isprivate(m); |
---|
| 721 | } |
---|
[3abf28b] | 722 | |
---|
[d559df9] | 723 | if (loginout==-1) { |
---|
| 724 | owl_message_set_islogout(m); |
---|
| 725 | } else if (loginout==1) { |
---|
| 726 | owl_message_set_islogin(m); |
---|
| 727 | } |
---|
[aa5f725] | 728 | } |
---|
| 729 | |
---|
[0ff8fb57] | 730 | void owl_message_create_admin(owl_message *m, char *header, char *text) |
---|
| 731 | { |
---|
[d0d65df] | 732 | owl_message_init(m); |
---|
[4b464a4] | 733 | owl_message_set_type_admin(m); |
---|
[d0d65df] | 734 | owl_message_set_body(m, text); |
---|
[bd3f232] | 735 | owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */ |
---|
[7d4fbcd] | 736 | } |
---|
| 737 | |
---|
[37eab7f] | 738 | /* caller should set the direction */ |
---|
| 739 | void owl_message_create_loopback(owl_message *m, char *text) |
---|
| 740 | { |
---|
| 741 | owl_message_init(m); |
---|
| 742 | owl_message_set_type_loopback(m); |
---|
| 743 | owl_message_set_body(m, text); |
---|
[eec69e1] | 744 | owl_message_set_sender(m, "loopsender"); |
---|
| 745 | owl_message_set_recipient(m, "looprecip"); |
---|
[37eab7f] | 746 | owl_message_set_isprivate(m); |
---|
| 747 | } |
---|
| 748 | |
---|
[09489b89] | 749 | #ifdef HAVE_LIBZEPHYR |
---|
[0ff8fb57] | 750 | void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) |
---|
| 751 | { |
---|
[7d4fbcd] | 752 | struct hostent *hent; |
---|
[d0d65df] | 753 | char *ptr, *tmp, *tmp2; |
---|
[7d4fbcd] | 754 | |
---|
[d0d65df] | 755 | owl_message_init(m); |
---|
| 756 | |
---|
[4b464a4] | 757 | owl_message_set_type_zephyr(m); |
---|
| 758 | owl_message_set_direction_in(m); |
---|
[7d4fbcd] | 759 | |
---|
| 760 | /* first save the full notice */ |
---|
| 761 | memcpy(&(m->notice), n, sizeof(ZNotice_t)); |
---|
| 762 | |
---|
[25dd31a] | 763 | /* a little gross, we'll replace \r's with ' ' for now */ |
---|
[7d4fbcd] | 764 | owl_zephyr_hackaway_cr(&(m->notice)); |
---|
| 765 | |
---|
[25dd31a] | 766 | /* save the time, we need to nuke the string saved by message_init */ |
---|
[5a95b69] | 767 | if (m->timestr) owl_free(m->timestr); |
---|
[25dd31a] | 768 | m->time=n->z_time.tv_sec; |
---|
| 769 | m->timestr=owl_strdup(ctime(&(m->time))); |
---|
| 770 | m->timestr[strlen(m->timestr)-1]='\0'; |
---|
| 771 | |
---|
[7d4fbcd] | 772 | /* set other info */ |
---|
[d0d65df] | 773 | owl_message_set_sender(m, n->z_sender); |
---|
| 774 | owl_message_set_class(m, n->z_class); |
---|
| 775 | owl_message_set_instance(m, n->z_class_inst); |
---|
| 776 | owl_message_set_recipient(m, n->z_recipient); |
---|
[7d4fbcd] | 777 | if (n->z_opcode) { |
---|
[d0d65df] | 778 | owl_message_set_opcode(m, n->z_opcode); |
---|
[7d4fbcd] | 779 | } else { |
---|
[d0d65df] | 780 | owl_message_set_opcode(m, ""); |
---|
[7d4fbcd] | 781 | } |
---|
[d0d65df] | 782 | owl_message_set_zsig(m, n->z_message); |
---|
[7d4fbcd] | 783 | |
---|
| 784 | if ((ptr=strchr(n->z_recipient, '@'))!=NULL) { |
---|
[d0d65df] | 785 | owl_message_set_realm(m, ptr+1); |
---|
[7d4fbcd] | 786 | } else { |
---|
[09489b89] | 787 | owl_message_set_realm(m, owl_zephyr_get_realm()); |
---|
[7d4fbcd] | 788 | } |
---|
| 789 | |
---|
[5789230] | 790 | /* Set the "isloginout" attribute if it's a login message */ |
---|
[1d3e925] | 791 | if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) { |
---|
[5a95b69] | 792 | if (!strcasecmp(n->z_opcode, "user_login") || !strcasecmp(n->z_opcode, "user_logout")) { |
---|
[b0430a6] | 793 | tmp=owl_zephyr_get_field(n, 1); |
---|
[5a95b69] | 794 | owl_message_set_attribute(m, "loginhost", tmp); |
---|
| 795 | owl_free(tmp); |
---|
| 796 | |
---|
[b0430a6] | 797 | tmp=owl_zephyr_get_field(n, 3); |
---|
[5a95b69] | 798 | owl_message_set_attribute(m, "logintty", tmp); |
---|
| 799 | owl_free(tmp); |
---|
| 800 | } |
---|
| 801 | |
---|
[d559df9] | 802 | if (!strcasecmp(n->z_opcode, "user_login")) { |
---|
| 803 | owl_message_set_islogin(m); |
---|
| 804 | } else if (!strcasecmp(n->z_opcode, "user_logout")) { |
---|
| 805 | owl_message_set_islogout(m); |
---|
| 806 | } |
---|
[5789230] | 807 | } |
---|
| 808 | |
---|
[5a95b69] | 809 | |
---|
[9854278] | 810 | /* set the "isprivate" attribute if it's a private zephyr */ |
---|
[09489b89] | 811 | if (!strcasecmp(n->z_recipient, owl_zephyr_get_sender())) { |
---|
[5789230] | 812 | owl_message_set_isprivate(m); |
---|
| 813 | } |
---|
| 814 | |
---|
[9854278] | 815 | /* set the "isauto" attribute if it's an autoreply */ |
---|
| 816 | if (!strcasecmp(n->z_message, "Automated reply:") || |
---|
| 817 | !strcasecmp(n->z_opcode, "auto")) { |
---|
| 818 | owl_message_set_attribute(m, "isauto", ""); |
---|
| 819 | } |
---|
| 820 | |
---|
[7d4fbcd] | 821 | m->zwriteline=strdup(""); |
---|
| 822 | |
---|
[b45293f] | 823 | /* set the body */ |
---|
[b0430a6] | 824 | tmp=owl_zephyr_get_message(n); |
---|
[7e3e00a] | 825 | if (owl_global_is_newlinestrip(&g)) { |
---|
[d0d65df] | 826 | tmp2=owl_util_stripnewlines(tmp); |
---|
| 827 | owl_message_set_body(m, tmp2); |
---|
| 828 | owl_free(tmp2); |
---|
[7e3e00a] | 829 | } else { |
---|
[d0d65df] | 830 | owl_message_set_body(m, tmp); |
---|
[7e3e00a] | 831 | } |
---|
[ecd5dc5] | 832 | owl_free(tmp); |
---|
[7d4fbcd] | 833 | |
---|
[c86a35c] | 834 | #ifdef OWL_ENABLE_ZCRYPT |
---|
[d309eb3] | 835 | /* if zcrypt is enabled try to decrypt the message */ |
---|
| 836 | if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) { |
---|
| 837 | char *out; |
---|
[c269e22] | 838 | int ret; |
---|
[d309eb3] | 839 | |
---|
[d0d65df] | 840 | out=owl_malloc(strlen(owl_message_get_body(m))*16+20); |
---|
[9ceee9d] | 841 | ret=owl_zcrypt_decrypt(out, owl_message_get_body(m), owl_message_get_class(m), owl_message_get_instance(m)); |
---|
[a15a84f] | 842 | if (ret==0) { |
---|
[d0d65df] | 843 | owl_message_set_body(m, out); |
---|
[a15a84f] | 844 | } else { |
---|
| 845 | owl_free(out); |
---|
| 846 | } |
---|
[d309eb3] | 847 | } |
---|
[c269e22] | 848 | #endif |
---|
[d309eb3] | 849 | |
---|
[7d4fbcd] | 850 | /* save the hostname */ |
---|
[3a2daac] | 851 | owl_function_debugmsg("About to do gethostbyaddr"); |
---|
[7d4fbcd] | 852 | hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); |
---|
| 853 | if (hent && hent->h_name) { |
---|
[8298425] | 854 | owl_message_set_hostname(m, hent->h_name); |
---|
[7d4fbcd] | 855 | } else { |
---|
[8298425] | 856 | owl_message_set_hostname(m, inet_ntoa(n->z_sender_addr)); |
---|
[7d4fbcd] | 857 | } |
---|
| 858 | } |
---|
[09489b89] | 859 | #else |
---|
| 860 | void owl_message_create_from_znotice(owl_message *m, void *n) |
---|
| 861 | { |
---|
| 862 | } |
---|
| 863 | #endif |
---|
[7d4fbcd] | 864 | |
---|
[5a95b69] | 865 | /* If 'direction' is '0' it is a login message, '1' is a logout message. */ |
---|
| 866 | void owl_message_create_pseudo_zlogin(owl_message *m, int direction, char *user, char *host, char *time, char *tty) |
---|
| 867 | { |
---|
| 868 | char *longuser, *ptr; |
---|
| 869 | |
---|
[ba9f236] | 870 | #ifdef HAVE_LIBZEPHYR |
---|
[5a95b69] | 871 | memset(&(m->notice), 0, sizeof(ZNotice_t)); |
---|
[ba9f236] | 872 | #endif |
---|
| 873 | |
---|
[5a95b69] | 874 | longuser=long_zuser(user); |
---|
| 875 | |
---|
| 876 | owl_message_init(m); |
---|
| 877 | |
---|
| 878 | owl_message_set_type_zephyr(m); |
---|
| 879 | owl_message_set_direction_in(m); |
---|
| 880 | |
---|
| 881 | owl_message_set_attribute(m, "pseudo", ""); |
---|
| 882 | owl_message_set_attribute(m, "loginhost", host ? host : ""); |
---|
| 883 | owl_message_set_attribute(m, "logintty", tty ? tty : ""); |
---|
| 884 | |
---|
| 885 | owl_message_set_sender(m, longuser); |
---|
| 886 | owl_message_set_class(m, "LOGIN"); |
---|
| 887 | owl_message_set_instance(m, longuser); |
---|
| 888 | owl_message_set_recipient(m, ""); |
---|
| 889 | if (direction==0) { |
---|
| 890 | owl_message_set_opcode(m, "USER_LOGIN"); |
---|
| 891 | owl_message_set_islogin(m); |
---|
| 892 | } else if (direction==1) { |
---|
| 893 | owl_message_set_opcode(m, "USER_LOGOUT"); |
---|
| 894 | owl_message_set_islogout(m); |
---|
| 895 | } |
---|
| 896 | |
---|
| 897 | if ((ptr=strchr(longuser, '@'))!=NULL) { |
---|
| 898 | owl_message_set_realm(m, ptr+1); |
---|
| 899 | } else { |
---|
| 900 | owl_message_set_realm(m, owl_zephyr_get_realm()); |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | m->zwriteline=strdup(""); |
---|
| 904 | |
---|
| 905 | owl_message_set_body(m, "<uninitialized>"); |
---|
| 906 | |
---|
| 907 | /* save the hostname */ |
---|
[2de4f20] | 908 | owl_function_debugmsg("create_pseudo_login: host is %s", host ? host : ""); |
---|
[8298425] | 909 | owl_message_set_hostname(m, host ? host : ""); |
---|
[5a95b69] | 910 | owl_free(longuser); |
---|
| 911 | } |
---|
| 912 | |
---|
[0ff8fb57] | 913 | void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) |
---|
| 914 | { |
---|
[b45293f] | 915 | owl_zwrite z; |
---|
| 916 | int ret; |
---|
[8298425] | 917 | char hostbuff[5000]; |
---|
[b45293f] | 918 | |
---|
[d0d65df] | 919 | owl_message_init(m); |
---|
[b45293f] | 920 | |
---|
| 921 | /* create a zwrite for the purpose of filling in other message fields */ |
---|
| 922 | owl_zwrite_create_from_line(&z, line); |
---|
| 923 | |
---|
| 924 | /* set things */ |
---|
| 925 | owl_message_set_direction_out(m); |
---|
| 926 | owl_message_set_type_zephyr(m); |
---|
[09489b89] | 927 | owl_message_set_sender(m, owl_zephyr_get_sender()); |
---|
[8fec514] | 928 | owl_message_set_class(m, owl_zwrite_get_class(&z)); |
---|
| 929 | owl_message_set_instance(m, owl_zwrite_get_instance(&z)); |
---|
[9ceee9d] | 930 | if (owl_zwrite_get_numrecips(&z)>0) { |
---|
| 931 | owl_message_set_recipient(m, |
---|
| 932 | long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */ |
---|
| 933 | } |
---|
[8fec514] | 934 | owl_message_set_opcode(m, owl_zwrite_get_opcode(&z)); |
---|
[d0d65df] | 935 | owl_message_set_realm(m, owl_zwrite_get_realm(&z)); /* also a hack, but not here */ |
---|
[b45293f] | 936 | m->zwriteline=owl_strdup(line); |
---|
[d0d65df] | 937 | owl_message_set_body(m, body); |
---|
[8fec514] | 938 | owl_message_set_zsig(m, zsig); |
---|
[b45293f] | 939 | |
---|
| 940 | /* save the hostname */ |
---|
[8298425] | 941 | ret=gethostname(hostbuff, MAXHOSTNAMELEN); |
---|
| 942 | hostbuff[MAXHOSTNAMELEN]='\0'; |
---|
[b45293f] | 943 | if (ret) { |
---|
[8298425] | 944 | owl_message_set_hostname(m, "localhost"); |
---|
| 945 | } else { |
---|
| 946 | owl_message_set_hostname(m, hostbuff); |
---|
[b45293f] | 947 | } |
---|
| 948 | owl_zwrite_free(&z); |
---|
[312675c] | 949 | |
---|
| 950 | if(owl_message_is_personal(m)) |
---|
| 951 | owl_message_set_isprivate(m); |
---|
[b45293f] | 952 | } |
---|
[7d4fbcd] | 953 | |
---|
[0ff8fb57] | 954 | void owl_message_pretty_zsig(owl_message *m, char *buff) |
---|
| 955 | { |
---|
[b45293f] | 956 | /* stick a one line version of the zsig in buff */ |
---|
[7d4fbcd] | 957 | char *ptr; |
---|
| 958 | |
---|
[d0d65df] | 959 | strcpy(buff, owl_message_get_zsig(m)); |
---|
[b45293f] | 960 | ptr=strchr(buff, '\n'); |
---|
| 961 | if (ptr) ptr[0]='\0'; |
---|
[7d4fbcd] | 962 | } |
---|
| 963 | |
---|
[0ff8fb57] | 964 | void owl_message_free(owl_message *m) |
---|
| 965 | { |
---|
[d0d65df] | 966 | int i, j; |
---|
| 967 | owl_pair *p; |
---|
[09489b89] | 968 | #ifdef HAVE_LIBZEPHYR |
---|
[4b464a4] | 969 | if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) { |
---|
[7d4fbcd] | 970 | ZFreeNotice(&(m->notice)); |
---|
| 971 | } |
---|
[09489b89] | 972 | #endif |
---|
[25dd31a] | 973 | if (m->timestr) owl_free(m->timestr); |
---|
[7d4fbcd] | 974 | if (m->zwriteline) owl_free(m->zwriteline); |
---|
[d0d65df] | 975 | |
---|
| 976 | /* free all the attributes */ |
---|
| 977 | j=owl_list_get_size(&(m->attributes)); |
---|
| 978 | for (i=0; i<j; i++) { |
---|
| 979 | p=owl_list_get_element(&(m->attributes), i); |
---|
| 980 | owl_free(owl_pair_get_value(p)); |
---|
| 981 | owl_free(p); |
---|
| 982 | } |
---|
| 983 | |
---|
| 984 | owl_list_free_simple(&(m->attributes)); |
---|
[7d4fbcd] | 985 | |
---|
| 986 | owl_fmtext_free(&(m->fmtext)); |
---|
| 987 | } |
---|