Ignore:
File:
1 edited

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>
    111#include "owl.h"
    212#include "filterproc.h"
    3 #include <sys/socket.h>
    4 #include <arpa/inet.h>
    513
    614static owl_fmtext_cache fmtext_cache[OWL_FMTEXT_CACHE_SIZE];
     
    3442  m->delete=0;
    3543
    36 #ifdef HAVE_LIBZEPHYR
    37   m->has_notice = false;
    38 #endif
    39 
    4044  owl_message_set_hostname(m, "");
    41   m->attributes = g_ptr_array_new();
     45  owl_list_create(&(m->attributes));
    4246 
    4347  /* 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';
    4751
    4852  m->fmtext = NULL;
     
    5458void owl_message_set_attribute(owl_message *m, const char *attrname, const char *attrvalue)
    5559{
    56   int i;
     60  int i, j;
    5761  owl_pair *p = NULL, *pair = NULL;
    5862
     
    6064
    6165  /* 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);
    6469    if (owl_pair_get_key(p) == attrname) {
    6570      g_free(owl_pair_get_value(p));
     
    7277    pair = g_new(owl_pair, 1);
    7378    owl_pair_create(pair, attrname, NULL);
    74     g_ptr_array_add(m->attributes, pair);
     79    owl_list_append_element(&(m->attributes), pair);
    7580  }
    7681  owl_pair_set_value(pair, owl_validate_or_convert(attrvalue));
     
    8287const char *owl_message_get_attribute_value(const owl_message *m, const char *attrname)
    8388{
    84   int i;
     89  int i, j;
    8590  owl_pair *p;
    8691  GQuark quark;
     
    9297  attrname = g_quark_to_string(quark);
    9398
    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);
    96102    if (owl_pair_get_key(p) == attrname) {
    97103      return(owl_pair_get_value(p));
     
    112118 */
    113119void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm) {
    114   int i;
     120  int i, j;
    115121  owl_pair *p;
    116122  char *buff, *tmpbuff;
     
    118124  owl_fmtext_init_null(fm);
    119125
    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);
    130135
    131136    if(buff == NULL) {
     
    347352}
    348353
    349 CALLER_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->has_notice ? &m->notice : NULL;
     502  return(&(m->notice));
    503503}
    504504#else
     
    580580
    581581/* caller must free return value. */
    582 CALLER_OWN char *owl_message_get_cc(const owl_message *m)
     582char *owl_message_get_cc(const owl_message *m)
    583583{
    584584  const char *cur;
     
    597597
    598598/* caller must free return value */
    599 CALLER_OWN GList *owl_message_get_cc_without_recipient(const owl_message *m)
     599GList *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;
    794793
    795794  /* a little gross, we'll replace \r's with ' ' for now */
     
    798797  /* save the time, we need to nuke the string saved by message_init */
    799798  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';
    803802
    804803  /* set other info */
     
    836835
    837836 
    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 != '@') {
    840841    owl_message_set_isprivate(m);
    841842  }
     
    875876  if (owl_global_is_zcrypt(&g) && !strcasecmp(n->z_opcode, "crypt")) {
    876877    const char *argv[] = {
    877       NULL,
     878      "zcrypt",
    878879      "-D",
    879880      "-c", owl_message_get_class(m),
     
    881882      NULL
    882883    };
    883     char *out = NULL;
     884    char *out;
    884885    int rv;
    885886    int status;
    886887    char *zcrypt;
    887888
    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);
    892892    g_free(zcrypt);
    893893
     
    898898      }
    899899      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);
    904903    }
    905     g_free(out);
    906904  }
    907905
     
    10061004void owl_message_cleanup(owl_message *m)
    10071005{
    1008   int i;
     1006  int i, j;
    10091007  owl_pair *p;
    10101008#ifdef HAVE_LIBZEPHYR   
    1011   if (m->has_notice) {
     1009  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
    10121010    ZFreeNotice(&(m->notice));
    10131011  }
     
    10161014
    10171015  /* 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);
    10201019    g_free(owl_pair_get_value(p));
    10211020    g_free(p);
    10221021  }
    10231022
    1024   g_ptr_array_free(m->attributes, true);
     1023  owl_list_cleanup(&(m->attributes), NULL);
    10251024 
    10261025  owl_message_invalidate_format(m);
Note: See TracChangeset for help on using the changeset viewer.