Changeset 8f95fc4
- Timestamp:
- Dec 25, 2013, 2:45:30 PM (11 years ago)
- Children:
- 58777e9
- Parents:
- 7dcef03
- git-author:
- Anders Kaseorg <andersk@mit.edu> (12/25/13 12:17:55)
- git-committer:
- Anders Kaseorg <andersk@mit.edu> (12/25/13 14:45:30)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
message.c
r7dcef03 r8f95fc4 39 39 40 40 owl_message_set_hostname(m, ""); 41 m->attributes = g_ptr_array_new();41 g_datalist_init(&m->attributes); 42 42 43 43 /* save the time */ … … 54 54 void owl_message_set_attribute(owl_message *m, const char *attrname, const char *attrvalue) 55 55 { 56 int i; 57 owl_pair *p = NULL, *pair = NULL; 58 59 attrname = g_intern_string(attrname); 60 61 /* look for an existing pair with this key, */ 62 for (i = 0; i < m->attributes->len; i++) { 63 p = m->attributes->pdata[i]; 64 if (owl_pair_get_key(p) == attrname) { 65 g_free(owl_pair_get_value(p)); 66 pair = p; 67 break; 68 } 69 } 70 71 if(pair == NULL) { 72 pair = g_slice_new(owl_pair); 73 owl_pair_create(pair, attrname, NULL); 74 g_ptr_array_add(m->attributes, pair); 75 } 76 owl_pair_set_value(pair, owl_validate_or_convert(attrvalue)); 56 g_datalist_set_data_full(&m->attributes, attrname, 57 owl_validate_or_convert(attrvalue), g_free); 77 58 } 78 59 … … 82 63 const char *owl_message_get_attribute_value(const owl_message *m, const char *attrname) 83 64 { 84 int i; 85 owl_pair *p; 86 GQuark quark; 87 88 quark = g_quark_try_string(attrname); 89 if (quark == 0) 90 /* don't bother inserting into string table */ 91 return NULL; 92 attrname = g_quark_to_string(quark); 93 94 for (i = 0; i < m->attributes->len; i++) { 95 p = m->attributes->pdata[i]; 96 if (owl_pair_get_key(p) == attrname) { 97 return(owl_pair_get_value(p)); 98 } 99 } 100 101 /* 102 owl_function_debugmsg("No attribute %s found for message %i", 103 attrname, 104 owl_message_get_id(m)); 105 */ 106 return(NULL); 65 return g_datalist_get_data(&((owl_message *)m)->attributes, attrname); 107 66 } 108 67 … … 111 70 * function to indent fmtext. 112 71 */ 113 void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm) { 114 int i; 115 owl_pair *p; 72 static void owl_message_attribute_tofmtext(GQuark key_id, gpointer data, gpointer fm) 73 { 116 74 char *buff, *tmpbuff; 117 75 76 tmpbuff = owl_text_indent(data, 19, false); 77 buff = g_strdup_printf(" %-15.15s: %s\n", g_quark_to_string(key_id), tmpbuff); 78 g_free(tmpbuff); 79 owl_fmtext_append_normal(fm, buff); 80 g_free(buff); 81 } 82 83 void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm) 84 { 118 85 owl_fmtext_init_null(fm); 119 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 } 130 131 if(buff == NULL) { 132 buff = g_strdup_printf(" %-15.15s: %s\n", owl_pair_get_key(p), "<error>"); 133 if(buff == NULL) 134 buff=g_strdup(" <error>\n"); 135 } 136 owl_fmtext_append_normal(fm, buff); 137 g_free(buff); 138 } 86 g_datalist_foreach(&((owl_message *)m)->attributes, owl_message_attribute_tofmtext, fm); 139 87 } 140 88 … … 1006 954 void owl_message_cleanup(owl_message *m) 1007 955 { 1008 int i;1009 owl_pair *p;1010 956 #ifdef HAVE_LIBZEPHYR 1011 957 if (m->has_notice) { … … 1016 962 1017 963 /* free all the attributes */ 1018 for (i = 0; i < m->attributes->len; i++) { 1019 p = m->attributes->pdata[i]; 1020 g_free(owl_pair_get_value(p)); 1021 g_slice_free(owl_pair, p); 1022 } 1023 1024 g_ptr_array_free(m->attributes, true); 964 g_datalist_clear(&m->attributes); 1025 965 1026 966 owl_message_invalidate_format(m); -
owl.h
rca1fb26a r8f95fc4 356 356 int delete; 357 357 const char *hostname; 358 G PtrArray *attributes; /* this is a list of pairs */358 GData *attributes; 359 359 char *timestr; 360 360 time_t time; -
perlconfig.c
r7dcef03 r8f95fc4 69 69 } 70 70 71 static void owl_perlconfig_store_attribute(GQuark key_id, gpointer data, gpointer h) 72 { 73 (void)hv_store(h, g_quark_to_string(key_id), strlen(data), 74 owl_new_sv(data), 0); 75 } 76 71 77 CALLER_OWN SV *owl_perlconfig_message2hashref(const owl_message *m) 72 78 { … … 76 82 char *ptr, *utype, *blessas; 77 83 const char *f; 78 int i;79 const owl_pair *pair;80 84 const owl_filter *wrap; 81 85 … … 112 116 } 113 117 114 for (i = 0; i < m->attributes->len; i++) { 115 pair = m->attributes->pdata[i]; 116 (void)hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)), 117 owl_new_sv(owl_pair_get_value(pair)),0); 118 } 118 g_datalist_foreach(&((owl_message *)m)->attributes, owl_perlconfig_store_attribute, h); 119 119 120 120 MSG2H(h, type);
Note: See TracChangeset
for help on using the changeset viewer.