Ignore:
File:
1 edited

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>
    111#include "owl.h"
    122#include "filterproc.h"
     3#include <sys/socket.h>
     4#include <arpa/inet.h>
    135
    146static owl_fmtext_cache fmtext_cache[OWL_FMTEXT_CACHE_SIZE];
     
    4234  m->delete=0;
    4335
     36#ifdef HAVE_LIBZEPHYR
     37  m->has_notice = false;
     38#endif
     39
    4440  owl_message_set_hostname(m, "");
    45   owl_list_create(&(m->attributes));
     41  m->attributes = g_ptr_array_new();
    4642 
    4743  /* 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';
    5147
    5248  m->fmtext = NULL;
     
    5854void owl_message_set_attribute(owl_message *m, const char *attrname, const char *attrvalue)
    5955{
    60   int i, j;
     56  int i;
    6157  owl_pair *p = NULL, *pair = NULL;
    6258
     
    6460
    6561  /* 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];
    6964    if (owl_pair_get_key(p) == attrname) {
    7065      g_free(owl_pair_get_value(p));
     
    7772    pair = g_new(owl_pair, 1);
    7873    owl_pair_create(pair, attrname, NULL);
    79     owl_list_append_element(&(m->attributes), pair);
     74    g_ptr_array_add(m->attributes, pair);
    8075  }
    8176  owl_pair_set_value(pair, owl_validate_or_convert(attrvalue));
     
    8782const char *owl_message_get_attribute_value(const owl_message *m, const char *attrname)
    8883{
    89   int i, j;
     84  int i;
    9085  owl_pair *p;
    9186  GQuark quark;
     
    9792  attrname = g_quark_to_string(quark);
    9893
    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];
    10296    if (owl_pair_get_key(p) == attrname) {
    10397      return(owl_pair_get_value(p));
     
    118112 */
    119113void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm) {
    120   int i, j;
     114  int i;
    121115  owl_pair *p;
    122116  char *buff, *tmpbuff;
     
    124118  owl_fmtext_init_null(fm);
    125119
    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    }
    135130
    136131    if(buff == NULL) {
     
    352347}
    353348
     349CALLER_OWN char *owl_message_format_time(const owl_message *m)
     350{
     351  return owl_util_format_time(localtime(&m->time));
     352}
     353
    354354void owl_message_set_type_admin(owl_message *m)
    355355{
     
    500500const ZNotice_t *owl_message_get_notice(const owl_message *m)
    501501{
    502   return(&(m->notice));
     502  return m->has_notice ? &m->notice : NULL;
    503503}
    504504#else
     
    580580
    581581/* caller must free return value. */
    582 char *owl_message_get_cc(const owl_message *m)
     582CALLER_OWN char *owl_message_get_cc(const owl_message *m)
    583583{
    584584  const char *cur;
     
    597597
    598598/* caller must free return value */
    599 GList *owl_message_get_cc_without_recipient(const owl_message *m)
     599CALLER_OWN GList *owl_message_get_cc_without_recipient(const owl_message *m)
    600600{
    601601  char *cc, *shortuser, *recip;
     
    791791  /* first save the full notice */
    792792  m->notice = *n;
     793  m->has_notice = true;
    793794
    794795  /* a little gross, we'll replace \r's with ' ' for now */
     
    797798  /* save the time, we need to nuke the string saved by message_init */
    798799  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';
    802803
    803804  /* set other info */
     
    835836
    836837 
    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)) {
    841840    owl_message_set_isprivate(m);
    842841  }
     
    876875  if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) {
    877876    const char *argv[] = {
    878       "zcrypt",
     877      NULL,
    879878      "-D",
    880879      "-c", owl_message_get_class(m),
     
    882881      NULL
    883882    };
    884     char *out;
     883    char *out = NULL;
    885884    int rv;
    886885    int status;
    887886    char *zcrypt;
    888887
    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);
    892892    g_free(zcrypt);
    893893
     
    898898      }
    899899      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);
    904906  }
    905907
     
    10041006void owl_message_cleanup(owl_message *m)
    10051007{
    1006   int i, j;
     1008  int i;
    10071009  owl_pair *p;
    10081010#ifdef HAVE_LIBZEPHYR   
    1009   if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
     1011  if (m->has_notice) {
    10101012    ZFreeNotice(&(m->notice));
    10111013  }
     
    10141016
    10151017  /* 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];
    10191020    g_free(owl_pair_get_value(p));
    10201021    g_free(p);
    10211022  }
    10221023
    1023   owl_list_cleanup(&(m->attributes), NULL);
     1024  g_ptr_array_free(m->attributes, true);
    10241025 
    10251026  owl_message_invalidate_format(m);
Note: See TracChangeset for help on using the changeset viewer.