Changeset 526a20d


Ignore:
Timestamp:
Nov 7, 2014, 4:11:20 AM (8 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Parents:
5f3f1e4 (diff), 6a5f0c3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge 6a5f0c3f91523f48a326ec914def708482287bdb into 5f3f1e484f3c4b262b481efbd32602853bb41a27
Files:
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    rca1fb26a r58777e9  
    5858     util.c logging.c \
    5959     perlconfig.c keys.c functions.c zwrite.c viewwin.c help.c filter.c \
    60      regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
     60     regex.c history.c view.c dict.c variable.c filterelement.c \
    6161     keypress.c keymap.c keybinding.c cmd.c context.c \
    6262     aim.c buddy.c buddylist.c style.c errqueue.c \
  • aim.c

    r7dcef03 r6a5f0c3  
    10561056                         OWL_MESSAGE_DIRECTION_IN,
    10571057                         0);
    1058   if (args->icbmflags & AIM_IMFLAGS_AWAY) owl_message_set_attribute(m, "isauto", "");
     1058  if (args->icbmflags & AIM_IMFLAGS_AWAY) owl_message_set_attribute(m, "isauto", "", NULL);
    10591059  owl_global_messagequeue_addmsg(&g, m);
    10601060  g_free(stripmsg);
  • message.c

    r7dcef03 r6a5f0c3  
    3939
    4040  owl_message_set_hostname(m, "");
    41   m->attributes = g_ptr_array_new();
     41  g_datalist_init(&m->attributes);
    4242 
    4343  /* save the time */
     
    5252 * name already exists, replace the old value with the new value
    5353 */
    54 void owl_message_set_attribute(owl_message *m, const char *attrname, const char *attrvalue)
    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));
     54void owl_message_set_attribute(owl_message *m, const char *attrname, const char *attrvalue, GDestroyNotify attrdestroy)
     55{
     56  if (owl_needs_convert(attrvalue)) {
     57    g_datalist_set_data_full(&m->attributes, attrname,
     58                             owl_validate_or_convert(attrvalue), g_free);
     59    if (attrdestroy)
     60      attrdestroy((gpointer)attrvalue);
     61  } else {
     62    g_datalist_set_data_full(&m->attributes, attrname, (gpointer)attrvalue, attrdestroy);
     63  }
    7764}
    7865
     
    8269const char *owl_message_get_attribute_value(const owl_message *m, const char *attrname)
    8370{
    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);
     71  return g_datalist_get_data(&((owl_message *)m)->attributes, attrname);
    10772}
    10873
     
    11176 * function to indent fmtext.
    11277 */
    113 void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm) {
    114   int i;
    115   owl_pair *p;
     78static void owl_message_attribute_tofmtext(GQuark key_id, gpointer data, gpointer fm)
     79{
    11680  char *buff, *tmpbuff;
    11781
     82  tmpbuff = owl_text_indent(data, 19, false);
     83  buff = g_strdup_printf("  %-15.15s: %s\n", g_quark_to_string(key_id), tmpbuff);
     84  g_free(tmpbuff);
     85  owl_fmtext_append_normal(fm, buff);
     86  g_free(buff);
     87}
     88
     89void owl_message_attributes_tofmtext(const owl_message *m, owl_fmtext *fm)
     90{
    11891  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   }
     92  g_datalist_foreach(&((owl_message *)m)->attributes, owl_message_attribute_tofmtext, fm);
    13993}
    14094
     
    170124}
    171125
    172 void owl_message_set_class(owl_message *m, const char *class)
    173 {
    174   owl_message_set_attribute(m, "class", class);
    175 }
    176 
    177126const char *owl_message_get_class(const owl_message *m)
    178127{
     
    184133}
    185134
    186 void owl_message_set_instance(owl_message *m, const char *inst)
    187 {
    188   owl_message_set_attribute(m, "instance", inst);
    189 }
    190 
    191135const char *owl_message_get_instance(const owl_message *m)
    192136{
     
    198142}
    199143
    200 void owl_message_set_sender(owl_message *m, const char *sender)
    201 {
    202   owl_message_set_attribute(m, "sender", sender);
    203 }
    204 
    205144const char *owl_message_get_sender(const owl_message *m)
    206145{
     
    212151}
    213152
    214 void owl_message_set_zsig(owl_message *m, const char *zsig)
    215 {
    216   owl_message_set_attribute(m, "zsig", zsig);
    217 }
    218 
    219153const char *owl_message_get_zsig(const owl_message *m)
    220154{
     
    226160}
    227161
    228 void owl_message_set_recipient(owl_message *m, const char *recip)
    229 {
    230   owl_message_set_attribute(m, "recipient", recip);
    231 }
    232 
    233162const char *owl_message_get_recipient(const owl_message *m)
    234163{
     
    242171}
    243172
    244 void owl_message_set_realm(owl_message *m, const char *realm)
    245 {
    246   owl_message_set_attribute(m, "realm", realm);
    247 }
    248 
    249173const char *owl_message_get_realm(const owl_message *m)
    250174{
     
    256180}
    257181
    258 void owl_message_set_body(owl_message *m, const char *body)
    259 {
    260   owl_message_set_attribute(m, "body", body);
    261 }
    262 
    263182const char *owl_message_get_body(const owl_message *m)
    264183{
     
    271190
    272191
    273 void owl_message_set_opcode(owl_message *m, const char *opcode)
    274 {
    275   owl_message_set_attribute(m, "opcode", opcode);
    276 }
    277 
    278192const char *owl_message_get_opcode(const owl_message *m)
    279193{
     
    288202void owl_message_set_islogin(owl_message *m)
    289203{
    290   owl_message_set_attribute(m, "loginout", "login");
     204  owl_message_set_attribute(m, "loginout", "login", NULL);
    291205}
    292206
     
    294208void owl_message_set_islogout(owl_message *m)
    295209{
    296   owl_message_set_attribute(m, "loginout", "logout");
     210  owl_message_set_attribute(m, "loginout", "logout", NULL);
    297211}
    298212
     
    329243void owl_message_set_isprivate(owl_message *m)
    330244{
    331   owl_message_set_attribute(m, "isprivate", "true");
     245  owl_message_set_attribute(m, "isprivate", "true", NULL);
    332246}
    333247
     
    354268void owl_message_set_type_admin(owl_message *m)
    355269{
    356   owl_message_set_attribute(m, "type", "admin");
     270  owl_message_set_attribute(m, "type", "admin", NULL);
    357271}
    358272
    359273void owl_message_set_type_loopback(owl_message *m)
    360274{
    361   owl_message_set_attribute(m, "type", "loopback");
     275  owl_message_set_attribute(m, "type", "loopback", NULL);
    362276}
    363277
    364278void owl_message_set_type_zephyr(owl_message *m)
    365279{
    366   owl_message_set_attribute(m, "type", "zephyr");
     280  owl_message_set_attribute(m, "type", "zephyr", NULL);
    367281}
    368282
    369283void owl_message_set_type_aim(owl_message *m)
    370284{
    371   owl_message_set_attribute(m, "type", "AIM");
    372 }
    373 
    374 void owl_message_set_type(owl_message *m, const char* type)
    375 {
    376   owl_message_set_attribute(m, "type", type);
     285  owl_message_set_attribute(m, "type", "AIM", NULL);
    377286}
    378287
     
    483392  if (!z) return "";
    484393  return z;
    485 }
    486 
    487 void owl_message_set_zwriteline(owl_message *m, const char *line)
    488 {
    489   owl_message_set_attribute(m, "zwriteline", line);
    490394}
    491395
     
    564468
    565469void owl_message_set_isanswered(owl_message *m) {
    566   owl_message_set_attribute(m, "question", "answered");
     470  owl_message_set_attribute(m, "question", "answered", NULL);
    567471}
    568472
     
    696600{
    697601  owl_message_init(m);
    698   owl_message_set_body(m, text);
    699   owl_message_set_sender(m, sender);
    700   owl_message_set_recipient(m, recipient);
     602  owl_message_set_attribute(m, "body", g_strdup(text), g_free);
     603  owl_message_set_attribute(m, "sender", g_strdup(sender), g_free);
     604  owl_message_set_attribute(m, "recipient", g_strdup(recipient), g_free);
    701605  owl_message_set_type_aim(m);
    702606
     
    723627  owl_message_init(m);
    724628  owl_message_set_type_admin(m);
    725   owl_message_set_body(m, text);
    726   owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */
     629  owl_message_set_attribute(m, "body", g_strdup(text), g_free);
     630  owl_message_set_attribute(m, "adminheader", g_strdup(header), g_free); /* just a hack for now */
    727631}
    728632
     
    732636  owl_message_init(m);
    733637  owl_message_set_type_loopback(m);
    734   owl_message_set_body(m, text);
    735   owl_message_set_sender(m, "loopsender");
    736   owl_message_set_recipient(m, "looprecip");
     638  owl_message_set_attribute(m, "body", g_strdup(text), g_free);
     639  owl_message_set_attribute(m, "sender", "loopsender", NULL);
     640  owl_message_set_attribute(m, "recipient", "looprecip", NULL);
    737641  owl_message_set_isprivate(m);
    738642}
     
    768672    }
    769673
    770     owl_message_set_attribute(m, "zephyr_ccs", recips->str);
    771     g_string_free(recips, true);
     674    owl_message_set_attribute(m, "zephyr_ccs", g_string_free(recips, false), g_free);
    772675  }
    773676}
     
    781684  struct hostent *hent;
    782685#endif /* ZNOTICE_SOCKADDR */
    783   char *tmp, *tmp2;
     686  char *tmp;
    784687  int len;
    785688
     
    803706
    804707  /* set other info */
    805   owl_message_set_sender(m, n->z_sender);
    806   owl_message_set_class(m, n->z_class);
    807   owl_message_set_instance(m, n->z_class_inst);
    808   owl_message_set_recipient(m, n->z_recipient);
     708  owl_message_set_attribute(m, "sender", n->z_sender, NULL);
     709  owl_message_set_attribute(m, "class", n->z_class, NULL);
     710  owl_message_set_attribute(m, "instance", n->z_class_inst, NULL);
     711  owl_message_set_attribute(m, "recipient", n->z_recipient, NULL);
    809712  if (n->z_opcode) {
    810     owl_message_set_opcode(m, n->z_opcode);
     713    owl_message_set_attribute(m, "opcode", n->z_opcode, NULL);
    811714  } else {
    812     owl_message_set_opcode(m, "");
    813   }
    814   owl_message_set_zsig(m, owl_zephyr_get_zsig(n, &len));
    815 
    816   owl_message_set_realm(m, zuser_realm(n->z_recipient));
     715    owl_message_set_attribute(m, "opcode", "", NULL);
     716  }
     717  owl_message_set_attribute(m, "zsig", owl_zephyr_get_zsig(n, &len), NULL);
     718
     719  owl_message_set_attribute(m, "realm", zuser_realm(n->z_recipient), NULL);
    817720
    818721  /* Set the "isloginout" attribute if it's a login message */
    819722  if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) {
    820723    if (!strcasecmp(n->z_opcode, "user_login") || !strcasecmp(n->z_opcode, "user_logout")) {
    821       tmp=owl_zephyr_get_field(n, 1);
    822       owl_message_set_attribute(m, "loginhost", tmp);
    823       g_free(tmp);
    824 
    825       tmp=owl_zephyr_get_field(n, 3);
    826       owl_message_set_attribute(m, "logintty", tmp);
    827       g_free(tmp);
     724      owl_message_set_attribute(m, "loginhost", owl_zephyr_get_field(n, 1), g_free);
     725      owl_message_set_attribute(m, "logintty", owl_zephyr_get_field(n, 3), g_free);
    828726    }
    829727
     
    844742  if (!strcasecmp(n->z_message, "Automated reply:") ||
    845743      !strcasecmp(n->z_opcode, "auto")) {
    846     owl_message_set_attribute(m, "isauto", "");
     744    owl_message_set_attribute(m, "isauto", "", NULL);
    847745  }
    848746
     
    864762  tmp=owl_zephyr_get_message(n, m);
    865763  if (owl_global_is_newlinestrip(&g)) {
    866     tmp2=owl_util_stripnewlines(tmp);
    867     owl_message_set_body(m, tmp2);
    868     g_free(tmp2);
     764    owl_message_set_attribute(m, "body", owl_util_stripnewlines(tmp), g_free);
     765    g_free(tmp);
    869766  } else {
    870     owl_message_set_body(m, tmp);
    871   }
    872   g_free(tmp);
     767    owl_message_set_attribute(m, "body", tmp, g_free);
     768  }
    873769
    874770  /* if zcrypt is enabled try to decrypt the message */
     
    897793        out[len - 8] = 0;
    898794      }
    899       owl_message_set_body(m, out);
     795      owl_message_set_attribute(m, "body", out, g_free);
    900796    } else {
    901797      /* Replace the opcode. Otherwise the UI and other bits of code think the
    902798       * message was encrypted. */
    903       owl_message_set_opcode(m, "failed-decrypt");
     799      owl_message_set_attribute(m, "opcode", "failed-decrypt", NULL);
     800      g_free(out);
    904801    }
    905     g_free(out);
    906802  }
    907803
     
    930826  owl_message_set_direction_in(m);
    931827
    932   owl_message_set_attribute(m, "pseudo", "");
    933   owl_message_set_attribute(m, "loginhost", host ? host : "");
    934   owl_message_set_attribute(m, "logintty", tty ? tty : "");
    935 
    936   owl_message_set_sender(m, longuser);
    937   owl_message_set_class(m, "LOGIN");
    938   owl_message_set_instance(m, longuser);
    939   owl_message_set_recipient(m, "");
     828  owl_message_set_attribute(m, "pseudo", "", NULL);
     829  owl_message_set_attribute(m, "loginhost", g_strdup(host ? host : ""), g_free);
     830  owl_message_set_attribute(m, "logintty", g_strdup(tty ? tty : ""), g_free);
     831
     832  owl_message_set_attribute(m, "sender", g_strdup(longuser), g_free);
     833  owl_message_set_attribute(m, "class", "LOGIN", NULL);
     834  owl_message_set_attribute(m, "instance", g_strdup(longuser), g_free);
     835  owl_message_set_attribute(m, "recipient", "", NULL);
    940836  if (direction==0) {
    941     owl_message_set_opcode(m, "USER_LOGIN");
     837    owl_message_set_attribute(m, "opcode", "USER_LOGIN", NULL);
    942838    owl_message_set_islogin(m);
    943839  } else if (direction==1) {
    944     owl_message_set_opcode(m, "USER_LOGOUT");
     840    owl_message_set_attribute(m, "opcode", "USER_LOGOUT", NULL);
    945841    owl_message_set_islogout(m);
    946842  }
    947843
    948   owl_message_set_realm(m, zuser_realm(longuser));
    949 
    950   owl_message_set_body(m, "<uninitialized>");
     844  owl_message_set_attribute(m, "realm", g_strdup(zuser_realm(longuser)), g_free);
     845
     846  owl_message_set_attribute(m, "body", "<uninitialized>", NULL);
    951847
    952848  /* save the hostname */
     
    965861  owl_message_set_direction_out(m);
    966862  owl_message_set_type_zephyr(m);
    967   owl_message_set_sender(m, owl_zephyr_get_sender());
    968   owl_message_set_class(m, owl_zwrite_get_class(z));
    969   owl_message_set_instance(m, owl_zwrite_get_instance(z));
     863  owl_message_set_attribute(m, "sender", g_strdup(owl_zephyr_get_sender()), g_free);
     864  owl_message_set_attribute(m, "class", g_strdup(owl_zwrite_get_class(z)), g_free);
     865  owl_message_set_attribute(m, "instance", g_strdup(owl_zwrite_get_instance(z)), g_free);
    970866  if (recip_index < owl_zwrite_get_numrecips(z)) {
    971867    char *zuser = owl_zwrite_get_recip_n_with_realm(z, recip_index);
    972868    char *longzuser = long_zuser(zuser);
    973     owl_message_set_recipient(m, longzuser);
    974     owl_message_set_realm(m, zuser_realm(longzuser));
    975     g_free(longzuser);
     869    owl_message_set_attribute(m, "realm", g_strdup(zuser_realm(longzuser)), g_free);
     870    owl_message_set_attribute(m, "recipient", longzuser, g_free);
    976871    g_free(zuser);
    977872  } else {
     
    980875     * anyway. */
    981876    const char *realm = owl_zwrite_get_realm(z);
    982     owl_message_set_realm(m, realm[0] ? realm : owl_zephyr_get_realm());
    983   }
    984   owl_message_set_opcode(m, owl_zwrite_get_opcode(z));
     877    owl_message_set_attribute(m, "realm", g_strdup(realm[0] ? realm : owl_zephyr_get_realm()), g_free);
     878  }
     879  owl_message_set_attribute(m, "opcode", g_strdup(owl_zwrite_get_opcode(z)), g_free);
    985880
    986881  /* Although not strictly the zwriteline, anyone using the unsantized version
    987882   * of it probably has a bug. */
    988883  replyline = owl_zwrite_get_replyline(z, recip_index);
    989   owl_message_set_zwriteline(m, replyline);
     884  owl_message_set_attribute(m, "zwriteline", g_strdup(replyline), g_free);
    990885  g_free(replyline);
    991886
    992   owl_message_set_body(m, body);
    993   owl_message_set_zsig(m, owl_zwrite_get_zsig(z));
     887  owl_message_set_attribute(m, "body", g_strdup(body), g_free);
     888  owl_message_set_attribute(m, "zsig", g_strdup(owl_zwrite_get_zsig(z)), g_free);
    994889 
    995890  /* save the hostname */
     
    1006901void owl_message_cleanup(owl_message *m)
    1007902{
    1008   int i;
    1009   owl_pair *p;
    1010903#ifdef HAVE_LIBZEPHYR   
    1011904  if (m->has_notice) {
     
    1016909
    1017910  /* 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);
     911  g_datalist_clear(&m->attributes);
    1025912 
    1026913  owl_message_invalidate_format(m);
  • owl.h

    rca1fb26a r58777e9  
    339339} owl_zwrite;
    340340
    341 typedef struct _owl_pair {
    342   const char *key;
    343   char *value;
    344 } owl_pair;
    345 
    346341struct _owl_fmtext_cache;
    347342
     
    356351  int delete;
    357352  const char *hostname;
    358   GPtrArray *attributes;          /* this is a list of pairs */
     353  GData *attributes;
    359354  char *timestr;
    360355  time_t time;
  • perlconfig.c

    r7dcef03 r6a5f0c3  
    6969}
    7070
     71static 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
    7177CALLER_OWN SV *owl_perlconfig_message2hashref(const owl_message *m)
    7278{
     
    7682  char *ptr, *utype, *blessas;
    7783  const char *f;
    78   int i;
    79   const owl_pair *pair;
    8084  const owl_filter *wrap;
    8185
     
    112116  }
    113117
    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);
    119119 
    120120  MSG2H(h, type);
     
    195195    key = hv_iterkey(ent, &len);
    196196    val = SvPV_nolen(hv_iterval(hash, ent));
    197     if(!strcmp(key, "type")) {
    198       owl_message_set_type(m, val);
    199     } else if(!strcmp(key, "direction")) {
     197    if (!strcmp(key, "direction")) {
    200198      owl_message_set_direction(m, owl_message_parse_direction(val));
    201199    } else if(!strcmp(key, "private")) {
     
    206204    } else if (!strcmp(key, "hostname")) {
    207205      owl_message_set_hostname(m, val);
    208     } else if (!strcmp(key, "zwriteline")) {
    209       owl_message_set_zwriteline(m, val);
    210206    } else if (!strcmp(key, "time")) {
    211207      g_free(m->timestr);
     
    214210      m->time = mktime(&tm);
    215211    } else {
    216       owl_message_set_attribute(m, key, val);
     212      owl_message_set_attribute(m, key, g_strdup(val), g_free);
    217213    }
    218214  }
    219215  if(owl_message_is_type_admin(m)) {
    220216    if(!owl_message_get_attribute_value(m, "adminheader"))
    221       owl_message_set_attribute(m, "adminheader", "");
     217      owl_message_set_attribute(m, "adminheader", "", NULL);
    222218  }
    223219  return m;
  • tester.c

    r21dc927 r6a5f0c3  
    464464  owl_message_set_type_zephyr(&m);
    465465  owl_message_set_direction_in(&m);
    466   owl_message_set_class(&m, "owl");
    467   owl_message_set_instance(&m, "tester");
    468   owl_message_set_sender(&m, "owl-user");
    469   owl_message_set_recipient(&m, "joe");
    470   owl_message_set_attribute(&m, "foo", "bar");
     466  owl_message_set_attribute(&m, "class", "owl", NULL);
     467  owl_message_set_attribute(&m, "instance", "tester", NULL);
     468  owl_message_set_attribute(&m, "sender", "owl-user", NULL);
     469  owl_message_set_attribute(&m, "recipient", "joe", NULL);
     470  owl_message_set_attribute(&m, "foo", "bar", NULL);
    471471
    472472#define TEST_FILTER(f, e) do {                          \
  • util.c

    rcba6b9c r526a20d  
    610610}
    611611
     612/* Check whether in is not valid UTF-8 or has format characters. */
     613bool owl_needs_convert(const char *in)
     614{
     615  const char *p;
     616  if (!g_utf8_validate(in, -1, NULL))
     617    return true;
     618  for (p = strchr(in, OWL_FMTEXT_UC_STARTBYTE_UTF8);
     619       p != NULL;
     620       p = strchr(p + 1, OWL_FMTEXT_UC_STARTBYTE_UTF8)) {
     621    if (owl_fmtext_is_format_char(g_utf8_get_char(p)))
     622      return true;
     623  }
     624  return false;
     625}
     626
    612627/* If in is not UTF-8, convert from ISO-8859-1. We may want to allow
    613628 * the caller to specify an alternative in the future. We also strip
  • .travis.yml

    r48c09d4 r5f3f1e4  
     1
    12language: perl
    23compiler:
     
    910  - "5.16"
    1011  - "5.18"
    11   - "5.19"
     12  - "5.20"
    1213install:
    1314  - sudo apt-get update -q
  • functions.c

    r7dcef03 rb61ad80  
    12271227  time_t now;
    12281228  va_list ap;
    1229   va_start(ap, fmt);
    12301229
    12311230  if (!owl_global_is_debug_fast(&g))
     
    12421241          (int) getpid(), tmpbuff, now - owl_global_get_starttime(&g));
    12431242  g_free(tmpbuff);
     1243
     1244  va_start(ap, fmt);
    12441245  vfprintf(file, fmt, ap);
     1246  va_end(ap);
     1247
    12451248  putc('\n', file);
    12461249  fflush(file);
    1247 
    1248   va_end(ap);
    12491250}
    12501251
  • perl/modules/Twitter/lib/BarnOwl/Module/Twitter.pm

    rb8a3e00 r140429f  
    137137        my $twitter_args = { username   => $cfg->{user},
    138138                             password   => $cfg->{password},
    139                              source     => 'barnowl',
     139                             source     => 'barnowl',
     140                             ssl        => 1,
     141                             legacy_lists_api => 0,
    140142                         };
    141143        if (defined $cfg->{service}) {
     
    274276);
    275277
     278BarnOwl::new_command( 'twitter-favorite' => sub { cmd_twitter_favorite(@_) },
     279    {
     280    summary     => 'Favorite the current Twitter message',
     281    usage       => 'twitter-favorite [ACCOUNT]',
     282    description => <<END_DESCRIPTION
     283Favorite the current Twitter message using ACCOUNT (defaults to the
     284account that received the tweet).
     285END_DESCRIPTION
     286    }
     287);
     288
    276289BarnOwl::new_command( 'twitter-follow' => sub { cmd_twitter_follow(@_); },
    277290    {
     
    355368    $account = $m->account unless defined($account);
    356369    find_account($account)->twitter_retweet($m);
     370    return;
     371}
     372
     373sub cmd_twitter_favorite {
     374    my $cmd = shift;
     375    my $account = shift;
     376    my $m = BarnOwl::getcurmsg();
     377    if(!$m || $m->type ne 'Twitter') {
     378        die("$cmd must be used with a Twitter message selected.\n");
     379    }
     380
     381    $account = $m->account unless defined($account);
     382    find_account($account)->twitter_favorite($m);
    357383    return;
    358384}
  • perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm

    r4ebbfbc r140429f  
    371371        $self->twitter_direct($1, $2);
    372372    } elsif(defined $self->{twitter}) {
    373         if(length($msg) > 140) {
    374             die("Twitter: Message over 140 characters long.\n");
    375         }
    376373        $self->twitter_command('update', {
    377374            status => $msg,
     
    432429}
    433430
     431sub twitter_favorite {
     432    my $self = shift;
     433    my $msg = shift;
     434
     435    if($msg->service ne $self->{cfg}->{service}) {
     436        die("Cannot favorite a message from a different service.\n");
     437    }
     438    $self->twitter_command(create_favorite => $msg->{status_id});
     439}
     440
     441
    434442sub twitter_follow {
    435443    my $self = shift;
  • variable.c

    r7dcef03 r94b9ee0  
    10381038CALLER_OWN char *owl_variable_bool_get_tostring_default(const owl_variable *v, void *dummy)
    10391039{
    1040   bool val = owl_variable_get_bool(v);
    1041   if (val == 0) {
    1042     return g_strdup("off");
    1043   } else if (val == 1) {
    1044     return g_strdup("on");
    1045   } else {
    1046     return g_strdup("<invalid>");
    1047   }
     1040  return g_strdup(owl_variable_get_bool(v) ? "on" : "off");
    10481041}
    10491042
  • zephyr.c

    r7dcef03 r18380fd  
    283283#ifdef HAVE_LIBZEPHYR
    284284  FILE *file;
     285  int fopen_errno;
    285286  char *tmp, *start;
    286287  char *buffer = NULL;
     
    289290  int subSize = 1024;
    290291  int count;
    291   struct stat statbuff;
    292292
    293293  subsfile = owl_zephyr_dotfile(".zephyr.subs", filename);
    294294
    295   if (stat(subsfile, &statbuff) != 0) {
    296     g_free(subsfile);
    297     if (error_on_nofile == 1)
     295  count = 0;
     296  file = fopen(subsfile, "r");
     297  fopen_errno = errno;
     298  g_free(subsfile);
     299  if (!file) {
     300    if (error_on_nofile == 1 || fopen_errno != ENOENT)
    298301      return -1;
    299302    return 0;
    300303  }
    301 
    302   ZResetAuthentication();
    303   count = 0;
    304   file = fopen(subsfile, "r");
    305   g_free(subsfile);
    306   if (!file)
    307     return -1;
    308304
    309305  subs = g_new(ZSubscription_t, subSize);
     
    348344    g_free(buffer);
    349345
     346  ZResetAuthentication();
    350347  return owl_zephyr_loadsubs_helper(subs, count);
    351348#else
     
    412409  char *buffer = NULL;
    413410  int count;
    414   struct stat statbuff;
    415411
    416412  subs = g_new(ZSubscription_t, numSubs);
    417413  subsfile = owl_zephyr_dotfile(".anyone", filename);
    418414
    419   if (stat(subsfile, &statbuff) == -1) {
    420     g_free(subs);
    421     g_free(subsfile);
    422     return 0;
    423   }
    424 
    425   ZResetAuthentication();
    426415  count = 0;
    427416  file = fopen(subsfile, "r");
     
    445434    fclose(file);
    446435  } else {
     436    g_free(subs);
    447437    return 0;
    448438  }
    449439  g_free(buffer);
    450440
     441  ZResetAuthentication();
    451442  return owl_zephyr_loadsubs_helper(subs, count);
    452443#else
Note: See TracChangeset for help on using the changeset viewer.