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