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