Changeset d110d95


Ignore:
Timestamp:
Oct 7, 2017, 7:25:15 AM (9 years ago)
Author:
GitHub <noreply@github.com>
Parents:
0c059f0 (diff), b36b9a6 (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.
git-author:
Anders Kaseorg <andersk@mit.edu> (10/07/17 07:25:15)
git-committer:
GitHub <noreply@github.com> (10/07/17 07:25:15)
Message:
Merge b36b9a6a6bb74ef2564f73f0c78e56d8d3efcb74 into 0c059f0fccba1043c860fc69292bd24f7284f2a9
Files:
7 added
1 deleted
36 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r392b5cf rd110d95  
    6363     util.c logging.c \
    6464     perlconfig.c keys.c functions.c zwrite.c viewwin.c help.c filter.c \
    65      regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
     65     regex.c history.c view.c dict.c variable.c filterelement.c \
    6666     keypress.c keymap.c keybinding.c cmd.c context.c \
    6767     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

    rff528e6 rd110d95  
    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
    … …  
    477386  if (!z) return "";
    478387  return z;
    479 }
    480 
    481 void owl_message_set_zwriteline(owl_message *m, const char *line)
    482 {
    483   owl_message_set_attribute(m, "zwriteline", line);
    484388}
    485389
    … …  
    558462
    559463void owl_message_set_isanswered(owl_message *m) {
    560   owl_message_set_attribute(m, "question", "answered");
     464  owl_message_set_attribute(m, "question", "answered", NULL);
    561465}
    562466
    … …  
    690594{
    691595  owl_message_init(m);
    692   owl_message_set_body(m, text);
    693   owl_message_set_sender(m, sender);
    694   owl_message_set_recipient(m, recipient);
     596  owl_message_set_attribute(m, "body", g_strdup(text), g_free);
     597  owl_message_set_attribute(m, "sender", g_strdup(sender), g_free);
     598  owl_message_set_attribute(m, "recipient", g_strdup(recipient), g_free);
    695599  owl_message_set_type_aim(m);
    696600
    … …  
    717621  owl_message_init(m);
    718622  owl_message_set_type_admin(m);
    719   owl_message_set_body(m, text);
    720   owl_message_set_attribute(m, "adminheader", header); /* just a hack for now */
     623  owl_message_set_attribute(m, "body", g_strdup(text), g_free);
     624  owl_message_set_attribute(m, "adminheader", g_strdup(header), g_free); /* just a hack for now */
    721625}
    722626
    … …  
    726630  owl_message_init(m);
    727631  owl_message_set_type_loopback(m);
    728   owl_message_set_body(m, text);
    729   owl_message_set_sender(m, "loopsender");
    730   owl_message_set_recipient(m, "looprecip");
     632  owl_message_set_attribute(m, "body", g_strdup(text), g_free);
     633  owl_message_set_attribute(m, "sender", "loopsender", NULL);
     634  owl_message_set_attribute(m, "recipient", "looprecip", NULL);
    731635  owl_message_set_isprivate(m);
    732636}
    … …  
    762666    }
    763667
    764     owl_message_set_attribute(m, "zephyr_ccs", recips->str);
    765     g_string_free(recips, true);
     668    owl_message_set_attribute(m, "zephyr_ccs", g_string_free(recips, false), g_free);
    766669  }
    767670}
    … …  
    775678  struct hostent *hent;
    776679#endif /* ZNOTICE_SOCKADDR */
    777   char *tmp, *tmp2;
     680  char *tmp;
    778681  int len;
    779682
    … …  
    797700
    798701  /* set other info */
    799   owl_message_set_sender(m, n->z_sender);
    800   owl_message_set_class(m, n->z_class);
    801   owl_message_set_instance(m, n->z_class_inst);
    802   owl_message_set_recipient(m, n->z_recipient);
     702  owl_message_set_attribute(m, "sender", n->z_sender, NULL);
     703  owl_message_set_attribute(m, "class", n->z_class, NULL);
     704  owl_message_set_attribute(m, "instance", n->z_class_inst, NULL);
     705  owl_message_set_attribute(m, "recipient", n->z_recipient, NULL);
    803706  if (n->z_opcode) {
    804     owl_message_set_opcode(m, n->z_opcode);
     707    owl_message_set_attribute(m, "opcode", n->z_opcode, NULL);
    805708  } else {
    806     owl_message_set_opcode(m, "");
    807   }
    808   owl_message_set_zsig(m, owl_zephyr_get_zsig(n, &len));
    809 
    810   owl_message_set_realm(m, zuser_realm(n->z_recipient));
     709    owl_message_set_attribute(m, "opcode", "", NULL);
     710  }
     711  owl_message_set_attribute(m, "zsig", owl_zephyr_get_zsig(n, &len), NULL);
     712
     713  owl_message_set_attribute(m, "realm", zuser_realm(n->z_recipient), NULL);
    811714
    812715  /* Set the "isloginout" attribute if it's a login message */
    813716  if (!strcasecmp(n->z_class, "login") || !strcasecmp(n->z_class, OWL_WEBZEPHYR_CLASS)) {
    814717    if (!strcasecmp(n->z_opcode, "user_login") || !strcasecmp(n->z_opcode, "user_logout")) {
    815       tmp=owl_zephyr_get_field(n, 1);
    816       owl_message_set_attribute(m, "loginhost", tmp);
    817       g_free(tmp);
    818 
    819       tmp=owl_zephyr_get_field(n, 3);
    820       owl_message_set_attribute(m, "logintty", tmp);
    821       g_free(tmp);
     718      owl_message_set_attribute(m, "loginhost", owl_zephyr_get_field(n, 1), g_free);
     719      owl_message_set_attribute(m, "logintty", owl_zephyr_get_field(n, 3), g_free);
    822720    }
    823721
    … …  
    838736  if (!strcasecmp(n->z_message, "Automated reply:") ||
    839737      !strcasecmp(n->z_opcode, "auto")) {
    840     owl_message_set_attribute(m, "isauto", "");
     738    owl_message_set_attribute(m, "isauto", "", NULL);
    841739  }
    842740
    … …  
    858756  tmp=owl_zephyr_get_message(n, m);
    859757  if (owl_global_is_newlinestrip(&g)) {
    860     tmp2=owl_util_stripnewlines(tmp);
    861     owl_message_set_body(m, tmp2);
    862     g_free(tmp2);
     758    owl_message_set_attribute(m, "body", owl_util_stripnewlines(tmp), g_free);
     759    g_free(tmp);
    863760  } else {
    864     owl_message_set_body(m, tmp);
    865   }
    866   g_free(tmp);
     761    owl_message_set_attribute(m, "body", tmp, g_free);
     762  }
    867763
    868764  /* if zcrypt is enabled try to decrypt the message */
    … …  
    891787        out[len - 8] = 0;
    892788      }
    893       owl_message_set_body(m, out);
     789      owl_message_set_attribute(m, "body", out, g_free);
    894790    } else {
    895791      /* Replace the opcode. Otherwise the UI and other bits of code think the
    896792       * message was encrypted. */
    897       owl_message_set_opcode(m, "failed-decrypt");
     793      owl_message_set_attribute(m, "opcode", "failed-decrypt", NULL);
     794      g_free(out);
    898795    }
    899     g_free(out);
    900796  }
    901797
    … …  
    924820  owl_message_set_direction_in(m);
    925821
    926   owl_message_set_attribute(m, "pseudo", "");
    927   owl_message_set_attribute(m, "loginhost", host ? host : "");
    928   owl_message_set_attribute(m, "logintty", tty ? tty : "");
    929 
    930   owl_message_set_sender(m, longuser);
    931   owl_message_set_class(m, "LOGIN");
    932   owl_message_set_instance(m, longuser);
    933   owl_message_set_recipient(m, "");
     822  owl_message_set_attribute(m, "pseudo", "", NULL);
     823  owl_message_set_attribute(m, "loginhost", g_strdup(host ? host : ""), g_free);
     824  owl_message_set_attribute(m, "logintty", g_strdup(tty ? tty : ""), g_free);
     825
     826  owl_message_set_attribute(m, "sender", g_strdup(longuser), g_free);
     827  owl_message_set_attribute(m, "class", "LOGIN", NULL);
     828  owl_message_set_attribute(m, "instance", g_strdup(longuser), g_free);
     829  owl_message_set_attribute(m, "recipient", "", NULL);
    934830  if (direction==0) {
    935     owl_message_set_opcode(m, "USER_LOGIN");
     831    owl_message_set_attribute(m, "opcode", "USER_LOGIN", NULL);
    936832    owl_message_set_islogin(m);
    937833  } else if (direction==1) {
    938     owl_message_set_opcode(m, "USER_LOGOUT");
     834    owl_message_set_attribute(m, "opcode", "USER_LOGOUT", NULL);
    939835    owl_message_set_islogout(m);
    940836  }
    941837
    942   owl_message_set_realm(m, zuser_realm(longuser));
    943 
    944   owl_message_set_body(m, "<uninitialized>");
     838  owl_message_set_attribute(m, "realm", g_strdup(zuser_realm(longuser)), g_free);
     839
     840  owl_message_set_attribute(m, "body", "<uninitialized>", NULL);
    945841
    946842  /* save the hostname */
    … …  
    959855  owl_message_set_direction_out(m);
    960856  owl_message_set_type_zephyr(m);
    961   owl_message_set_sender(m, owl_zephyr_get_sender());
    962   owl_message_set_class(m, owl_zwrite_get_class(z));
    963   owl_message_set_instance(m, owl_zwrite_get_instance(z));
     857  owl_message_set_attribute(m, "sender", g_strdup(owl_zephyr_get_sender()), g_free);
     858  owl_message_set_attribute(m, "class", g_strdup(owl_zwrite_get_class(z)), g_free);
     859  owl_message_set_attribute(m, "instance", g_strdup(owl_zwrite_get_instance(z)), g_free);
    964860  if (recip_index < owl_zwrite_get_numrecips(z)) {
    965861    char *zuser = owl_zwrite_get_recip_n_with_realm(z, recip_index);
    966862    char *longzuser = long_zuser(zuser);
    967     owl_message_set_recipient(m, longzuser);
    968     owl_message_set_realm(m, zuser_realm(longzuser));
    969     g_free(longzuser);
     863    owl_message_set_attribute(m, "realm", g_strdup(zuser_realm(longzuser)), g_free);
     864    owl_message_set_attribute(m, "recipient", longzuser, g_free);
    970865    g_free(zuser);
    971866  } else {
    … …  
    974869     * anyway. */
    975870    const char *realm = owl_zwrite_get_realm(z);
    976     owl_message_set_realm(m, realm[0] ? realm : owl_zephyr_get_realm());
    977   }
    978   owl_message_set_opcode(m, owl_zwrite_get_opcode(z));
     871    owl_message_set_attribute(m, "realm", g_strdup(realm[0] ? realm : owl_zephyr_get_realm()), g_free);
     872  }
     873  owl_message_set_attribute(m, "opcode", g_strdup(owl_zwrite_get_opcode(z)), g_free);
    979874
    980875  /* Although not strictly the zwriteline, anyone using the unsantized version
    981876   * of it probably has a bug. */
    982877  replyline = owl_zwrite_get_replyline(z, recip_index);
    983   owl_message_set_zwriteline(m, replyline);
     878  owl_message_set_attribute(m, "zwriteline", g_strdup(replyline), g_free);
    984879  g_free(replyline);
    985880
    986   owl_message_set_body(m, body);
    987   owl_message_set_zsig(m, owl_zwrite_get_zsig(z));
     881  owl_message_set_attribute(m, "body", g_strdup(body), g_free);
     882  owl_message_set_attribute(m, "zsig", g_strdup(owl_zwrite_get_zsig(z)), g_free);
    988883 
    989884  /* save the hostname */
    … …  
    1000895void owl_message_cleanup(owl_message *m)
    1001896{
    1002   int i;
    1003   owl_pair *p;
    1004897#ifdef HAVE_LIBZEPHYR   
    1005898  if (m->has_notice) {
    … …  
    1010903
    1011904  /* free all the attributes */
    1012   for (i = 0; i < m->attributes->len; i++) {
    1013     p = m->attributes->pdata[i];
    1014     g_free(owl_pair_get_value(p));
    1015     g_slice_free(owl_pair, p);
    1016   }
    1017 
    1018   g_ptr_array_free(m->attributes, true);
     905  g_datalist_clear(&m->attributes);
    1019906 
    1020907  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 rb36b9a6  
    6969}
    7070
     71static void owl_perlconfig_store_attribute(GQuark key_id, gpointer data, gpointer h)
     72{
     73  const char *key = g_quark_to_string(key_id);
     74  (void)hv_store(h, key, strlen(key), 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

    ra7250ee rd110d95  
    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

    rd2ba33c rd110d95  
    608608  }
    609609  return r;
     610}
     611
     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;
    610625}
    611626
  • .travis.yml

    r48c09d4 rbecd617  
    11language: perl
     2sudo: false
    23compiler:
    34  - clang
    … …  
    910  - "5.16"
    1011  - "5.18"
    11   - "5.19"
    12 install:
    13   - sudo apt-get update -q
    14 # we actually want debhelper >= 7, libperl-dev >= 5.10.1-8, libzephyr-dev >= 3.0~beta
    15   - sudo apt-get install -q autoconf autotools-dev debhelper dh-autoreconf libglib2.0-dev libkrb5-dev libncurses5-dev libncursesw5-dev libssl-dev libzephyr-dev pkg-config zip
     12  - "5.20"
     13addons:
     14  apt:
     15    # we actually want debhelper >= 7, libperl-dev >= 5.10.1-8, libzephyr-dev >= 3.0~beta
     16    packages:
     17    - autoconf
     18    - autotools-dev
     19    - debhelper
     20    - dh-autoreconf
     21    - libglib2.0-dev
     22    - libkrb5-dev
     23    - libncurses5-dev
     24    - libncursesw5-dev
     25    - libssl-dev
     26    - libzephyr-dev
     27    - pkg-config
     28    - zip
    1629# perl things
    1730# In lp:~barnowl/barnowl/packaging, we use apt-get.  Here, we use cpanm.
    1831#  - sudo apt-get install libanyevent-perl libclass-accessor-perl libextutils-depends-perl libglib-perl libmodule-install-perl libnet-twitter-lite-perl libpar-perl libperl-dev
    19   - cpanm AnyEvent Class::Accessor ExtUtils::Depends Glib Module::Install Net::Twitter::Lite PAR
    20 script: "./autogen.sh && ./configure && make distcheck"
     32# It's taken care of by the default install script
     33script: ./autogen.sh && ./configure && make distcheck
  • ChangeLog

    r6f87658 r678a7650  
     11.10
     2 * No changes above what's already in 1.10rc1
     3
     41.10rc1
     5 * Numerous autotools/build machinery fixes -andersk@mit.edu
     6 * Numerous code correctness and simplification/cleanup fixes -andersk@mit.edu
     7 * Add and use a cpanfile documenting perl module dependencies -jgross@mit.edu
     8 * Add Travis configuration -jgross@mit.edu
     9 * Avoid strchrnul -andersk@mit.edu
     10 * Numerous IRC fixes -jgross@mit.edu
     11 * Improve smartnarrow and smartfilter documentation -jgross@mit.edu
     12 * filterproc: Rewrite using GIOChannel -andersk@mit.edu
     13 * Implement :twitter-favorite -nelhage@nelhage.com
     14 * Kill the client-side tweet length check. -nelhage@nelhage.com
     15 * squelch the Twitter legacy_list_api warnings -nelhage@nelhage.com
     16 * Use SSL for Twitter by default -adehnert@mit.edu
     17 * Humanize zsigs -andersk@mit.edu
     18 * Show Zephyr charset in info popup -andersk@mit.edu
     19 * Fix Jabber SRV record support (at one point fixed connecting via jabber to google talk or facebook) -james2vegas@aim.com
     20 * fix cmd_join in BarnOwl/Module/IRC.pm -james2vegas@aim.com
     21 * Add a ~/.owl/ircchannels file, persist channels -jgross@mit.edu
     22 * Added hooks for user going idle or active. -jgross@mit.edu
     23 * Support channel-or-user IRC commands, and setup irc-msg to use it. -ezyang@mit.edu
     24 * Refactor perl calls through a single method -jgross@mit.edu
     25 * Really support building Perl modules from a separate builddir -andersk@mit.edu
     26 * Get rid of all our embedded copies of Module::Install -andersk@mit.edu
     27 * Don't let new_variable_* overriding previously set values -rnjacobs@mit.edu
     28 * Messages sent to 'class messages' are not personal -jgross@mit.edu
     29 * Expose message_matches_filter to perl -jgross@mit.edu
     30 * Fail fast on -c filsrv, which most people won't have permission to send to -rnjacobs@mit.edu
     31 * zcrypt: Use getopt_long for argument parsing -andersk@mit.edu
     32 * zcrypt: Accept -help and --version -andersk@mit.edu
     33 * barnowl --help: Write to stdout and exit successfully -andersk@mit.edu
     34 * Don't swallow errors in :unsuball -davidben@mit.edu
     35 * Allow testing in a separate build directory -andersk@mit.edu
     36 * Add support for arbitrary Perl subs for getters and setters for barnowl variables -glasgall@mit.edu
     37 * owl_zephyr_loadsubs: Don’t leak memory on error opening ~/.zephyr.subs -andersk@mit.edu
     38 * Make :loadsubs reload instanced personals too -davidben@mit.edu
     39 * Fix some undefined behavior in filter.c, caught by clang scan-build -jgross@mit.edu
     40 * Die on a failed zephyr_zwrite; don't silently ignore it -jgross@mit.edu
     41 * Fix a memory leak in zcrypt.c, caught by clang scan-build -jgross@mit.edu
     42 * zcrypt: Make gpg stop messing around in ~/.gnupg -andersk@mit.edu
     43 * Fix display of pseudologins -davidben@mit.edu
     44 * Unbundle random Facebook module libraries -davidben@mit.edu
     45 * Replace deprecated GLib < 2.31.0 APIs -andersk@mit.edu
     46 * Abstract g->interrupt_lock -andersk@mit.edu
     47 * zephyr: Replace outgoing default format with a small URL -geofft@mit.edu
     48
    1491.9
    250 * Update Jabber module for Net::DNS changes -james2vegas@aim.com
  • commands.c

    rca1fb26a r4511ac3  
    153153  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
    154154              "set a variable value",
    155               "set [-q] [<variable>] [<value>]\n"
     155              "set [-q] <variable> [<value>]\n"
    156156              "set",
    157157              "Set the named variable to the specified value.  If no\n"
    … …  
    487487              "\n"
    488488              "SEE ALSO: aaway, zaway"),
     489
     490  OWLCMD_ARGS("flush-logs", owl_command_flushlogs, OWL_CTX_ANY,
     491              "flush the queue of messages waiting to be logged",
     492              "flush-logs [-f | --force] [-q | --quiet]",
     493              "If BarnOwl failed to log a file, this command tells\n"
     494              "BarnOwl to try logging the messages that have since\n"
     495              "come in, and to resume logging normally.\n"
     496              "\n"
     497              "Normally, if logging any of these messages fails,\n"
     498              "that message is added to the queue of messages waiting\n"
     499              "to be logged, and any new messages are deferred until\n"
     500              "the next :flush-logs.  If the --force flag is passed,\n"
     501              "any messages on the queue which cannot successfully be\n"
     502              "logged are dropped, and BarnOwl will resume logging\n"
     503              "normally.\n"
     504              "\n"
     505              "Unless --quiet is passed, a message is printed about\n"
     506              "how many logs there are to flush."),
    489507
    490508  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
    … …  
    548566              "optional color arguments are used they specifies the colors that\n"
    549567              "messages matching this filter should be displayed in.\n\n"
    550               "SEE ALSO: view, viewclass, viewuser\n"),
     568              "SEE ALSO: smartfilter, smartnarrow, view, viewclass, viewuser\n"),
    551569
    552570  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
    … …  
    585603              "filter expression that will be dynamically created by BarnOwl and then\n"
    586604              "applied as the view's filter\n"
    587               "SEE ALSO: filter, viewclass, viewuser\n"),
     605              "SEE ALSO: filter, smartfilter, smartnarrow, viewclass, viewuser\n"),
    588606
    589607  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
    … …  
    599617              "    then narrow to the class and instance.\n"
    600618              "If '-r' or '--related' is specified, behave as though the\n"
    601               "    'narrow-related' variable was inverted."),
     619              "    'narrow-related' variable was inverted.\n\n"
     620              "SEE ALSO: filter, smartfilter, view, viewclass, viewuser\n"),
    602621
    603622  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
    … …  
    610629              "If the curmsg is a class message, the filter is that class.\n"
    611630              "If the curmsg is a class message and '-i' is specified\n"
    612               "    the filter is to that class and instance.\n"),
     631              "    the filter is to that class and instance.\n\n"
     632              "SEE ALSO: filter, smartnarrow, view, viewclass, viewuser\n"),
    613633
    614634  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
    … …  
    618638              "matching the specified class and switch the current view\n"
    619639              "to it.\n\n"
    620               "SEE ALSO: filter, view, viewuser\n"),
     640              "SEE ALSO: filter, smartfilter, smartnarrow, view, viewuser\n"),
    621641  OWLCMD_ALIAS("vc", "viewclass"),
    622642
    … …  
    627647              "matching the specified user and switch the current\n"
    628648              "view to it.\n\n"
    629               "SEE ALSO: filter, view, viewclass\n"),
     649              "SEE ALSO: filter, smartfilter, smartnarrow, view, viewclass\n"),
    630650  OWLCMD_ALIAS("vu", "viewuser"),
    631651  OWLCMD_ALIAS("viewperson", "viewuser"),
    … …  
    14331453{
    14341454  owl_function_unsuball();
     1455}
     1456
     1457char *owl_command_flushlogs(int argc, const char *const *argv, const char *buff)
     1458{
     1459  bool force = false;
     1460  bool quiet = false;
     1461  int i;
     1462
     1463  for (i = 1; i < argc; i++) {
     1464    if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--force")) {
     1465      force = true;
     1466    } else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--quiet")) {
     1467      quiet = true;
     1468    } else {
     1469      owl_function_makemsg("Invalid flag to flush-logs: %s", argv[i]);
     1470    }
     1471  }
     1472  owl_log_flush_logs(force, quiet);
     1473  return NULL;
    14351474}
    14361475
  • configure.ac

    r77dfeb1 r370d94d  
    11dnl Process this file with autoconf to produce a configure script.
    2 AC_INIT([BarnOwl],[1.10dev],[bug-barnowl@mit.edu])
     2AC_INIT([BarnOwl],[1.11dev],[bug-barnowl@mit.edu])
    33AM_INIT_AUTOMAKE([1.7.0 foreign std-options -Wall -Wno-portability])
    44AM_MAINTAINER_MODE([enable])
  • filterproc.c

    r7155955 re8db357  
    11#include "filterproc.h"
    22#include <sys/wait.h>
    3 #include <fcntl.h>
     3#include <string.h>
    44#include <glib.h>
    5 #include <poll.h>
    6 #include <string.h>
    7 #include <unistd.h>
    85
    9 /* Even in case of error, send_receive is responsible for closing wfd
    10  * (to EOF the child) and rfd (for consistency). */
    11 static int send_receive(int rfd, int wfd, const char *out, char **in)
     6struct filter_data {
     7  const char **in;
     8  const char *in_end;
     9  GString *out_str;
     10  GMainLoop *loop;
     11  int err;
     12};
     13
     14static gboolean filter_stdin(GIOChannel *channel, GIOCondition condition, gpointer data_)
    1215{
    13   GString *str = g_string_new("");
    14   char buf[1024];
    15   nfds_t nfds;
    16   int err = 0;
    17   struct pollfd fds[2];
     16  struct filter_data *data = data_;
     17  gboolean done = condition & (G_IO_ERR | G_IO_HUP);
    1818
    19   fcntl(rfd, F_SETFL, O_NONBLOCK | fcntl(rfd, F_GETFL));
    20   fcntl(wfd, F_SETFL, O_NONBLOCK | fcntl(wfd, F_GETFL));
    21 
    22   fds[0].fd = rfd;
    23   fds[0].events = POLLIN;
    24   fds[1].fd = wfd;
    25   fds[1].events = POLLOUT;
    26 
    27   if(!out || !*out) {
    28     /* Nothing to write. Close our end so the child doesn't hang waiting. */
    29     close(wfd); wfd = -1;
    30     out = NULL;
     19  if (condition & G_IO_OUT) {
     20    gsize n;
     21    GIOStatus ret = g_io_channel_write_chars(channel, *data->in, data->in_end - *data->in, &n, NULL);
     22    *data->in += n;
     23    if (ret == G_IO_STATUS_ERROR)
     24      data->err = 1;
     25    if (ret == G_IO_STATUS_ERROR || *data->in == data->in_end)
     26      done = TRUE;
    3127  }
    3228
    33   while(1) {
    34     if(out && *out) {
    35       nfds = 2;
    36     } else {
    37       nfds = 1;
    38     }
    39     err = poll(fds, nfds, -1);
    40     if(err < 0) {
    41       break;
    42     }
    43     if(out && *out) {
    44       if(fds[1].revents & POLLOUT) {
    45         err = write(wfd, out, strlen(out));
    46         if(err > 0) {
    47           out += err;
    48         }
    49         if(err < 0) {
    50           out = NULL;
    51         }
    52       }
    53       if(!out || !*out || fds[1].revents & (POLLERR | POLLHUP)) {
    54         close(wfd); wfd = -1;
    55         out = NULL;
    56       }
    57     }
    58     if(fds[0].revents & POLLIN) {
    59       err = read(rfd, buf, sizeof(buf));
    60       if(err <= 0) {
    61         break;
    62       }
    63       g_string_append_len(str, buf, err);
    64     } else if(fds[0].revents & (POLLHUP | POLLERR)) {
    65       err = 0;
    66       break;
     29  if (condition & G_IO_ERR)
     30    data->err = 1;
     31
     32  if (done)
     33    g_io_channel_shutdown(channel, TRUE, NULL);
     34  return !done;
     35}
     36
     37static gboolean filter_stdout(GIOChannel *channel, GIOCondition condition, gpointer data_)
     38{
     39  struct filter_data *data = data_;
     40  gboolean done = condition & (G_IO_ERR | G_IO_HUP);
     41
     42  if (condition & (G_IO_IN | G_IO_HUP)) {
     43    gchar *buf;
     44    gsize n;
     45    GIOStatus ret = g_io_channel_read_to_end(channel, &buf, &n, NULL);
     46    g_string_append_len(data->out_str, buf, n);
     47    g_free(buf);
     48    if (ret == G_IO_STATUS_ERROR) {
     49      data->err = 1;
     50      done = TRUE;
    6751    }
    6852  }
    6953
    70   if (wfd >= 0) close(wfd);
    71   close(rfd);
    72   *in = g_string_free(str, err < 0);
    73   return err;
     54  if (condition & G_IO_ERR)
     55    data->err = 1;
     56
     57  if (done) {
     58    g_io_channel_shutdown(channel, TRUE, NULL);
     59    g_main_loop_quit(data->loop);
     60  }
     61  return !done;
    7462}
    7563
    7664int call_filter(const char *const *argv, const char *in, char **out, int *status)
    7765{
    78   int err;
    7966  GPid child_pid;
    8067  int child_stdin, child_stdout;
    … …  
    8976  }
    9077
    91   err = send_receive(child_stdout, child_stdin, in, out);
    92   if (err == 0) {
    93     waitpid(child_pid, status, 0);
    94   }
    95   return err;
     78  if (in == NULL) in = "";
     79  GMainContext *context = g_main_context_new();
     80  struct filter_data data = {&in, in + strlen(in), g_string_new(""), g_main_loop_new(context, FALSE), 0};
     81
     82  GIOChannel *channel = g_io_channel_unix_new(child_stdin);
     83  g_io_channel_set_encoding(channel, NULL, NULL);
     84  g_io_channel_set_flags(channel, g_io_channel_get_flags(channel) | G_IO_FLAG_NONBLOCK, NULL);
     85  GSource *source = g_io_create_watch(channel, G_IO_OUT | G_IO_ERR | G_IO_HUP);
     86  g_io_channel_unref(channel);
     87  g_source_set_callback(source, (GSourceFunc)filter_stdin, &data, NULL);
     88  g_source_attach(source, context);
     89  g_source_unref(source);
     90
     91  channel = g_io_channel_unix_new(child_stdout);
     92  g_io_channel_set_encoding(channel, NULL, NULL);
     93  g_io_channel_set_flags(channel, g_io_channel_get_flags(channel) | G_IO_FLAG_NONBLOCK, NULL);
     94  source = g_io_create_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP);
     95  g_io_channel_unref(channel);
     96  g_source_set_callback(source, (GSourceFunc)filter_stdout, &data, NULL);
     97  g_source_attach(source, context);
     98  g_source_unref(source);
     99
     100  g_main_loop_run(data.loop);
     101
     102  g_main_loop_unref(data.loop);
     103  g_main_context_unref(context);
     104
     105  waitpid(child_pid, status, 0);
     106  g_spawn_close_pid(child_pid);
     107  *out = g_string_free(data.out_str, data.err);
     108  return data.err;
    96109}
  • 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
  • keys.c

    rdcd48ad rd400776  
    4444  BIND_CMD("M-RIGHT",     "edit:move-next-word", "");
    4545  BIND_CMD("M-[ 1 ; 3 D", "edit:move-next-word", "");
     46  BIND_CMD("M-[ 1 ; 5 D", "edit:move-next-word", "");
    4647  BIND_CMD("M-b",         "edit:move-prev-word", "");
    4748  BIND_CMD("M-O 3 D",     "edit:move-prev-word", "");
    4849  BIND_CMD("M-LEFT",      "edit:move-prev-word", "");
    49   BIND_CMD("M-[ 1 ; 3 C", "edit:move-next-word", "");
     50  BIND_CMD("M-[ 1 ; 3 C", "edit:move-prev-word", "");
     51  BIND_CMD("M-[ 1 ; 5 C", "edit:move-prev-word", "");
    5052
    5153  BIND_CMD("LEFT",        "edit:move-left", "");
  • logging.c

    r7dcef03 r0c059f0  
    77} owl_log_entry;
    88
     9typedef struct _owl_log_options { /* noproto */
     10  bool drop_failed_logs;
     11  bool display_initial_log_count;
     12} owl_log_options;
    913
    1014static GMainContext *log_context;
    1115static GMainLoop *log_loop;
    1216static GThread *logging_thread;
    13 
    14 /* This is now the one function that should be called to log a
    15  * message.  It will do all the work necessary by calling the other
    16  * functions in this file as necessary.
     17static bool defer_logs; /* to be accessed only on the disk-writing thread */
     18static GQueue *deferred_entry_queue;
     19
     20static void owl_log_error_main_thread(gpointer data)
     21{
     22  owl_function_error("%s", (const char*)data);
     23}
     24
     25static void owl_log_adminmsg_main_thread(gpointer data)
     26{
     27  owl_function_adminmsg("Logging", (const char*)data);
     28}
     29
     30static void owl_log_makemsg_main_thread(gpointer data)
     31{
     32  owl_function_makemsg("%s", (const char*)data);
     33}
     34
     35static void G_GNUC_PRINTF(1, 2) owl_log_error(const char *fmt, ...)
     36{
     37  va_list ap;
     38  char *data;
     39
     40  va_start(ap, fmt);
     41  data = g_strdup_vprintf(fmt, ap);
     42  va_end(ap);
     43
     44  owl_select_post_task(owl_log_error_main_thread,
     45                       data, g_free, g_main_context_default());
     46}
     47
     48static void G_GNUC_PRINTF(1, 2) owl_log_adminmsg(const char *fmt, ...)
     49{
     50  va_list ap;
     51  char *data;
     52
     53  va_start(ap, fmt);
     54  data = g_strdup_vprintf(fmt, ap);
     55  va_end(ap);
     56
     57  owl_select_post_task(owl_log_adminmsg_main_thread,
     58                       data, g_free, g_main_context_default());
     59}
     60
     61static void G_GNUC_PRINTF(1, 2) owl_log_makemsg(const char *fmt, ...)
     62{
     63  va_list ap;
     64  char *data;
     65
     66  va_start(ap, fmt);
     67  data = g_strdup_vprintf(fmt, ap);
     68  va_end(ap);
     69
     70  owl_select_post_task(owl_log_makemsg_main_thread,
     71                       data, g_free, g_main_context_default());
     72}
     73
     74static CALLER_OWN owl_log_entry *owl_log_new_entry(const char *buffer, const char *filename)
     75{
     76  owl_log_entry *log_msg = g_slice_new(owl_log_entry);
     77  log_msg->message = g_strdup(buffer);
     78  log_msg->filename = g_strdup(filename);
     79  return log_msg;
     80}
     81
     82static void owl_log_deferred_enqueue_message(const char *buffer, const char *filename)
     83{
     84  g_queue_push_tail(deferred_entry_queue, owl_log_new_entry(buffer, filename));
     85}
     86
     87static void owl_log_deferred_enqueue_first_message(const char *buffer, const char *filename)
     88{
     89  g_queue_push_head(deferred_entry_queue, owl_log_new_entry(buffer, filename));
     90}
     91
     92/* write out the entry if possible
     93 * return 0 on success, errno on failure to open
    1794 */
    18 void owl_log_message(const owl_message *m) {
    19   owl_function_debugmsg("owl_log_message: entering");
    20 
    21   if (m == NULL) {
    22     owl_function_debugmsg("owl_log_message: passed null message");
    23     return;
    24   }
    25 
    26   /* should we be logging this message? */
    27   if (!owl_log_shouldlog_message(m)) {
    28     owl_function_debugmsg("owl_log_message: not logging message");
    29     return;
    30   }
    31 
    32   /* handle incmoing messages */
    33   if (owl_message_is_direction_in(m)) {
    34     owl_log_incoming(m);
    35     owl_function_debugmsg("owl_log_message: leaving");
    36     return;
    37   }
    38 
    39   /* handle outgoing messages */
    40   owl_log_outgoing(m);
    41 
    42   owl_function_debugmsg("owl_log_message: leaving");
    43 }
    44 
    45 /* Return 1 if we should log the given message, otherwise return 0 */
    46 int owl_log_shouldlog_message(const owl_message *m) {
    47   const owl_filter *f;
    48 
    49   /* If there's a logfilter and this message matches it, log */
    50   f=owl_global_get_filter(&g, owl_global_get_logfilter(&g));
    51   if (f && owl_filter_message_match(f, m)) return(1);
    52 
    53   /* otherwise we do things based on the logging variables */
    54 
    55   /* skip login/logout messages if appropriate */
    56   if (!owl_global_is_loglogins(&g) && owl_message_is_loginout(m)) return(0);
    57      
    58   /* check direction */
    59   if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) && owl_message_is_direction_out(m)) {
    60     return(0);
    61   }
    62   if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) && owl_message_is_direction_in(m)) {
    63     return(0);
    64   }
    65 
    66   if (owl_message_is_type_zephyr(m)) {
    67     if (owl_message_is_personal(m) && !owl_global_is_logging(&g)) return(0);
    68     if (!owl_message_is_personal(m) && !owl_global_is_classlogging(&g)) return(0);
    69   } else {
    70     if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
    71       if (!owl_global_is_logging(&g)) return(0);
    72     } else {
    73       if (!owl_global_is_classlogging(&g)) return(0);
    74     }
    75   }
    76   return(1);
    77 }
    78 
    79 CALLER_OWN char *owl_log_zephyr(const owl_message *m)
    80 {
    81     char *tmp = NULL;
    82     GString *buffer = NULL;
    83     buffer = g_string_new("");
    84     tmp = short_zuser(owl_message_get_sender(m));
    85     g_string_append_printf(buffer, "Class: %s Instance: %s",
    86                            owl_message_get_class(m),
    87                            owl_message_get_instance(m));
    88     if (strcmp(owl_message_get_opcode(m), "")) {
    89       g_string_append_printf(buffer, " Opcode: %s",
    90                              owl_message_get_opcode(m));
    91     }
    92     g_string_append_printf(buffer, "\n");
    93     g_string_append_printf(buffer, "Time: %s Host: %s\n",
    94                            owl_message_get_timestr(m),
    95                            owl_message_get_hostname(m));
    96     g_string_append_printf(buffer, "From: %s <%s>\n\n",
    97                            owl_message_get_zsig(m), tmp);
    98     g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    99     g_free(tmp);
    100     return g_string_free(buffer, FALSE);
    101 }
    102 
    103 CALLER_OWN char *owl_log_aim(const owl_message *m)
    104 {
    105     GString *buffer = NULL;
    106     buffer = g_string_new("");
    107     g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
    108                            owl_message_get_sender(m), owl_message_get_recipient(m));
    109     g_string_append_printf(buffer, "Time: %s\n\n",
    110                            owl_message_get_timestr(m));
    111     if (owl_message_is_login(m)) {
    112         g_string_append_printf(buffer, "LOGIN\n\n");
    113     } else if (owl_message_is_logout(m)) {
    114         g_string_append_printf(buffer, "LOGOUT\n\n");
    115     } else {
    116         g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    117     }
    118     return g_string_free(buffer, FALSE);
    119 }
    120 
    121 CALLER_OWN char *owl_log_jabber(const owl_message *m)
    122 {
    123     GString *buffer = NULL;
    124     buffer = g_string_new("");
    125     g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
    126                            owl_message_get_sender(m),
    127                            owl_message_get_recipient(m));
    128     g_string_append_printf(buffer, "Time: %s\n\n",
    129                            owl_message_get_timestr(m));
    130     g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m));
    131     return g_string_free(buffer, FALSE);
    132 }
    133 
    134 CALLER_OWN char *owl_log_generic(const owl_message *m)
    135 {
    136     GString *buffer;
    137     buffer = g_string_new("");
    138     g_string_append_printf(buffer, "From: <%s> To: <%s>\n",
    139                            owl_message_get_sender(m),
    140                            owl_message_get_recipient(m));
    141     g_string_append_printf(buffer, "Time: %s\n\n",
    142                            owl_message_get_timestr(m));
    143     g_string_append_printf(buffer, "%s\n\n",
    144                            owl_message_get_body(m));
    145     return g_string_free(buffer, FALSE);
    146 }
    147 
    148 static void owl_log_error_main_thread(gpointer data)
    149 {
    150   owl_function_error("%s", (const char*)data);
    151 }
    152 
    153 static void owl_log_error(const char *message)
    154 {
    155   char *data = g_strdup(message);
    156   owl_select_post_task(owl_log_error_main_thread,
    157                        data, g_free, g_main_context_default());
    158 }
    159 
    160 static void owl_log_write_entry(gpointer data)
    161 {
    162   owl_log_entry *msg = (owl_log_entry*)data;
     95static int owl_log_try_write_entry(owl_log_entry *msg)
     96{
    16397  FILE *file = NULL;
    16498  file = fopen(msg->filename, "a");
    16599  if (!file) {
    166     owl_log_error("Unable to open file for logging");
    167     return;
     100    return errno;
    168101  }
    169102  fprintf(file, "%s", msg->message);
    170103  fclose(file);
    171 }
    172 
    173 static void owl_log_entry_free(void *data)
     104  return 0;
     105}
     106
     107static void owl_log_entry_delete(void *data)
    174108{
    175109  owl_log_entry *msg = (owl_log_entry*)data;
    176   if (msg) {
    177     g_free(msg->message);
    178     g_free(msg->filename);
    179     g_slice_free(owl_log_entry, msg);
    180   }
     110  g_free(msg->message);
     111  g_free(msg->filename);
     112  g_slice_free(owl_log_entry, msg);
     113}
     114
     115#if GLIB_CHECK_VERSION(2, 32, 0)
     116#else
     117static void owl_log_entry_delete_gfunc(gpointer data, gpointer user_data)
     118{
     119  owl_log_entry_delete(data);
     120}
     121#endif
     122
     123static void owl_log_file_error(owl_log_entry *msg, int errnum)
     124{
     125  owl_log_error("Unable to open file for logging: %s (file %s)",
     126                g_strerror(errnum),
     127                msg->filename);
     128}
     129
     130/* If we are deferring log messages, enqueue this entry for writing.
     131 * Otherwise, try to write this log message, and, if it fails with
     132 * EPERM, EACCES, or ETIMEDOUT, go into deferred logging mode and
     133 * queue an admin message.  If it fails with anything else, display an
     134 * error message, drop the log message, and do not go into deferred
     135 * logging mode.
     136 *
     137 * N.B. This function is called only on the disk-writing thread. */
     138static void owl_log_eventually_write_entry(gpointer data)
     139{
     140  int ret;
     141  owl_log_entry *msg = (owl_log_entry*)data;
     142  if (defer_logs) {
     143    owl_log_deferred_enqueue_message(msg->message, msg->filename);
     144  } else {
     145    ret = owl_log_try_write_entry(msg);
     146    if (ret == EPERM || ret == EACCES || ret == ETIMEDOUT) {
     147      defer_logs = true;
     148      owl_log_error("Unable to open file for logging (%s): \n"
     149                    "%s.  \n"
     150                    "Consider renewing your tickets.  Logging has been \n"
     151                    "suspended, and your messages will be saved.  To \n"
     152                    "resume logging, use the command :flush-logs.\n\n",
     153                    msg->filename,
     154                    g_strerror(ret));
     155      /* If we were not in deferred logging mode, either the queue should be
     156       * empty, or we are attempting to log a message that we just popped off
     157       * the head of the queue.  Either way, we should enqueue this message as
     158       * the first message in the queue, rather than the last, so that we
     159       * preserve message ordering. */
     160      owl_log_deferred_enqueue_first_message(msg->message, msg->filename);
     161    } else if (ret != 0) {
     162      owl_log_file_error(msg, ret);
     163    }
     164  }
     165}
     166
     167/* tries to write the deferred log entries
     168 *
     169 * N.B. This function is called only on the disk-writing thread. */
     170static void owl_log_write_deferred_entries(gpointer data)
     171{
     172  owl_log_entry *entry;
     173  owl_log_options *opts = (owl_log_options *)data;
     174  int ret;
     175  int logged_message_count = 0;
     176  bool all_succeeded = true;
     177
     178  if (opts->display_initial_log_count) {
     179    if (g_queue_is_empty(deferred_entry_queue)) {
     180      owl_log_makemsg("There are no logs to flush.");
     181    } else {
     182      owl_log_makemsg("Attempting to flush %u logs...",
     183                      g_queue_get_length(deferred_entry_queue));
     184    }
     185  }
     186
     187  defer_logs = false;
     188  while (!g_queue_is_empty(deferred_entry_queue) && !defer_logs) {
     189    logged_message_count++;
     190    entry = (owl_log_entry*)g_queue_pop_head(deferred_entry_queue);
     191    if (!opts->drop_failed_logs) {
     192      /* Attempt to write the log entry.  If it fails, re-queue the entry at
     193       * the head of the queue. */
     194      owl_log_eventually_write_entry(entry);
     195    } else {
     196      /* Attempt to write the log entry. If it fails, print an error message,
     197       * drop the log, and keep going through the queue. */
     198      ret = owl_log_try_write_entry(entry);
     199      if (ret != 0) {
     200        all_succeeded = false;
     201        owl_log_file_error(entry, ret);
     202      }
     203    }
     204    owl_log_entry_delete(entry);
     205  }
     206  if (logged_message_count > 0) {
     207    if (opts->display_initial_log_count) {
     208      /* first clear the "attempting to flush" message from the status bar */
     209      owl_log_makemsg("");
     210    }
     211    if (!defer_logs) {
     212      if (all_succeeded) {
     213        owl_log_adminmsg("Flushed %d logs and resumed logging.",
     214                         logged_message_count);
     215      } else {
     216        owl_log_adminmsg("Flushed or dropped %d logs and resumed logging.",
     217                         logged_message_count);
     218      }
     219    } else {
     220      owl_log_error("Attempted to flush %d logs; %u deferred logs remain.",
     221                    logged_message_count, g_queue_get_length(deferred_entry_queue));
     222    }
     223  }
     224}
     225
     226void owl_log_flush_logs(bool drop_failed_logs, bool quiet)
     227{
     228  owl_log_options *data = g_new(owl_log_options, 1);
     229  data->drop_failed_logs = drop_failed_logs;
     230  data->display_initial_log_count = !quiet;
     231
     232  owl_select_post_task(owl_log_write_deferred_entries,
     233                       data,
     234                       g_free,
     235                       log_context);
    181236}
    182237
    183238void owl_log_enqueue_message(const char *buffer, const char *filename)
    184239{
    185   owl_log_entry *log_msg = NULL;
    186   log_msg = g_slice_new(owl_log_entry);
    187   log_msg->message = g_strdup(buffer);
    188   log_msg->filename = g_strdup(filename);
    189   owl_select_post_task(owl_log_write_entry, log_msg,
    190                        owl_log_entry_free, log_context);
    191 }
    192 
    193 void owl_log_append(const owl_message *m, const char *filename) {
    194   char *buffer = NULL;
    195   if (owl_message_is_type_zephyr(m)) {
    196     buffer = owl_log_zephyr(m);
    197   } else if (owl_message_is_type_jabber(m)) {
    198     buffer = owl_log_jabber(m);
    199   } else if (owl_message_is_type_aim(m)) {
    200     buffer = owl_log_aim(m);
    201   } else {
    202     buffer = owl_log_generic(m);
    203   }
    204   owl_log_enqueue_message(buffer, filename);
    205   g_free(buffer);
    206 }
    207 
    208 void owl_log_outgoing(const owl_message *m)
    209 {
    210   char *filename, *logpath;
    211   char *to, *temp;
    212   GList *cc;
    213 
    214   /* expand ~ in path names */
    215   logpath = owl_util_makepath(owl_global_get_logpath(&g));
    216 
    217   /* Figure out what path to log to */
    218   if (owl_message_is_type_zephyr(m)) {
    219     /* If this has CC's, do all but the "recipient" which we'll do below */
    220     cc = owl_message_get_cc_without_recipient(m);
    221     while (cc != NULL) {
    222       temp = short_zuser(cc->data);
    223       filename = g_build_filename(logpath, temp, NULL);
    224       owl_log_append(m, filename);
    225 
    226       g_free(filename);
    227       g_free(temp);
    228       g_free(cc->data);
    229       cc = g_list_delete_link(cc, cc);
    230     }
    231 
    232     to = short_zuser(owl_message_get_recipient(m));
    233   } else if (owl_message_is_type_jabber(m)) {
    234     to = g_strdup_printf("jabber:%s", owl_message_get_recipient(m));
    235     g_strdelimit(to, "/", '_');
    236   } else if (owl_message_is_type_aim(m)) {
    237     char *temp2;
    238     temp = owl_aim_normalize_screenname(owl_message_get_recipient(m));
    239     temp2 = g_utf8_strdown(temp,-1);
    240     to = g_strdup_printf("aim:%s", temp2);
    241     g_free(temp2);
    242     g_free(temp);
    243   } else {
    244     to = g_strdup("loopback");
    245   }
    246 
    247   filename = g_build_filename(logpath, to, NULL);
    248   owl_log_append(m, filename);
    249   g_free(to);
    250   g_free(filename);
    251 
    252   filename = g_build_filename(logpath, "all", NULL);
    253   owl_log_append(m, filename);
    254   g_free(logpath);
    255   g_free(filename);
    256 }
    257 
     240  owl_log_entry *log_msg = owl_log_new_entry(buffer, filename);
     241  owl_select_post_task(owl_log_eventually_write_entry, log_msg,
     242                       owl_log_entry_delete, log_context);
     243}
    258244
    259245void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text)
    260246{
    261   char *filename, *logpath;
    262   char *tobuff, *recip;
    263   owl_message *m;
    264   GString *msgbuf;
    265   /* create a present message so we can pass it to
    266    * owl_log_shouldlog_message(void)
    267    */
    268   m = g_slice_new(owl_message);
     247  owl_message *m = g_slice_new(owl_message);
    269248  /* recip_index = 0 because there can only be one recipient anyway */
    270249  owl_message_create_from_zwrite(m, zw, text, 0);
    271   if (!owl_log_shouldlog_message(m)) {
    272     owl_message_delete(m);
    273     return;
    274   }
     250  g_free(owl_perlconfig_call_with_message("BarnOwl::Logging::log_outgoing_error", m));
    275251  owl_message_delete(m);
    276 
    277   /* chop off a local realm */
    278   recip = owl_zwrite_get_recip_n_with_realm(zw, 0);
    279   tobuff = short_zuser(recip);
    280   g_free(recip);
    281 
    282   /* expand ~ in path names */
    283   logpath = owl_util_makepath(owl_global_get_logpath(&g));
    284   filename = g_build_filename(logpath, tobuff, NULL);
    285   msgbuf = g_string_new("");
    286   g_string_printf(msgbuf, "ERROR (owl): %s\n%s\n", tobuff, text);
    287   if (text[strlen(text)-1] != '\n') {
    288     g_string_append_printf(msgbuf, "\n");
    289   }
    290   owl_log_enqueue_message(msgbuf->str, filename);
    291   g_string_free(msgbuf, TRUE);
    292 
    293   filename = g_build_filename(logpath, "all", NULL);
    294   g_free(logpath);
    295   msgbuf = g_string_new("");
    296   g_string_printf(msgbuf, "ERROR (owl): %s\n%s\n", tobuff, text);
    297   if (text[strlen(text)-1] != '\n') {
    298     g_string_append_printf(msgbuf, "\n");
    299   }
    300   owl_log_enqueue_message(msgbuf->str, filename);
    301   g_string_free(msgbuf, TRUE);
    302 
    303   g_free(tobuff);
    304 }
    305 
    306 void owl_log_incoming(const owl_message *m)
    307 {
    308   char *filename, *allfilename, *logpath;
    309   const char *from=NULL;
    310   char *frombuff=NULL;
    311   int len, ch, i, personal;
    312 
    313   /* figure out if it's a "personal" message or not */
    314   if (owl_message_is_type_zephyr(m)) {
    315     if (owl_message_is_personal(m)) {
    316       personal = 1;
    317     } else {
    318       personal = 0;
    319     }
    320   } else if (owl_message_is_type_jabber(m)) {
    321     /* This needs to be fixed to handle groupchat */
    322     const char* msgtype = owl_message_get_attribute_value(m,"jtype");
    323     if (msgtype && !strcmp(msgtype,"groupchat")) {
    324       personal = 0;
    325     } else {
    326       personal = 1;
    327     }
    328   } else {
    329     if (owl_message_is_private(m) || owl_message_is_loginout(m)) {
    330       personal = 1;
    331     } else {
    332       personal = 0;
    333     }
    334   }
    335 
    336 
    337   if (owl_message_is_type_zephyr(m)) {
    338     if (personal) {
    339       from=frombuff=short_zuser(owl_message_get_sender(m));
    340     } else {
    341       from=frombuff=g_strdup(owl_message_get_class(m));
    342     }
    343   } else if (owl_message_is_type_aim(m)) {
    344     /* we do not yet handle chat rooms */
    345     char *normalto, *temp;
    346     temp = owl_aim_normalize_screenname(owl_message_get_sender(m));
    347     normalto = g_utf8_strdown(temp, -1);
    348     from=frombuff=g_strdup_printf("aim:%s", normalto);
    349     g_free(normalto);
    350     g_free(temp);
    351   } else if (owl_message_is_type_loopback(m)) {
    352     from=frombuff=g_strdup("loopback");
    353   } else if (owl_message_is_type_jabber(m)) {
    354     if (personal) {
    355       from=frombuff=g_strdup_printf("jabber:%s",
    356                                     owl_message_get_sender(m));
    357     } else {
    358       from=frombuff=g_strdup_printf("jabber:%s",
    359                                     owl_message_get_recipient(m));
    360     }
    361   } else {
    362     from=frombuff=g_strdup("unknown");
    363   }
    364  
    365   /* check for malicious sender formats */
    366   len=strlen(frombuff);
    367   if (len<1 || len>35) from="weird";
    368   if (strchr(frombuff, '/')) from="weird";
    369 
    370   ch=frombuff[0];
    371   if (!g_ascii_isalnum(ch)) from="weird";
    372 
    373   for (i=0; i<len; i++) {
    374     if (frombuff[i]<'!' || frombuff[i]>='~') from="weird";
    375   }
    376 
    377   if (!strcmp(frombuff, ".") || !strcasecmp(frombuff, "..")) from="weird";
    378 
    379   if (!personal) {
    380     if (strcmp(from, "weird")) {
    381       char* temp = g_utf8_strdown(frombuff, -1);
    382       if (temp) {
    383         g_free(frombuff);
    384         from = frombuff = temp;
    385       }
    386     }
    387   }
    388 
    389   /* create the filename (expanding ~ in path names) */
    390   if (personal) {
    391     logpath = owl_util_makepath(owl_global_get_logpath(&g));
    392     filename = g_build_filename(logpath, from, NULL);
    393     allfilename = g_build_filename(logpath, "all", NULL);
    394     owl_log_append(m, allfilename);
    395     g_free(allfilename);
    396   } else {
    397     logpath = owl_util_makepath(owl_global_get_classlogpath(&g));
    398     filename = g_build_filename(logpath, from, NULL);
    399   }
    400 
    401   owl_log_append(m, filename);
    402   g_free(filename);
    403 
    404   if (personal && owl_message_is_type_zephyr(m)) {
    405     /* We want to log to all of the CC'd people who were not us, or
    406      * the sender, as well.
    407      */
    408     char *temp;
    409     GList *cc;
    410     cc = owl_message_get_cc_without_recipient(m);
    411     while (cc != NULL) {
    412       temp = short_zuser(cc->data);
    413       if (strcasecmp(temp, frombuff) != 0) {
    414         filename = g_build_filename(logpath, temp, NULL);
    415         owl_log_append(m, filename);
    416         g_free(filename);
    417       }
    418 
    419       g_free(temp);
    420       g_free(cc->data);
    421       cc = g_list_delete_link(cc, cc);
    422     }
    423   }
    424 
    425   g_free(frombuff);
    426   g_free(logpath);
    427252}
    428253
    429254static gpointer owl_log_thread_func(gpointer data)
    430255{
     256  log_context = g_main_context_new();
    431257  log_loop = g_main_loop_new(log_context, FALSE);
    432258  g_main_loop_run(log_loop);
    … …  
    434260}
    435261
    436 void owl_log_init(void) 
     262void owl_log_init(void)
    437263{
    438264  log_context = g_main_context_new();
    … …  
    454280  }
    455281#endif
    456  
     282
     283  deferred_entry_queue = g_queue_new();
    457284}
    458285
    459286static void owl_log_quit_func(gpointer data)
    460287{
     288  /* flush the deferred logs queue, trying to write the
     289   * entries to the disk one last time.  Drop any failed
     290   * entries, and be quiet about it. */
     291  owl_log_options opts;
     292  opts.drop_failed_logs = true;
     293  opts.display_initial_log_count = false;
     294  owl_log_write_deferred_entries(&opts);
     295#if GLIB_CHECK_VERSION(2, 32, 0)
     296  g_queue_free_full(deferred_entry_queue, owl_log_entry_delete);
     297#else
     298  g_queue_foreach(deferred_entry_queue, owl_log_entry_delete_gfunc, NULL);
     299  g_queue_free(deferred_entry_queue);
     300#endif
     301
    461302  g_main_loop_quit(log_loop);
    462303}
  • owl.c

    r441fd42 r4ead7b3  
    230230  /* let perl know about it */
    231231  owl_perlconfig_newmsg(m, NULL);
    232   /* log the message if we need to */
    233   owl_log_message(m);
    234232  /* redraw the sepbar; TODO: don't violate layering */
    235233  owl_global_sepbar_dirty(&g);
  • perl/Makefile.am

    ra870319 reea7bed4  
    99        lib/BarnOwl/Completion/Context.pm \
    1010        lib/BarnOwl/Completion/Util.pm \
     11        lib/BarnOwl/DeferredLogging.pm \
    1112        lib/BarnOwl/Editwin.pm \
    1213        lib/BarnOwl/Help.pm \
    1314        lib/BarnOwl/Hook.pm \
    1415        lib/BarnOwl/Hooks.pm \
     16        lib/BarnOwl/Logging.pm \
    1517        lib/BarnOwl/MainLoopCompatHook.pm \
    1618        lib/BarnOwl/Message.pm \
  • perl/lib/BarnOwl.pm

    recd4edf reea7bed4  
    1616                    create_style getnumcolors wordwrap
    1717                    message_matches_filter
     18                    get_variable_info
    1819                    add_dispatch remove_dispatch
    1920                    add_io_dispatch remove_io_dispatch
    … …  
    3839use BarnOwl::Hook;
    3940use BarnOwl::Hooks;
     41use BarnOwl::Logging;
    4042use BarnOwl::Message;
    4143use BarnOwl::Style;
    … …  
    4547use BarnOwl::Completion;
    4648use BarnOwl::Help;
     49use BarnOwl::DeferredLogging;
    4750
    4851use List::Util qw(max);
    … …  
    249252C<QUIET> is false, this method displays an error message if
    250253if C<FILTER_NAME> does not name a valid filter.
     254
     255=head2 get_variable_info VARIABLE_NAME
     256
     257Returns a hash with the following keys, describing the variable named:
     258
     259=over
     260
     261=item name
     262
     263=item description
     264
     265=item summary
     266
     267=item validsettings
     268
     269=item takes_on_off
     270
     271=back
     272
     273Fails if C<VARIABLE_NAME> does not name a valid variable.
    251274
    252275=head2 add_dispatch FD CALLBACK
  • perl/lib/BarnOwl/Complete/Client.pm

    r4626016 r1f92f39  
    146146sub complete_set {
    147147    my $ctx = shift;
    148     return complete_flags($ctx,
    149         [qw(-q)],
    150         {
    151         },
    152          \&complete_set_args
    153         );
    154 }
    155 sub complete_set_args {
    156     my $ctx = shift;
    157     my $arg = shift;
    158     return if $arg;
    159     return complete_variable();
     148    my $is_unset = ($ctx->words->[0] eq "unset");
     149
     150    # Shift away the -q if seen.
     151    my $seen_q = 0;
     152    if ($ctx->word > 1 && $ctx->words->[1] eq "-q") {
     153        $seen_q = 1;
     154        $ctx = $ctx->shift_words(1);
     155    }
     156
     157    # First argument is the variable.
     158    if ($ctx->word == 1) {
     159        my @vars = complete_variable();
     160        if ($is_unset) {
     161            # Only complete the variables which are unsettable.
     162            @vars = grep { BarnOwl::get_variable_info($_)->{takes_on_off} } @vars;
     163        }
     164        unshift(@vars, "-q") unless $seen_q;
     165        return @vars;
     166    }
     167    # For set, second argument is the value.
     168    if (!$is_unset && $ctx->word == 2) {
     169        # Parse what we can out of validsettings.
     170        my $info;
     171        eval { $info = BarnOwl::get_variable_info($ctx->words->[1]) };
     172        return if $@;
     173        if ($info->{validsettings} eq "<path>") {
     174            return complete_file($ctx->words->[2]);
     175        } elsif ($info->{validsettings} !~ /^<.*>$/) {
     176            # Assume it's a comma-separated list of values;
     177            return split(",", $info->{validsettings});
     178        }
     179    }
     180    return;
    160181}
    161182
  • perl/lib/BarnOwl/Message.pm

    r0adbce1 r5dee79a  
    33
    44package BarnOwl::Message;
     5
     6use File::Spec;
    57
    68use BarnOwl::Message::Admin;
    … …  
    115117    }
    116118    return $s;
     119}
     120
     121=head2 log MESSAGE
     122
     123Returns the text that should be written to a file to log C<MESSAGE>.
     124
     125=cut
     126
     127sub log {
     128    my ($m) = @_;
     129    return $m->log_header . "\n\n" . $m->log_body . "\n\n";
     130}
     131
     132=head2 log_header MESSAGE
     133
     134Returns the header of the message, for logging purposes.
     135If you override L<BarnOwl::Message::log>, this method is not called.
     136
     137=cut
     138
     139sub log_header {
     140    my ($m) = @_;
     141    my $sender = $m->sender;
     142    my $recipient = $m->recipient;
     143    my $timestr = $m->time;
     144    return "From: <$sender> To: <$recipient>\n"
     145         . "Time: $timestr";
     146}
     147
     148=head2 log_body MESSAGE
     149
     150Returns the body of the message, for logging purposes.
     151If you override L<BarnOwl::Message::log>, this method is not called.
     152
     153=cut
     154
     155sub log_body {
     156    my ($m) = @_;
     157    if ($m->is_loginout) {
     158        return uc($m->login)
     159            . $m->login_type
     160            . ($m->login_extra ? ' at ' . $m->login_extra : '');
     161    } else {
     162        return $m->body;
     163    }
     164}
     165
     166=head2 log_filenames MESSAGE
     167
     168Returns a list of filenames to which this message should be logged.
     169The filenames should be relative to the path returned by C<log_path>.
     170See L<BarnOwl::Logging::get_filenames> for the specification of valid
     171filenames, and for what happens if this method returns an invalid
     172filename.
     173
     174=cut
     175
     176sub log_filenames {
     177    my ($m) = @_;
     178    my $filename;
     179    if ($m->is_incoming) {
     180        $filename = $m->pretty_sender;
     181    } elsif ($m->is_outgoing) {
     182        $filename = $m->pretty_recipient;
     183    }
     184    $filename = "unknown" if !defined($filename) || $filename eq '';
     185    if (BarnOwl::getvar('log-to-subdirectories') eq 'on') {
     186        return ($filename);
     187    } else {
     188        return ($m->log_subfolder . ':' . $filename);
     189    }
     190}
     191
     192=head2 log_to_all_file MESSAGE
     193
     194There is an C<all> file.  This method determines if C<MESSAGE>
     195should get logged to it, in addition to any files returned by
     196C<log_filenames>.
     197
     198It defaults to returning true if and only if C<MESSAGE> is outgoing.
     199
     200=cut
     201
     202sub log_to_all_file {
     203    my ($m) = @_;
     204    return $m->is_outgoing;
     205}
     206
     207=head2 log_path MESSAGE
     208
     209Returns the folder in which all messages of this class get logged.
     210
     211Defaults to C<log_base_path/log_subfolder> if C<log-to-subdirectories>
     212is enabled, or to the C<logpath> BarnOwl variable if it is not.
     213
     214Most protocols should override C<log_subfolder> rather than
     215C<log_path>, in order to properly take into account the value of
     216C<log-to-subdirectories>.
     217
     218=cut
     219
     220sub log_path {
     221    my ($m) = @_;
     222    if (BarnOwl::getvar('log-to-subdirectories') eq 'on') {
     223        return File::Spec->catfile($m->log_base_path, $m->log_subfolder);
     224    } else {
     225        return BarnOwl::getvar('logpath');
     226    }
     227}
     228
     229=head2 log_base_path MESSAGE
     230
     231Returns the base path for logging.  See C<log_path> for more information.
     232
     233Defaults to the BarnOwl variable C<logbasepath>.
     234
     235=cut
     236
     237sub log_base_path {
     238    return BarnOwl::getvar('logbasepath');
     239}
     240
     241=head2 log_subfolder MESSAGE
     242
     243Returns the subfolder of C<log_base_path> to log messages in.
     244
     245Defaults to C<lc($m->type)>.
     246
     247=cut
     248
     249sub log_subfolder {
     250    return lc(shift->type);
     251}
     252
     253=head2 log_outgoing_error MESSAGE
     254
     255Returns the string that should be logged if there is an error sending
     256an outgoing message.
     257
     258=cut
     259
     260sub log_outgoing_error {
     261    my ($m) = @_;
     262    my $recipient = $m->pretty_recipient;
     263    my $body = $m->body;
     264    chomp $body;
     265    return "ERROR (BarnOwl): $recipient\n$body\n\n";
     266}
     267
     268=head2 should_log MESSAGE
     269
     270Returns true if we should log C<MESSAGE>.  This does not override
     271user settings; if the BarnOwl variable C<loggingdirection> is in,
     272and C<MESSAGE> is outgoing and does not match the C<logfilter>, it
     273will not get logged regardless of what this method returns.
     274
     275Note that this method I<does> override the BarnOwl C<logging>
     276variable; if a derived class overrides this method and does not
     277provide an alternative BarnOwl variable (such as C<classlogging>),
     278the overriding method should check the BarnOwl C<logging> variable.
     279
     280Defaults to returning the value of the BarnOwl variable C<logging>.
     281
     282=cut
     283
     284sub should_log {
     285    return BarnOwl::getvar('logging') eq 'on';
    117286}
    118287
  • perl/lib/BarnOwl/Message/AIM.pm

    r7011c3dc reea7bed4  
    2424}
    2525
     26sub normalize_screenname {
     27    my ($screenname) = @_;
     28    $screenname =~ s/\s+//g;
     29    return lc($screenname);
     30}
     31
     32sub log_filenames {
     33    return map { normalize_screenname($_) } BarnOwl::Message::log_filenames(@_);
     34}
    2635
    27361;
  • perl/lib/BarnOwl/Message/Loopback.pm

    ree183be r8cec8f7  
    1414sub replysendercmd {return 'loopwrite';}
    1515
     16sub log_subfolder { return ''; }
     17sub log_filenames { return ('loopback'); }
    1618
    17191;
  • perl/lib/BarnOwl/Message/Zephyr.pm

    r0adbce1 r8f91a70  
    2121    my ($user, $realm) = split(/@/,$principal);
    2222    return $realm;
     23}
     24
     25sub casefold_principal {
     26    my $principal = shift;
     27    # split the principal right after the final @, without eating any
     28    # characters; this way, we always get at least '@' in $user
     29    my ($user, $realm) = split(/(?<=@)(?=[^@]+$)/, $principal);
     30    $user = '' if !defined $user;
     31    $user = lc($user);
     32    $user = $user . uc($realm) if defined $realm;
     33    return $user;
    2334}
    2435
    … …  
    132143    return $1 if $self->body =~ /^\s*cc:\s+([^\n]+)/i;
    133144    return undef;
     145}
     146
     147# Note: This is the cc-line without the recipient; it does not include
     148# the sender.
     149sub zephyr_cc_without_recipient {
     150    my $self = shift;
     151    my $recipient = lc(strip_realm($self->recipient));
     152    my $cc = $self->zephyr_cc;
     153    return grep { lc(strip_realm($_)) ne $recipient } split(/\s+/, $cc) if defined $cc;
     154    return ();
    134155}
    135156
    … …  
    223244}
    224245
     246# Logging
     247sub log_header {
     248    my ($m) = @_;
     249    my $class = $m->class;
     250    my $instance = $m->instance;
     251    my $opcode = $m->opcode;
     252    my $timestr = $m->time;
     253    my $host = $m->host;
     254    my $sender = $m->pretty_sender;
     255    my $zsig = $m->zsig;
     256    my $rtn = "Class: $class Instance: $instance";
     257    $rtn .= " Opcode: $opcode" unless !defined $opcode || $opcode eq '';
     258    $rtn .= "\nTime: $timestr Host: $host"
     259          . "\nFrom: $zsig <$sender>";
     260    return $rtn;
     261}
     262
     263sub log_filenames {
     264    my ($m) = @_;
     265    my @filenames = ();
     266    if ($m->is_personal) {
     267        # If this has CC's, add all but the "recipient" which we'll add below
     268        @filenames = $m->zephyr_cc_without_recipient;
     269    }
     270    if ($m->is_incoming) {
     271        if ($m->is_personal) {
     272            push @filenames, $m->sender;
     273        } else {
     274            my $realm = '';
     275            $realm .= '@' . $m->realm if $m->realm ne BarnOwl::zephyr_getrealm();
     276            return (BarnOwl::compat_casefold($m->class) . uc($realm));
     277        }
     278    } else {
     279        push @filenames, $m->recipient;
     280    }
     281    return map { casefold_principal(BarnOwl::zephyr_smartstrip_user(strip_realm($_))) } @filenames;
     282}
     283
     284sub log_to_class_file {
     285    my ($m) = @_;
     286    return !$m->is_personal;
     287}
     288
     289sub log_path {
     290    my ($m) = @_;
     291    if ($m->log_to_class_file) {
     292        return BarnOwl::getvar('classlogpath');
     293    } else {
     294        return BarnOwl::getvar('logpath');
     295    }
     296}
     297
     298sub should_log {
     299    my ($m) = @_;
     300    if ($m->log_to_class_file) {
     301        return BarnOwl::getvar('classlogging') eq 'on';
     302    } else {
     303        return BarnOwl::getvar('logging') eq 'on';
     304    }
     305}
    225306
    2263071;
  • perl/modules/IRC/lib/BarnOwl/Message/IRC.pm

    r60b49a7 r3f0c209  
    9292}
    9393
     94# logging
     95sub log_filenames {
     96    my ($m) = @_;
     97    die "IRC should not be handling non-IRC messages" if lc($m->type) ne "irc";
     98    BarnOwl::error("IRC message without a network") if !defined($m->network) || $m->network eq '';
     99    my $filename = lc($m->network);
     100    # Note: Channel names generally start with '#', which
     101    # disambiguates channels from individuals; for example, personals
     102    # will look like, e.g., "~/zlog/irc/freenode:john-doe", whereas
     103    # channels will look like, e.g., "~/zlog/irc/freenode:#barnowl"
     104    if ($m->is_personal) {
     105        if ($m->is_incoming) {
     106            $filename .= ":" . $m->sender;
     107        } elsif ($m->is_outgoing) {
     108            $filename .= ":" . $m->recipient;
     109        }
     110    } else {
     111        $filename .= ":" . $m->channel;
     112    }
     113    return ($filename);
     114}
     115
     116sub log {
     117    my ($m) = @_;
     118    my $sender = $m->sender;
     119    my $timestr = $m->time;
     120    my $body = $m->body;
     121    if ($m->is_loginout) {
     122        return BarnOwl::Message::log($m);
     123    } else {
     124        return "[$timestr] <$sender> $body\n";
     125    }
     126}
     127
    941281;
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    r926c721 rd4f33f1  
    562562                               "[" . $conn->alias . "] Reconnect cancelled");
    563563        $conn->cancel_reconnect;
     564        delete $ircnets{$conn->alias};
     565    } elsif (exists $ircnets{$conn->alias}) { # inconsistent state; no socket, but not yet deleted
     566        BarnOwl::admin_message('IRC',
     567                               "[" . $conn->alias . "] Attempt to disconnect from a socketless connection; deleting it");
    564568        delete $ircnets{$conn->alias};
    565569    }
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    rbe43554 r4379288  
    437437}
    438438
     439sub rejoin_channels {
     440    my $self = shift;
     441    my @channels = @_;
     442    # As reported in https://barnowl.mit.edu/ticket/274, if we reconnect to
     443    # too many at once, the server rejects us.  Empirically, this is about
     444    # 20-26, so we set the cap at 15, then delay further joins for 5 seconds.
     445    my $MAX_RECONNECT_CHANNELS = 15;
     446    my $DELAY = 5;
     447    foreach my $c (@channels[ 0 .. $MAX_RECONNECT_CHANNELS ]) {
     448        $self->conn->send_msg(join => $c);
     449    }
     450    if ($MAX_RECONNECT_CHANNELS < $#channels) {
     451        my $remaining = $#channels - $MAX_RECONNECT_CHANNELS;
     452        my $cur_alias = $self->alias;
     453        BarnOwl::admin_message('IRC', "[$cur_alias] Delaying $remaining autorejoins for $DELAY seconds");
     454        # if we don't assign the timer to anything, then it gets garbage
     455        # collected, and never runs
     456        $self->{autoconnect_channels_delay_timer} = BarnOwl::Timer->new({
     457            name  => "IRC rejoin overflow timer ($remaining remaining)",
     458            after => $DELAY,
     459            cb    => sub {
     460                rejoin_channels($self, @channels[ $MAX_RECONNECT_CHANNELS .. $#channels ]);
     461            }
     462        });
     463    }
     464}
     465
     466
    439467sub connected {
    440468    my $self = shift;
    … …  
    443471    $self->cancel_reconnect;
    444472    if ($self->autoconnect_channels) {
    445         for my $c (@{$self->autoconnect_channels}) {
    446             $self->conn->send_msg(join => $c);
    447         }
     473        rejoin_channels($self, @{$self->autoconnect_channels});
    448474    }
    449475    $self->conn->enable_ping(60, sub {
  • perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm

    ra27acf7 rd2ba33c  
    172172}
    173173
     174sub log_filenames {
     175    return map { BarnOwl::compat_casefold($_) } BarnOwl::Message::log_filenames(@_);
     176}
     177
    174178=head1 SEE ALSO
    175179
  • perl/modules/Makefile.am

    re4b8f93 r268c7e8  
    1 MODULES = Jabber IRC WordWrap Twitter Facebook
     1MODULES = Jabber IRC WordWrap Twitter Facebook Kerberos
    22
    33EXTRA_DIST = $(MODULES:=/Makefile.PL) $(MODULES:=/lib)
  • 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;
  • perlglue.xs

    r7dcef03 rd2ba33c  
    385385                RETVAL
    386386
     387SV *
     388get_variable_info(name)
     389        const char *name;
     390        PREINIT:
     391                owl_variable *var;
     392                HV *h;
     393        CODE:
     394                var = owl_variable_get_var(owl_global_get_vardict(&g), name);
     395                if (var == NULL) {
     396                        croak("No such variable");
     397                }
     398                h = newHV();
     399                (void)hv_store(h, "name", strlen("name"),
     400                               owl_new_sv(owl_variable_get_name(var)), 0);
     401                (void)hv_store(h, "description", strlen("description"),
     402                               owl_new_sv(owl_variable_get_description(var)),
     403                               0);
     404                (void)hv_store(h, "summary", strlen("summary"),
     405                               owl_new_sv(owl_variable_get_summary(var)), 0);
     406                (void)hv_store(h, "validsettings", strlen("validsettings"),
     407                               owl_new_sv(owl_variable_get_validsettings(var)),
     408                               0);
     409                (void)hv_store(h, "takes_on_off", strlen("takes_on_off"),
     410                               newSViv(owl_variable_takes_on_off(var)), 0);
     411                RETVAL = newRV_noinc((SV*)h);
     412        OUTPUT:
     413                RETVAL
     414
     415const utf8 *
     416compat_casefold(in)
     417        const char * in
     418        PREINIT:
     419                char *rv;
     420        CODE:
     421                rv = owl_util_compat_casefold(in);
     422                RETVAL = rv;
     423        OUTPUT:
     424                RETVAL
     425        CLEANUP:
     426                g_free(rv);
     427
    387428
    388429MODULE = BarnOwl                PACKAGE = BarnOwl::Zephyr
    … …  
    407448        OUTPUT:
    408449                RETVAL
     450
     451const utf8 *
     452makepath(in)
     453        const char * in
     454        PREINIT:
     455                char *rv;
     456        CODE:
     457                rv = owl_util_makepath(in);
     458                RETVAL = rv;
     459        OUTPUT:
     460                RETVAL
     461        CLEANUP:
     462                g_free(rv);
    409463
    410464void
    … …  
    642696        OUTPUT:
    643697                RETVAL
     698
     699MODULE = BarnOwl                PACKAGE = BarnOwl::Logging
     700
     701void
     702enqueue_text(log_text, filename)
     703        const char * log_text
     704        const char * filename
     705        CODE:
     706                owl_log_enqueue_message(log_text, filename);
  • scripts/do-release

    rb8a3e00 rbc308eb  
    1 #!/bin/sh -e
     1#!/bin/bash
     2set -eu
    23
    34die() {
    … …  
    5556fi
    5657
     58[ -e Makefile.in ] || autoreconf -fvi
     59[ -e config.status ] || ./configure
     60make -j4 distcheck VERSION="$VERS"
     61
     62echo 'Checking distributed files against Git:'
     63if comm -3 <(tar -tzf "$TAG.tar.gz" | grep -v '/$' | sed "s%^$TAG/%%" | sort) \
     64    <(git ls-files | sort) | grep -vxf scripts/dist-ignore; then
     65    echo
     66    echo 'Error: Please fix Makefile.am and/or scripts/dist-ignore.'
     67    exit 1
     68fi
     69echo 'ok'
     70
     71mv "$TAG.tar.gz" "$TGZ.tgz"
     72
    5773if ! [ "$no_tag" ]; then
    5874    if git cat-file -t "$TAG" > /dev/null 2>&1; then
    … …  
    6581fi
    6682
    67 exittrap() { :; }
    68 for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done
    69 trap 'exittrap' EXIT
    70 
    71 TMPDIR=$(mktemp -d /tmp/barnowl.XXXXXX)
    72 
    73 exittrap() { rm -rf "$TMPDIR"; }
    74 
    75 git archive --format=tar --prefix="$TGZ/" "$TAG" | tar -x -C "$TMPDIR"
    76 
    77 CODIR=$(pwd)
    78 cd "$TMPDIR/$TGZ"
    79 [ "$git" ] && perl -i -pe 's{^(AC_INIT\(\[[^\]]+\],\s*)\[([^\]]+)\]}{${1}['$VERS']}' configure.ac
    80 autoreconf -fvi
    81 rm -r autom4te.cache/
    82 cd "$TMPDIR"
    83 tar czvf "$TGZ.tgz" "$TGZ"
    84 cd "$CODIR"
    85 
    86 mv "$TMPDIR/$TGZ.tgz" .
    87 rm -rf "$TMPDIR"
    88 
    89 exittrap() { :; }
    90 
    91 echo "Created release tarball for BarnOwl $VERS in $(pwd)"
     83echo "Created release tarball for BarnOwl $VERS at $(pwd)/$TGZ.tgz"
    9284echo "Remember to bump OWL_VERSION_STRING for future development."
    9385
  • t/completion.t

    re59d775 ra7250ee  
    66
    77use File::Basename;
    8 BEGIN {require (dirname($0) . "/mock.pl");};
     8use File::Spec;
     9BEGIN {require File::Spec->rel2abs("mock.pl", dirname($0));};
    910
    1011use BarnOwl::Complete::Filter qw(complete_filter_expr);
  • variable.c

    r7dcef03 r03fbf66  
    136136               "load logins from .anyone on startup", "" );
    137137
    138   OWLVAR_BOOL( "logging" /* %OwlVarStub */, 0,
    139                "turn personal logging on or off",
    140                "If this is set to on, personal messages are\n"
    141                "logged in the directory specified\n"
    142                "by the 'logpath' variable.  The filename in that\n"
    143                "directory is derived from the sender of the message.\n" );
    144 
    145   OWLVAR_BOOL( "classlogging" /* %OwlVarStub */, 0,
    146                "turn class logging on or off",
    147                "If this is set to on, class messages are\n"
    148                "logged in the directory specified\n"
    149                "by the 'classlogpath' variable.\n"
    150                "The filename in that directory is derived from\n"
    151                "the name of the class to which the message was sent.\n" );
    152 
    153   OWLVAR_ENUM( "loggingdirection" /* %OwlVarStub */, OWL_LOGGING_DIRECTION_BOTH,
    154                "specifies which kind of messages should be logged",
    155                "Can be one of 'both', 'in', or 'out'.  If 'in' is\n"
    156                "selected, only incoming messages are logged, if 'out'\n"
    157                "is selected only outgoing messages are logged.  If 'both'\n"
    158                "is selected both incoming and outgoing messages are\n"
    159                "logged.",
    160                "both,in,out");
    161 
    162138  OWLVAR_BOOL_FULL( "colorztext" /* %OwlVarStub */, 1,
    163139                    "allow @color() in zephyrs to change color",
    164                     NULL, NULL, owl_variable_colorztext_set, NULL);
     140                    "", NULL, owl_variable_colorztext_set, NULL);
    165141
    166142  OWLVAR_BOOL( "fancylines" /* %OwlVarStub */, 1,
    … …  
    185161               "Enable printing of login notifications",
    186162               "When this is enabled, BarnOwl will print login and logout notifications\n"
    187                "for AIM, zephyr, or other protocols.  If disabled BarnOwl will not print\n"
    188                "login or logout notifications.\n");
    189 
    190   OWLVAR_STRING( "logfilter" /* %OwlVarStub */, "",
    191                  "name of a filter controlling which messages to log",
    192 
    193                  "If non empty, any messages matching the given filter will be logged.\n"
    194                  "This is a completely separate mechanism from the other logging\n"
    195                  "variables like logging, classlogging, loglogins, loggingdirection,\n"
    196                  "etc.  If you want this variable to control all logging, make sure\n"
    197                  "all other logging variables are in their default state.\n");
    198 
    199   OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0,
    200                "Enable logging of login notifications",
    201                "When this is enabled, BarnOwl will log login and logout notifications\n"
    202163               "for AIM, zephyr, or other protocols.  If disabled BarnOwl will not print\n"
    203164               "login or logout notifications.\n");
    … …  
    214175                    "off,middle,on",
    215176                    NULL, owl_variable_disable_ctrl_d_set, NULL);
    216 
    217   OWLVAR_PATH( "logpath" /* %OwlVarStub */, "~/zlog/people",
    218                "path for logging personal zephyrs",
    219                "Specifies a directory which must exist.\n"
    220                "Files will be created in the directory for each sender.\n");
    221 
    222   OWLVAR_PATH( "classlogpath" /* %OwlVarStub:classlogpath */, "~/zlog/class",
    223                "path for logging class zephyrs",
    224                "Specifies a directory which must exist.\n"
    225                "Files will be created in the directory for each class.\n");
    226177
    227178  OWLVAR_PATH( "debug_file" /* %OwlVarStub */, OWL_DEBUG_FILE,
    … …  
    814765}
    815766
     767bool owl_variable_takes_on_off(const owl_variable *v) {
     768  return v->takes_on_off;
     769}
     770
    816771int owl_variable_get_type(const owl_variable *v)
    817772{
    … …  
    1038993CALLER_OWN char *owl_variable_bool_get_tostring_default(const owl_variable *v, void *dummy)
    1039994{
    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   }
     995  return g_strdup(owl_variable_get_bool(v) ? "on" : "off");
    1048996}
    1049997
  • zephyr.c

    r7dcef03 rff58239  
    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
    … …  
    13201311{
    13211312  int n = strcspn(in, "./");
    1322   char *realm = strchrnul(in, '@');
     1313  const char *realm = strchr(in, '@');
     1314  if (realm == NULL)
     1315    realm = in + strlen(in);
    13231316
    13241317  if (in + n >= realm ||
  • zwrite.c

    r7dcef03 r1958790  
    270270  rv = owl_zwrite_create_from_line(&z, cmd);
    271271  if (rv != 0) return rv;
    272   if (!owl_zwrite_is_message_set(&z)) {
    273     owl_zwrite_set_message(&z, msg);
    274   }
    275   owl_zwrite_populate_zsig(&z);
    276   owl_zwrite_send_message(&z);
     272  owl_function_zwrite(&z, msg);
    277273  owl_zwrite_cleanup(&z);
    278274  return(0);
Note: See TracChangeset for help on using the changeset viewer.