- Timestamp:
- Oct 11, 2002, 11:56:23 PM (22 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 68b41b0
- Parents:
- 2adaf1d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
message.c
r3a2daac rb45293f 1 1 #include <zephyr/zephyr.h> 2 2 #include <stdlib.h> 3 #include <unistd.h> 3 4 #include <string.h> 4 5 #include <sys/socket.h> … … 26 27 m->opcode=owl_strdup(""); 27 28 m->realm=owl_strdup(""); 29 m->zsig=owl_strdup(""); 28 30 strcpy(m->hostname, ""); 29 31 m->zwriteline=strdup(""); … … 65 67 char *owl_message_get_sender(owl_message *m) { 66 68 return(m->sender); 69 } 70 71 void owl_message_set_zsig(owl_message *m, char *zsig) { 72 if (m->zsig) owl_free(m->zsig); 73 m->zsig=owl_strdup(zsig); 74 } 75 76 char *owl_message_get_zsig(owl_message *m) { 77 return(m->zsig); 67 78 } 68 79 … … 347 358 } 348 359 349 void owl_message_create_from_z ephyr(owl_message *m, ZNotice_t *n) {360 void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) { 350 361 struct hostent *hent; 351 362 int k; … … 374 385 n->z_opcode=owl_strdup(""); 375 386 } 387 m->zsig=owl_strdup(n->z_message); 376 388 377 389 if ((ptr=strchr(n->z_recipient, '@'))!=NULL) { … … 383 395 m->zwriteline=strdup(""); 384 396 397 /* set the body */ 385 398 ptr=owl_zephyr_get_message(n, &k); 386 399 m->body=owl_malloc(k+10); … … 412 425 } 413 426 427 void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) { 428 owl_zwrite z; 429 int ret; 430 431 owl_message_init_raw(m); 432 433 /* create a zwrite for the purpose of filling in other message fields */ 434 owl_zwrite_create_from_line(&z, line); 435 436 /* set things */ 437 owl_message_set_direction_out(m); 438 owl_message_set_type_zephyr(m); 439 m->sender=owl_strdup(ZGetSender()); 440 m->class=owl_strdup(owl_zwrite_get_class(&z)); 441 m->inst=owl_strdup(owl_zwrite_get_instance(&z)); 442 m->recip=long_zuser(owl_zwrite_get_recip_n(&z, 0)); /* only gets the first user, must fix */ 443 owl_zwrite_get_recipstr(&z, m->recip); 444 m->opcode=owl_strdup(owl_zwrite_get_opcode(&z)); 445 m->realm=owl_strdup(owl_zwrite_get_realm(&z)); /* also a hack, but not here */ 446 m->zwriteline=owl_strdup(line); 447 m->body=owl_strdup(body); 448 m->zsig=owl_strdup(zsig); 449 450 /* save the hostname */ 451 ret=gethostname(m->hostname, MAXHOSTNAMELEN); 452 if (ret) { 453 strcpy(m->hostname, "localhost"); 454 } 455 456 /* create the formatted message */ 457 if (owl_global_is_config_format(&g)) { 458 _owl_message_make_text_from_config(m); 459 } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) { 460 _owl_message_make_text_from_zwriteline_standard(m); 461 } else { 462 _owl_message_make_text_from_zwriteline_simple(m); 463 } 464 465 owl_zwrite_free(&z); 466 } 414 467 415 468 void _owl_message_make_text_from_config(owl_message *m) { … … 432 485 } 433 486 487 void _owl_message_make_text_from_zwriteline_standard(owl_message *m) { 488 char *indent, *text, *zsigbuff; 489 490 text=owl_message_get_body(m); 491 492 indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); 493 owl_text_indent(indent, text, OWL_MSGTAB); 494 owl_fmtext_init_null(&(m->fmtext)); 495 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); 496 owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to "); 497 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_recipient(m)); 498 owl_fmtext_append_normal(&(m->fmtext), " (Zsig: "); 499 500 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))); 501 owl_message_pretty_zsig(m, zsigbuff); 502 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); 503 owl_free(zsigbuff); 504 505 owl_fmtext_append_normal(&(m->fmtext), ")"); 506 owl_fmtext_append_normal(&(m->fmtext), "\n"); 507 owl_fmtext_append_ztext(&(m->fmtext), indent); 508 if (text[strlen(text)-1]!='\n') { 509 owl_fmtext_append_normal(&(m->fmtext), "\n"); 510 } 511 512 owl_free(indent); 513 } 514 515 void _owl_message_make_text_from_zwriteline_simple(owl_message *m) { 516 _owl_message_make_text_from_zwriteline_standard(m); 517 } 518 434 519 void _owl_message_make_text_from_notice_standard(owl_message *m) { 435 char *body, *indent, *ptr; 436 char frombuff[1024]; 437 char zsigbuff[LINE]; 520 char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; 438 521 ZNotice_t *n; 439 522 int len; … … 514 597 515 598 /* stick on the zsig */ 516 _owl_message_get_zsig(m, zsigbuff, LINE); 517 if (zsigbuff[0]!='\0') { 518 owl_fmtext_append_normal(&(m->fmtext), " ("); 519 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); 520 owl_fmtext_append_normal(&(m->fmtext), ")"); 521 } 522 owl_fmtext_append_normal(&(m->fmtext), "\n"); 599 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))); 600 owl_message_pretty_zsig(m, zsigbuff); 601 owl_fmtext_append_normal(&(m->fmtext), " ("); 602 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); 603 owl_fmtext_append_normal(&(m->fmtext), ")"); 604 owl_fmtext_append_normal(&(m->fmtext), "\n"); 605 owl_free(zsigbuff); 606 607 /* then the indented message */ 523 608 owl_fmtext_append_ztext(&(m->fmtext), indent); 524 609 … … 536 621 537 622 void _owl_message_make_text_from_notice_simple(owl_message *m) { 538 char *body, *indent, *ptr; 539 char frombuff[1024]; 540 char zsigbuff[LINE]; 623 char *body, *indent, *ptr, *zsigbuff, frombuff[LINE]; 541 624 ZNotice_t *n; 542 625 int len; … … 616 699 617 700 /* stick on the zsig */ 618 _owl_message_get_zsig(m, zsigbuff, LINE); 619 if (zsigbuff[0]!='\0') { 620 owl_fmtext_append_normal(&(m->fmtext), " ("); 621 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); 622 owl_fmtext_append_normal(&(m->fmtext), ")"); 623 } 624 owl_fmtext_append_normal(&(m->fmtext), "\n"); 701 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))); 702 owl_message_pretty_zsig(m, zsigbuff); 703 owl_fmtext_append_normal(&(m->fmtext), " ("); 704 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff); 705 owl_fmtext_append_normal(&(m->fmtext), ")"); 706 owl_fmtext_append_normal(&(m->fmtext), "\n"); 707 owl_free(zsigbuff); 708 709 /* then the indented message */ 625 710 owl_fmtext_append_ztext(&(m->fmtext), indent); 626 711 … … 637 722 } 638 723 639 void _owl_message_get_zsig(owl_message *m, char *buff, int size) { 724 void owl_message_pretty_zsig(owl_message *m, char *buff) { 725 /* stick a one line version of the zsig in buff */ 640 726 char *ptr; 641 ZNotice_t n; 642 int len; 643 /* just a hackish thing for now. We'll only present the first line 644 or the first 'size'. characters. If the message is not 645 appropriate for having a zsig we'll return an empty string */ 646 n=m->notice; 647 648 649 /* bail if it shouldn't have a zsig */ 650 buff[0]='\0'; 651 if (!strcasecmp(n.z_opcode, "ping")) { 652 return; 653 } 654 655 /* find the right length to copy */ 656 len=strlen(n.z_message); 657 if (size < len) { 658 len=size; 659 } 660 if ((ptr=strchr(n.z_message, '\n'))!=NULL) { 661 if ((ptr-n.z_message) < len) { 662 len=ptr-n.z_message; 663 } 664 } 665 666 /* copy */ 667 strncpy(buff, n.z_message, len); 668 buff[len]='\0'; 669 } 670 727 728 strcpy(buff, m->zsig); 729 ptr=strchr(buff, '\n'); 730 if (ptr) ptr[0]='\0'; 731 } 671 732 672 733 void owl_message_free(owl_message *m) {
Note: See TracChangeset
for help on using the changeset viewer.