Changes in message.c [259e60a8:2354e9a]
Legend:
- Unmodified
- Added
- Removed
-
message.c
r259e60a8 r2354e9a 1 #include <stdlib.h>2 #include <unistd.h>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 1 #include "owl.h" 12 2 #include "filterproc.h" 3 #include <sys/socket.h> 4 #include <arpa/inet.h> 13 5 14 6 static owl_fmtext_cache fmtext_cache[OWL_FMTEXT_CACHE_SIZE]; … … 42 34 m->delete=0; 43 35 36 #ifdef HAVE_LIBZEPHYR 37 m->has_notice = false; 38 #endif 39 44 40 owl_message_set_hostname(m, ""); 45 owl_list_create(&(m->attributes));41 m->attributes = g_ptr_array_new(); 46 42 47 43 /* save the time */ 48 m->time =time(NULL);49 m->timestr =g_strdup(ctime(&(m->time)));50 m->timestr[strlen(m->timestr)-1] ='\0';44 m->time = time(NULL); 45 m->timestr = g_strdup(ctime(&m->time)); 46 m->timestr[strlen(m->timestr)-1] = '\0'; 51 47 52 48 m->fmtext = NULL; … … 58 54 void owl_message_set_attribute(owl_message *m, const char *attrname, const char *attrvalue) 59 55 { 60 int i , j;56 int i; 61 57 owl_pair *p = NULL, *pair = NULL; 62 58 … … 64 60 65 61 /* look for an existing pair with this key, */ 66 j=owl_list_get_size(&(m->attributes)); 67 for (i=0; i<j; i++) { 68 p=owl_list_get_element(&(m->attributes), i); 62 for (i = 0; i < m->attributes->len; i++) { 63 p = m->attributes->pdata[i]; 69 64 if (owl_pair_get_key(p) == attrname) { 70 65 g_free(owl_pair_get_value(p)); … … 77 72 pair = g_new(owl_pair, 1); 78 73 owl_pair_create(pair, attrname, NULL); 79 owl_list_append_element(&(m->attributes), pair);74 g_ptr_array_add(m->attributes, pair); 80 75 } 81 76 owl_pair_set_value(pair, owl_validate_or_convert(attrvalue)); … … 87 82 const char *owl_message_get_attribute_value(const owl_message *m, const char *attrname) 88 83 { 89 int i , j;84 int i; 90 85 owl_pair *p; 91 86 GQuark quark; … … 97 92 attrname = g_quark_to_string(quark); 98 93 99 j=owl_list_get_size(&(m->attributes)); 100 for (i=0; i<j; i++) { 101 p=owl_list_get_element(&(m->attributes), i); 94 for (i = 0; i < m->attributes->len; i++) { 95 p = m->attributes->pdata[i]; 102 96 if (owl_pair_get_key(p) == attrname) { 103 97 return(owl_pair_get_value(p)); … … 118 112 */ 119 113 void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm) { 120 int i , j;114 int i; 121 115 owl_pair *p; 122 116 char *buff, *tmpbuff; … … 124 118 owl_fmtext_init_null(fm); 125 119 126 j=owl_list_get_size(&(m->attributes)); 127 for (i=0; i<j; i++) { 128 p=owl_list_get_element(&(m->attributes), i); 129 130 tmpbuff = g_strdup(owl_pair_get_value(p)); 131 g_strdelimit(tmpbuff, "\n", '~'); 132 g_strdelimit(tmpbuff, "\r", '!'); 133 buff = g_strdup_printf(" %-15.15s: %s\n", owl_pair_get_key(p), tmpbuff); 134 g_free(tmpbuff); 120 for (i = 0; i < m->attributes->len; i++) { 121 p = m->attributes->pdata[i]; 122 123 buff = g_strdup(owl_pair_get_value(p)); 124 if (buff) { 125 tmpbuff = owl_text_indent(buff, 19, false); 126 g_free(buff); 127 buff = g_strdup_printf(" %-15.15s: %s\n", owl_pair_get_key(p), tmpbuff); 128 g_free(tmpbuff); 129 } 135 130 136 131 if(buff == NULL) { … … 352 347 } 353 348 349 CALLER_OWN char *owl_message_format_time(const owl_message *m) 350 { 351 return owl_util_format_time(localtime(&m->time)); 352 } 353 354 354 void owl_message_set_type_admin(owl_message *m) 355 355 { … … 500 500 const ZNotice_t *owl_message_get_notice(const owl_message *m) 501 501 { 502 return (&(m->notice));502 return m->has_notice ? &m->notice : NULL; 503 503 } 504 504 #else … … 580 580 581 581 /* caller must free return value. */ 582 char *owl_message_get_cc(const owl_message *m)582 CALLER_OWN char *owl_message_get_cc(const owl_message *m) 583 583 { 584 584 const char *cur; … … 597 597 598 598 /* caller must free return value */ 599 GList *owl_message_get_cc_without_recipient(const owl_message *m)599 CALLER_OWN GList *owl_message_get_cc_without_recipient(const owl_message *m) 600 600 { 601 601 char *cc, *shortuser, *recip; … … 791 791 /* first save the full notice */ 792 792 m->notice = *n; 793 m->has_notice = true; 793 794 794 795 /* a little gross, we'll replace \r's with ' ' for now */ … … 797 798 /* save the time, we need to nuke the string saved by message_init */ 798 799 if (m->timestr) g_free(m->timestr); 799 m->time =n->z_time.tv_sec;800 m->timestr =g_strdup(ctime(&(m->time)));801 m->timestr[strlen(m->timestr)-1] ='\0';800 m->time = n->z_time.tv_sec; 801 m->timestr = g_strdup(ctime(&m->time)); 802 m->timestr[strlen(m->timestr)-1] = '\0'; 802 803 803 804 /* set other info */ … … 835 836 836 837 837 /* set the "isprivate" attribute if it's a private zephyr. 838 ``private'' means recipient is non-empty and doesn't start wit 839 `@' */ 840 if (*n->z_recipient && *n->z_recipient != '@') { 838 /* set the "isprivate" attribute if it's a private zephyr. */ 839 if (owl_zwrite_recip_is_personal(n->z_recipient)) { 841 840 owl_message_set_isprivate(m); 842 841 } … … 876 875 if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) { 877 876 const char *argv[] = { 878 "zcrypt",877 NULL, 879 878 "-D", 880 879 "-c", owl_message_get_class(m), … … 882 881 NULL 883 882 }; 884 char *out ;883 char *out = NULL; 885 884 int rv; 886 885 int status; 887 886 char *zcrypt; 888 887 889 zcrypt = g_strdup_printf("%s/zcrypt", owl_get_bindir()); 890 891 rv = call_filter(zcrypt, argv, owl_message_get_body(m), &out, &status); 888 zcrypt = g_build_filename(owl_get_bindir(), "zcrypt", NULL); 889 argv[0] = zcrypt; 890 891 rv = call_filter(argv, owl_message_get_body(m), &out, &status); 892 892 g_free(zcrypt); 893 893 … … 898 898 } 899 899 owl_message_set_body(m, out); 900 g_free(out); 901 } else if(out) { 902 g_free(out); 903 } 900 } else { 901 /* Replace the opcode. Otherwise the UI and other bits of code think the 902 * message was encrypted. */ 903 owl_message_set_opcode(m, "failed-decrypt"); 904 } 905 g_free(out); 904 906 } 905 907 … … 1004 1006 void owl_message_cleanup(owl_message *m) 1005 1007 { 1006 int i , j;1008 int i; 1007 1009 owl_pair *p; 1008 1010 #ifdef HAVE_LIBZEPHYR 1009 if ( owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {1011 if (m->has_notice) { 1010 1012 ZFreeNotice(&(m->notice)); 1011 1013 } … … 1014 1016 1015 1017 /* free all the attributes */ 1016 j=owl_list_get_size(&(m->attributes)); 1017 for (i=0; i<j; i++) { 1018 p=owl_list_get_element(&(m->attributes), i); 1018 for (i = 0; i < m->attributes->len; i++) { 1019 p = m->attributes->pdata[i]; 1019 1020 g_free(owl_pair_get_value(p)); 1020 1021 g_free(p); 1021 1022 } 1022 1023 1023 owl_list_cleanup(&(m->attributes), NULL);1024 g_ptr_array_free(m->attributes, true); 1024 1025 1025 1026 owl_message_invalidate_format(m);
Note: See TracChangeset
for help on using the changeset viewer.