- Timestamp:
- Jun 10, 2003, 3:14:59 PM (21 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:
- f14a7ee
- Parents:
- 6e05655
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
message.c
rd559df9 rbd3f232 24 24 strcpy(m->hostname, ""); 25 25 m->zwriteline=strdup(""); 26 m->invalid_format=1; 26 27 27 28 owl_list_create(&(m->attributes)); … … 31 32 m->time=owl_strdup(ctime(&t)); 32 33 m->time[strlen(m->time)-1]='\0'; 34 owl_fmtext_init_null(&(m->fmtext)); 33 35 } 34 36 … … 98 100 } 99 101 102 void owl_message_invalidate_format(owl_message *m) 103 { 104 m->invalid_format=1; 105 } 106 100 107 owl_fmtext *owl_message_get_fmtext(owl_message *m) 101 108 { 109 owl_style *s; 110 111 /* if the format is invalid, regenerate the text based on the 112 * current style 113 */ 114 if (m->invalid_format) { 115 owl_fmtext_free(&(m->fmtext)); 116 owl_fmtext_init_null(&(m->fmtext)); 117 s=owl_global_get_current_style(&g); 118 owl_style_get_formattext(s, &(m->fmtext), m); 119 m->invalid_format=0; 120 } 102 121 return(&(m->fmtext)); 103 122 } … … 371 390 { 372 391 if (m == NULL) return(0); 392 (void) owl_message_get_fmtext(m); 373 393 return(owl_fmtext_num_lines(&(m->fmtext))); 374 394 } … … 417 437 { 418 438 owl_fmtext a, b; 439 440 /* this will ensure that our cached copy is up to date */ 441 (void) owl_message_get_fmtext(m); 419 442 420 443 owl_fmtext_init_null(&a); … … 538 561 return(m->id); 539 562 } 540 563 564 /* return 1 if the message contains "string", 0 otherwise. This is 565 * case insensitive because the functions it uses are 566 */ 541 567 int owl_message_search(owl_message *m, char *string) 542 568 { 543 /* return 1 if the message contains "string", 0 otherwise. This is 544 * case insensitive because the functions it uses are*/545 569 570 (void) owl_message_get_fmtext(m); /* is this necessary? */ 571 546 572 return (owl_fmtext_search(&(m->fmtext), string)); 547 573 } 548 574 549 void owl_message_create(owl_message *m, char *header, char *text)550 {551 char *indent;552 553 owl_message_init(m);554 owl_message_set_body(m, text);555 556 indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);557 owl_text_indent(indent, text, OWL_MSGTAB);558 owl_fmtext_init_null(&(m->fmtext));559 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);560 owl_fmtext_append_ztext(&(m->fmtext), header);561 owl_fmtext_append_normal(&(m->fmtext), "\n");562 owl_fmtext_append_ztext(&(m->fmtext), indent);563 if (text[strlen(text)-1]!='\n') {564 owl_fmtext_append_normal(&(m->fmtext), "\n");565 }566 567 owl_free(indent);568 }569 575 570 576 /* if loginout == -1 it's a logout message … … 596 602 owl_message_set_islogin(m); 597 603 } 598 599 /* create the formatted message */600 if (owl_global_is_config_format(&g)) {601 _owl_message_make_text_from_config(m);602 } else {603 _owl_message_make_text_from_aim(m);604 }605 }606 607 void _owl_message_make_text_from_aim(owl_message *m)608 {609 char *indent;610 611 if (owl_message_is_loginout(m)) {612 owl_fmtext_init_null(&(m->fmtext));613 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);614 if (owl_message_is_login(m)) {615 owl_fmtext_append_bold(&(m->fmtext), "AIM LOGIN");616 } else {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), owl_message_get_sender(m));621 owl_fmtext_append_normal(&(m->fmtext), "\n");622 } else if (owl_message_is_direction_in(m)) {623 indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);624 owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);625 owl_fmtext_init_null(&(m->fmtext));626 owl_fmtext_append_bold(&(m->fmtext), OWL_TABSTR);627 owl_fmtext_append_bold(&(m->fmtext), "AIM from ");628 owl_fmtext_append_bold(&(m->fmtext), owl_message_get_sender(m));629 owl_fmtext_append_bold(&(m->fmtext), "\n");630 owl_fmtext_append_bold(&(m->fmtext), indent);631 if (indent[strlen(indent)-1]!='\n') {632 owl_fmtext_append_normal(&(m->fmtext), "\n");633 }634 owl_free(indent);635 } else if (owl_message_is_direction_out(m)) {636 indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);637 owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);638 owl_fmtext_init_null(&(m->fmtext));639 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);640 owl_fmtext_append_normal(&(m->fmtext), "AIM sent to ");641 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_recipient(m));642 owl_fmtext_append_normal(&(m->fmtext), "\n");643 owl_fmtext_append_ztext(&(m->fmtext), indent);644 if (indent[strlen(indent)-1]!='\n') {645 owl_fmtext_append_normal(&(m->fmtext), "\n");646 }647 owl_free(indent);648 }649 604 } 650 605 651 606 void owl_message_create_admin(owl_message *m, char *header, char *text) 652 607 { 653 char *indent;654 655 608 owl_message_init(m); 656 609 owl_message_set_type_admin(m); 657 658 610 owl_message_set_body(m, text); 659 660 /* do something to make it clear the notice shouldn't be used for now */ 661 662 indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10); 663 owl_text_indent(indent, text, OWL_MSGTAB); 664 owl_fmtext_init_null(&(m->fmtext)); 665 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR); 666 owl_fmtext_append_bold(&(m->fmtext), "OWL ADMIN "); 667 owl_fmtext_append_ztext(&(m->fmtext), header); 668 owl_fmtext_append_normal(&(m->fmtext), "\n"); 669 owl_fmtext_append_ztext(&(m->fmtext), indent); 670 if (text[strlen(text)-1]!='\n') { 671 owl_fmtext_append_normal(&(m->fmtext), "\n"); 672 } 673 674 owl_free(indent); 611 owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */ 675 612 } 676 613 … … 770 707 m->time=owl_strdup(ctime((time_t *) &n->z_time.tv_sec)); 771 708 m->time[strlen(m->time)-1]='\0'; 772 773 /* create the formatted message */774 if (owl_global_is_config_format(&g)) {775 _owl_message_make_text_from_config(m);776 } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {777 _owl_message_make_text_from_notice_standard(m);778 } else {779 _owl_message_make_text_from_notice_simple(m);780 }781 782 709 } 783 710 … … 812 739 } 813 740 814 /* create the formatted message */815 if (owl_global_is_config_format(&g)) {816 _owl_message_make_text_from_config(m);817 } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {818 _owl_message_make_text_from_zwriteline_standard(m);819 } else {820 _owl_message_make_text_from_zwriteline_simple(m);821 }822 823 741 owl_zwrite_free(&z); 824 742 } 825 743 826 void _owl_message_make_text_from_config(owl_message *m)827 {828 char *body, *indent;829 830 owl_fmtext_init_null(&(m->fmtext));831 832 /* get body from the config */833 body=owl_config_getmsg(m, 1);834 835 /* indent */836 indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_TAB+10);837 owl_text_indent(indent, body, OWL_TAB);838 839 /* fmtext_append. This needs to change */840 owl_fmtext_append_ztext(&(m->fmtext), indent);841 842 owl_free(indent);843 owl_free(body);844 }845 846 void _owl_message_make_text_from_zwriteline_standard(owl_message *m)847 {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), "Zephyr sent 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 862 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);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);875 }876 877 void _owl_message_make_text_from_zwriteline_simple(owl_message *m)878 {879 char *indent, *text, *zsigbuff, *foo;880 881 text=owl_message_get_body(m);882 883 indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);884 owl_text_indent(indent, text, OWL_MSGTAB);885 owl_fmtext_init_null(&(m->fmtext));886 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);887 owl_fmtext_append_normal(&(m->fmtext), "To: ");888 foo=short_zuser(owl_message_get_recipient(m));889 owl_fmtext_append_normal(&(m->fmtext), foo);890 owl_free(foo);891 owl_fmtext_append_normal(&(m->fmtext), " (Zsig: ");892 893 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);894 owl_message_pretty_zsig(m, zsigbuff);895 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);896 owl_free(zsigbuff);897 898 owl_fmtext_append_normal(&(m->fmtext), ")");899 owl_fmtext_append_normal(&(m->fmtext), "\n");900 owl_fmtext_append_ztext(&(m->fmtext), indent);901 if (text[strlen(text)-1]!='\n') {902 owl_fmtext_append_normal(&(m->fmtext), "\n");903 }904 905 owl_free(indent);906 }907 908 void _owl_message_make_text_from_notice_standard(owl_message *m)909 {910 char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];911 ZNotice_t *n;912 913 n=&(m->notice);914 915 /* get the body */916 body=owl_malloc(strlen(owl_message_get_body(m))+30);917 strcpy(body, owl_message_get_body(m));918 919 /* add a newline if we need to */920 if (body[0]!='\0' && body[strlen(body)-1]!='\n') {921 strcat(body, "\n");922 }923 924 /* do the indenting into indent */925 indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);926 owl_text_indent(indent, body, OWL_MSGTAB);927 928 /* edit the from addr for printing */929 strcpy(frombuff, owl_message_get_sender(m));930 ptr=strchr(frombuff, '@');931 if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {932 *ptr='\0';933 }934 935 /* set the message for printing */936 owl_fmtext_init_null(&(m->fmtext));937 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);938 939 if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) {940 owl_fmtext_append_bold(&(m->fmtext), "PING");941 owl_fmtext_append_normal(&(m->fmtext), " from ");942 owl_fmtext_append_bold(&(m->fmtext), frombuff);943 owl_fmtext_append_normal(&(m->fmtext), "\n");944 } else if (!strcasecmp(n->z_class, "login")) {945 char *ptr, host[LINE], tty[LINE];946 int len;947 948 ptr=owl_zephyr_get_field(n, 1, &len);949 strncpy(host, ptr, len);950 host[len]='\0';951 ptr=owl_zephyr_get_field(n, 3, &len);952 strncpy(tty, ptr, len);953 tty[len]='\0';954 955 if (!strcasecmp(n->z_opcode, "user_login")) {956 owl_fmtext_append_bold(&(m->fmtext), "LOGIN");957 } else if (!strcasecmp(n->z_opcode, "user_logout")) {958 owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");959 }960 owl_fmtext_append_normal(&(m->fmtext), " for ");961 ptr=short_zuser(n->z_class_inst);962 owl_fmtext_append_bold(&(m->fmtext), ptr);963 owl_free(ptr);964 owl_fmtext_append_normal(&(m->fmtext), " at ");965 owl_fmtext_append_normal(&(m->fmtext), host);966 owl_fmtext_append_normal(&(m->fmtext), " ");967 owl_fmtext_append_normal(&(m->fmtext), tty);968 owl_fmtext_append_normal(&(m->fmtext), "\n");969 } else {970 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m));971 owl_fmtext_append_normal(&(m->fmtext), " / ");972 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m));973 owl_fmtext_append_normal(&(m->fmtext), " / ");974 owl_fmtext_append_bold(&(m->fmtext), frombuff);975 if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {976 owl_fmtext_append_normal(&(m->fmtext), " {");977 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m));978 owl_fmtext_append_normal(&(m->fmtext), "} ");979 }980 if (n->z_opcode[0]!='\0') {981 owl_fmtext_append_normal(&(m->fmtext), " [");982 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_opcode(m));983 owl_fmtext_append_normal(&(m->fmtext), "] ");984 }985 986 /* stick on the zsig */987 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);988 owl_message_pretty_zsig(m, zsigbuff);989 owl_fmtext_append_normal(&(m->fmtext), " (");990 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);991 owl_fmtext_append_normal(&(m->fmtext), ")");992 owl_fmtext_append_normal(&(m->fmtext), "\n");993 owl_free(zsigbuff);994 995 /* then the indented message */996 owl_fmtext_append_ztext(&(m->fmtext), indent);997 998 /* make private messages bold for smaat users */999 if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {1000 if (owl_message_is_personal(m)) {1001 owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);1002 }1003 }1004 }1005 1006 owl_free(body);1007 owl_free(indent);1008 }1009 1010 void _owl_message_make_text_from_notice_simple(owl_message *m)1011 {1012 char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];1013 ZNotice_t *n;1014 1015 n=&(m->notice);1016 1017 /* get the body */1018 body=owl_strdup(owl_message_get_body(m));1019 body=realloc(body, strlen(body)+30);1020 1021 /* add a newline if we need to */1022 if (body[0]!='\0' && body[strlen(body)-1]!='\n') {1023 strcat(body, "\n");1024 }1025 1026 /* do the indenting into indent */1027 indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);1028 owl_text_indent(indent, body, OWL_MSGTAB);1029 1030 /* edit the from addr for printing */1031 strcpy(frombuff, owl_message_get_sender(m));1032 ptr=strchr(frombuff, '@');1033 if (ptr && !strncmp(ptr+1, ZGetRealm(), strlen(ZGetRealm()))) {1034 *ptr='\0';1035 }1036 1037 /* set the message for printing */1038 owl_fmtext_init_null(&(m->fmtext));1039 owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);1040 1041 if (!strcasecmp(owl_message_get_opcode(m), "ping")) {1042 owl_fmtext_append_bold(&(m->fmtext), "PING");1043 owl_fmtext_append_normal(&(m->fmtext), " from ");1044 owl_fmtext_append_bold(&(m->fmtext), frombuff);1045 owl_fmtext_append_normal(&(m->fmtext), "\n");1046 } else if (!strcasecmp(owl_message_get_class(m), "login")) {1047 char *ptr, host[LINE], tty[LINE];1048 int len;1049 1050 ptr=owl_zephyr_get_field(n, 1, &len);1051 strncpy(host, ptr, len);1052 host[len]='\0';1053 ptr=owl_zephyr_get_field(n, 3, &len);1054 strncpy(tty, ptr, len);1055 tty[len]='\0';1056 1057 if (!strcasecmp(owl_message_get_opcode(m), "user_login")) {1058 owl_fmtext_append_bold(&(m->fmtext), "LOGIN");1059 } else if (!strcasecmp(owl_message_get_opcode(m), "user_logout")) {1060 owl_fmtext_append_bold(&(m->fmtext), "LOGOUT");1061 }1062 owl_fmtext_append_normal(&(m->fmtext), " for ");1063 ptr=short_zuser(owl_message_get_instance(m));1064 owl_fmtext_append_bold(&(m->fmtext), ptr);1065 owl_free(ptr);1066 owl_fmtext_append_normal(&(m->fmtext), " at ");1067 owl_fmtext_append_normal(&(m->fmtext), host);1068 owl_fmtext_append_normal(&(m->fmtext), " ");1069 owl_fmtext_append_normal(&(m->fmtext), tty);1070 owl_fmtext_append_normal(&(m->fmtext), "\n");1071 } else {1072 owl_fmtext_append_normal(&(m->fmtext), "From: ");1073 if (strcasecmp(owl_message_get_class(m), "message")) {1074 owl_fmtext_append_normal(&(m->fmtext), "Class ");1075 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_class(m));1076 owl_fmtext_append_normal(&(m->fmtext), " / Instance ");1077 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_instance(m));1078 owl_fmtext_append_normal(&(m->fmtext), " / ");1079 }1080 owl_fmtext_append_normal(&(m->fmtext), frombuff);1081 if (strcasecmp(owl_message_get_realm(m), ZGetRealm())) {1082 owl_fmtext_append_normal(&(m->fmtext), " {");1083 owl_fmtext_append_normal(&(m->fmtext), owl_message_get_realm(m));1084 owl_fmtext_append_normal(&(m->fmtext), "} ");1085 }1086 1087 /* stick on the zsig */1088 zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m))+30);1089 owl_message_pretty_zsig(m, zsigbuff);1090 owl_fmtext_append_normal(&(m->fmtext), " (");1091 owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);1092 owl_fmtext_append_normal(&(m->fmtext), ")");1093 owl_fmtext_append_normal(&(m->fmtext), "\n");1094 owl_free(zsigbuff);1095 1096 /* then the indented message */1097 owl_fmtext_append_ztext(&(m->fmtext), indent);1098 1099 /* make personal messages bold for smaat users */1100 if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {1101 if (owl_message_is_personal(m)) {1102 owl_fmtext_addattr((&m->fmtext), OWL_FMTEXT_ATTR_BOLD);1103 }1104 }1105 }1106 1107 owl_free(body);1108 owl_free(indent);1109 }1110 744 1111 745 void owl_message_pretty_zsig(owl_message *m, char *buff)
Note: See TracChangeset
for help on using the changeset viewer.