Changeset ea43085 for functions.c


Ignore:
Timestamp:
Jun 22, 2013, 9:49:47 PM (11 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Parents:
96d80e9 (diff), c474a97 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge c474a97ec58cb7252a91152375228eed5322676f into 96d80e9b4aa667605b9c786b0272e1ab04dfbe9b
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    rc474a97 r60e8617  
     1#include "owl.h"
     2#include "filterproc.h"
    13#include <stdio.h>
    2 #include <stdlib.h>
    3 #include <unistd.h>
    4 #include <signal.h>
    5 #include <netinet/in.h>
    6 #include <string.h>
    7 #include <time.h>
    8 #include <sys/types.h>
    94#include <sys/stat.h>
    105#include <sys/wait.h>
    11 #include <errno.h>
    12 #include <signal.h>
    13 #include "owl.h"
    14 #include "filterproc.h"
    15 
    16 char *owl_function_command(const char *cmdbuff)
     6
     7CALLER_OWN char *owl_function_command(const char *cmdbuff)
    178{
    189  owl_function_debugmsg("executing command: %s", cmdbuff);
     
    2112}
    2213
    23 char *owl_function_command_argv(const char *const *argv, int argc)
     14CALLER_OWN char *owl_function_command_argv(const char *const *argv, int argc)
    2415{
    2516  return owl_cmddict_execute_argv(owl_global_get_cmddict(&g),
     
    4738void owl_function_show_commands(void)
    4839{
    49   owl_list l;
     40  GPtrArray *l;
    5041  owl_fmtext fm;
    5142
     
    5344  owl_fmtext_append_bold(&fm, "Commands:  ");
    5445  owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n");
    55   owl_list_create(&l);
    56   owl_cmddict_get_names(owl_global_get_cmddict(&g), &l);
    57   owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe);
     46  l = owl_cmddict_get_names(owl_global_get_cmddict(&g));
     47  owl_fmtext_append_list(&fm, l, "\n", owl_function_cmd_describe);
    5848  owl_fmtext_append_normal(&fm, "\n");
    5949  owl_function_popless_fmtext(&fm);
    60   owl_list_cleanup(&l, g_free);
     50  owl_ptr_array_free(l, g_free);
    6151  owl_fmtext_cleanup(&fm);
    6252}
     
    8171
    8272void owl_function_show_styles(void) {
    83   owl_list l;
     73  GPtrArray *l;
    8474  owl_fmtext fm;
    8575
    8676  owl_fmtext_init_null(&fm);
    8777  owl_fmtext_append_bold(&fm, "Styles:\n");
    88   owl_list_create(&l);
    89   owl_global_get_style_names(&g, &l);
    90   owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe);
     78  l = owl_global_get_style_names(&g);
     79  owl_fmtext_append_list(&fm, l, "\n", owl_function_style_describe);
    9180  owl_fmtext_append_normal(&fm, "\n");
    9281  owl_function_popless_fmtext(&fm);
    93   owl_list_cleanup(&l, g_free);
     82  owl_ptr_array_free(l, g_free);
    9483  owl_fmtext_cleanup(&fm);
    9584}
    9685
    97 static void _owl_function_timer_append_fmtext(gpointer data, gpointer user_data) {
    98   owl_fmtext *fm = user_data;
    99   owl_timer *timer = data;
    100   char *str = g_strdup_printf("- %s: in %d seconds",
    101                               timer->name ? timer->name : "(unnamed)",
    102                               (int)(timer->time - time(NULL)));
    103   owl_fmtext_append_normal(fm, str);
    104   g_free(str);
    105   if (timer->interval) {
    106     str = g_strdup_printf(", repeat every %d seconds", timer->interval);
    107     owl_fmtext_append_normal(fm, str);
    108     g_free(str);
    109   }
    110   owl_fmtext_append_normal(fm, "\n");
    111 }
    112 
    113 void owl_function_show_timers(void) {
    114   owl_fmtext fm;
    115   GList **timers;
    116 
    117   owl_fmtext_init_null(&fm);
    118   owl_fmtext_append_bold(&fm, "Active timers:\n");
    119 
    120   timers = owl_global_get_timerlist(&g);
    121   g_list_foreach(*timers, _owl_function_timer_append_fmtext, &fm);
    122 
    123   owl_function_popless_fmtext(&fm);
    124   owl_fmtext_cleanup(&fm);
    125 }
    126 
    127 char *owl_function_style_describe(const char *name) {
     86CALLER_OWN char *owl_function_style_describe(const char *name)
     87{
    12888  const char *desc;
    12989  char *s;
     
    141101}
    142102
    143 char *owl_function_cmd_describe(const char *name)
     103CALLER_OWN char *owl_function_cmd_describe(const char *name)
    144104{
    145105  const owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name);
     
    158118
    159119  text=""
    160     "barnowl version " OWL_VERSION_STRING "\n"
     120    "BarnOwl version " OWL_VERSION_STRING "\n"
    161121    "Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n"
    162122    "Copyright (c) 2004 James Kretchmar. All rights reserved.\n"
     
    175135    "\n"
    176136    "   * Redistributions in any form must be accompanied by information on\n"
    177     "     how to obtain complete source code for the Owl software and any\n"
    178     "     accompanying software that uses the Owl software. The source code\n"
     137    "     how to obtain complete source code for the BarnOwl software and any\n"
     138    "     accompanying software that uses the BarnOwl software. The source code\n"
    179139    "     must either be included in the distribution or be available for no\n"
    180140    "     more than the cost of distribution plus a nominal fee, and must be\n"
     
    244204
    245205  /* do followlast if necessary */
    246   if (owl_global_should_followlast(&g)) owl_function_lastmsg_noredisplay();
     206  if (owl_global_should_followlast(&g)) owl_function_lastmsg();
    247207
    248208  /* redisplay etc. */
     
    256216void owl_function_add_outgoing_zephyrs(const owl_zwrite *z)
    257217{
    258   if (z->cc || owl_zwrite_get_numrecips(z) == 0) {
     218  if (z->cc && owl_zwrite_is_personal(z)) {
    259219    /* create the message */
    260220    owl_message *m = g_new(owl_message, 1);
     
    265225    int i;
    266226    for (i = 0; i < owl_zwrite_get_numrecips(z); i++) {
     227      owl_message *m;
     228
     229      if (!owl_zwrite_recip_is_personal(owl_zwrite_get_recip_n(z, i)))
     230        continue;
     231
    267232      /* create the message */
    268       owl_message *m = g_new(owl_message, 1);
     233      m = g_new(owl_message, 1);
    269234      owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i);
    270235
     
    279244 * owl_global_messagequeue_addmsg() for that.
    280245 */
    281 owl_message *owl_function_make_outgoing_aim(const char *body, const char *to)
     246CALLER_OWN owl_message *owl_function_make_outgoing_aim(const char *body, const char *to)
    282247{
    283248  owl_message *m;
     
    300265 * owl_global_messagequeue_addmsg() for that.
    301266 */
    302 owl_message *owl_function_make_outgoing_loopback(const char *body)
     267CALLER_OWN owl_message *owl_function_make_outgoing_loopback(const char *body)
    303268{
    304269  owl_message *m;
     
    312277}
    313278
    314 void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *))
     279owl_editwin *owl_function_start_edit_win(const char *line)
    315280{
    316281  owl_editwin *e;
     
    326291  g_free(s);
    327292
    328   owl_editwin_set_cbdata(e, data, cleanup);
    329   owl_editwin_set_callback(e, callback);
    330293  ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti",
    331294                            owl_global_deactivate_editcontext, &g);
    332295  owl_global_push_context_obj(&g, ctx);
    333 
     296  return e;
    334297}
    335298
     
    349312void owl_function_zwrite_setup(owl_zwrite *z)
    350313{
     314  owl_editwin *e;
    351315  /* send a ping if necessary */
    352316  if (owl_global_is_txping(&g)) {
     
    356320
    357321  owl_function_write_setup("zephyr");
    358   owl_function_start_edit_win(z->zwriteline,
    359                               &owl_callback_zwrite,
    360                               z, (void(*)(void*))owl_zwrite_delete);
     322  e = owl_function_start_edit_win(z->zwriteline);
     323  owl_editwin_set_cbdata(e, z, (void (*)(void *))owl_zwrite_delete);
     324  owl_editwin_set_callback(e, &owl_callback_zwrite);
    361325}
    362326
    363327void owl_function_aimwrite_setup(const char *to)
    364328{
     329  owl_editwin *e;
    365330  /* TODO: We probably actually want an owl_aimwrite object like
    366331   * owl_zwrite. */
    367332  char *line = g_strdup_printf("aimwrite %s", to);
    368333  owl_function_write_setup("message");
    369   owl_function_start_edit_win(line,
    370                               &owl_callback_aimwrite,
    371                               g_strdup(to),
    372                               g_free);
     334  e = owl_function_start_edit_win(line);
     335  owl_editwin_set_cbdata(e, g_strdup(to), g_free);
     336  owl_editwin_set_callback(e, &owl_callback_aimwrite);
    373337  g_free(line);
    374338}
     
    376340void owl_function_loopwrite_setup(void)
    377341{
     342  owl_editwin *e;
    378343  owl_function_write_setup("message");
    379   owl_function_start_edit_win("loopwrite",
    380                               &owl_callback_loopwrite,
    381                               NULL, NULL);
    382 }
    383 
    384 void owl_callback_zwrite(owl_editwin *e) {
     344  e = owl_function_start_edit_win("loopwrite");
     345  owl_editwin_set_callback(e, &owl_callback_loopwrite);
     346}
     347
     348void owl_callback_zwrite(owl_editwin *e, bool success)
     349{
     350  if (!success) return;
    385351  owl_zwrite *z = owl_editwin_get_cbdata(e);
    386352  owl_function_zwrite(z, owl_editwin_get_text(e));
     
    412378  owl_function_makemsg("Waiting for ack...");
    413379
    414   /* If it's personal */
    415   if (owl_zwrite_is_personal(z)) {
    416     /* create the outgoing message */
    417     owl_function_add_outgoing_zephyrs(z);
    418   }
     380  /* create the outgoing message */
     381  owl_function_add_outgoing_zephyrs(z);
    419382}
    420383#else
     
    441404  old_msg = g_strdup(owl_zwrite_get_message(z));
    442405
    443   zcrypt = g_strdup_printf("%s/zcrypt", owl_get_bindir());
    444   argv[0] = "zcrypt";
     406  zcrypt = g_build_filename(owl_get_bindir(), "zcrypt", NULL);
     407  argv[0] = zcrypt;
    445408  argv[1] = "-E";
    446409  argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z);
     
    448411  argv[6] = NULL;
    449412
    450   rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status);
     413  rv = call_filter(argv, owl_zwrite_get_message(z), &cryptmsg, &status);
    451414
    452415  g_free(zcrypt);
     
    466429  owl_function_makemsg("Waiting for ack...");
    467430
    468   /* If it's personal */
    469   if (owl_zwrite_is_personal(z)) {
    470     /* Create the outgoing message. Restore the un-crypted message for display. */
    471     owl_zwrite_set_message_raw(z, old_msg);
    472     owl_function_add_outgoing_zephyrs(z);
    473   }
    474 
    475   /* free the zwrite */
     431  /* Create the outgoing message. Restore the un-crypted message for display. */
     432  owl_zwrite_set_message_raw(z, old_msg);
     433  owl_function_add_outgoing_zephyrs(z);
     434
     435  /* Clean up. */
    476436  g_free(cryptmsg);
    477 }
    478 
    479 void owl_callback_aimwrite(owl_editwin *e) {
     437  g_free(old_msg);
     438}
     439
     440void owl_callback_aimwrite(owl_editwin *e, bool success)
     441{
     442  if (!success) return;
    480443  char *to = owl_editwin_get_cbdata(e);
    481444  owl_function_aimwrite(to, owl_editwin_get_text(e), true);
     
    541504}
    542505
    543 void owl_callback_loopwrite(owl_editwin *e) {
     506void owl_callback_loopwrite(owl_editwin *e, bool success)
     507{
     508  if (!success) return;
    544509  owl_function_loopwrite(owl_editwin_get_text(e));
    545510}
     
    691656{
    692657  owl_function_prevmsg_full(NULL, 1, 1);
     658}
     659
     660void owl_function_delete_and_expunge_message(int n)
     661{
     662  owl_messagelist *ml = owl_global_get_msglist(&g);
     663  owl_view *v = owl_global_get_current_view(&g);
     664  int lastmsgid = owl_function_get_curmsg_id(v);
     665
     666  /* delete and expunge the message */
     667  owl_messagelist_delete_and_expunge_element(ml, n);
     668
     669  owl_function_redisplay_to_nearest(lastmsgid, v);
     670}
     671
     672void owl_function_delete_and_expunge_cur(bool exclaim_success)
     673{
     674  int curmsg;
     675  const owl_view *v = owl_global_get_current_view(&g);
     676
     677  /* bail if there's no current message */
     678  if (owl_view_get_size(v) < 1) {
     679    owl_function_error("No current message to delete");
     680    return;
     681  }
     682
     683  /* delete the current message */
     684  curmsg = owl_global_get_curmsg(&g);
     685  owl_function_delete_and_expunge_message(curmsg);
     686  if (exclaim_success)
     687    owl_function_makemsg("Message deleted and expunged");
    693688}
    694689
     
    752747}
    753748
     749/* returns the current message id, if it exists.  Otherwise returns
     750 * -1 if we are past the end of the message list, and 0 otherwise. */
     751int owl_function_get_curmsg_id(const owl_view *v)
     752{
     753  int curmsg = owl_global_get_curmsg(&g);
     754  const owl_message *m = owl_view_get_element(v, curmsg);
     755  if (m)
     756    return owl_message_get_id(m);
     757  if (curmsg > 0) /* past the end of the message list (probably) */
     758    return -1;
     759  return 0;
     760}
     761
     762/* redisplays the view to the nearest message to the id given.
     763 * if msgid < 0, redisplay to past the end of the message list */
     764void owl_function_redisplay_to_nearest(int msgid, owl_view *v)
     765{
     766  int curmsg;
     767  /* update all views (we only have one right now) */
     768  owl_view_recalculate(v);
     769
     770  /* find where the new position should be */
     771  if (msgid < 0) {
     772    /* If already at the end, blank the screen and move curmsg
     773     * past the end of the messages. */
     774    curmsg = owl_view_get_size(v);
     775    owl_global_set_topmsg(&g, curmsg);
     776    owl_global_set_curmsg(&g, curmsg);
     777  } else {
     778    curmsg = owl_view_get_nearest_to_msgid(v, msgid);
     779    if (curmsg > owl_view_get_size(v) - 1)
     780      curmsg = owl_view_get_size(v) - 1;
     781    if (curmsg < 0)
     782      curmsg = 0;
     783    owl_global_set_curmsg(&g, curmsg);
     784    owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
     785  }
     786  /* if there are no messages set the direction to down in case we
     787   * delete everything upwards */
     788  owl_global_set_direction_downwards(&g);
     789
     790  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     791}
     792
    754793void owl_function_expunge(void)
    755794{
    756   int curmsg;
    757   const owl_message *m;
    758   owl_messagelist *ml;
    759   owl_view *v;
    760   int lastmsgid=0;
    761 
    762   curmsg=owl_global_get_curmsg(&g);
    763   v=owl_global_get_current_view(&g);
    764   ml=owl_global_get_msglist(&g);
    765 
    766   m=owl_view_get_element(v, curmsg);
    767   if (m) lastmsgid = owl_message_get_id(m);
     795  owl_messagelist *ml = owl_global_get_msglist(&g);
     796  owl_view *v = owl_global_get_current_view(&g);
     797  int lastmsgid = owl_function_get_curmsg_id(v);
    768798
    769799  /* expunge the message list */
    770800  owl_messagelist_expunge(ml);
    771801
    772   /* update all views (we only have one right now) */
    773   owl_view_recalculate(v);
    774 
    775   /* find where the new position should be
    776      (as close as possible to where we last where) */
    777   curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid);
    778   if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1;
    779   if (curmsg<0) curmsg = 0;
    780   owl_global_set_curmsg(&g, curmsg);
    781   owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
    782   /* if there are no messages set the direction to down in case we
    783      delete everything upwards */
    784   owl_global_set_direction_downwards(&g);
     802  owl_function_redisplay_to_nearest(lastmsgid, v);
    785803 
    786804  owl_function_makemsg("Messages expunged");
    787   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    788805}
    789806
     
    796813}
    797814
    798 void owl_function_lastmsg_noredisplay(void)
     815void owl_function_lastmsg(void)
    799816{
    800817  int oldcurmsg, curmsg;
     
    814831    owl_global_set_curmsg(&g, curmsg+1);
    815832  }
    816   /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */
     833  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    817834  owl_global_set_direction_downwards(&g);
    818 }
    819 
    820 void owl_function_lastmsg(void)
    821 {
    822   owl_function_lastmsg_noredisplay();
    823   owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
    824835}
    825836
     
    844855void owl_function_unsuball(void)
    845856{
    846   unsuball();
    847   owl_function_makemsg("Unsubscribed from all messages.");
     857  if (unsuball())
     858    owl_function_makemsg("Unsubscribed from all messages.");
    848859}
    849860
     
    860871void owl_function_loadsubs(const char *file)
    861872{
    862   int ret, ret2;
    863   const char *foo;
     873  int ret, ret2, ret3;
    864874  char *path;
    865875
     
    873883
    874884  /* for backwards compatibility for now */
    875   ret2=owl_zephyr_loaddefaultsubs();
     885  ret2 = owl_zephyr_loaddefaultsubs();
     886  ret3 = owl_zephyr_loadbarnowldefaultsubs();
    876887
    877888  if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
    878889
    879   foo=file?file:"file";
    880   if (ret==0 && ret2==0) {
     890  if (ret == 0 && ret2 == 0 && ret3 == 0) {
    881891    if (!file) {
    882892      owl_function_makemsg("Subscribed to messages.");
     
    884894      owl_function_makemsg("Subscribed to messages from %s", file);
    885895    }
    886   } else if (ret==-1) {
    887     owl_function_error("Could not read %s", foo);
    888   } else {
     896  } else if (ret == -1) {
     897    owl_function_error("Could not read %s", file ? file : "file");
     898  } else if (ret2 == -1) {
    889899    owl_function_error("Error subscribing to messages");
     900  } else {
     901    owl_function_error("Error subscribing to instanced personals");
    890902  }
    891903}
     
    906918}
    907919
    908 void owl_callback_aimlogin(owl_editwin *e) {
     920void owl_callback_aimlogin(owl_editwin *e, bool success)
     921{
     922  if (!success) return;
    909923  char *user = owl_editwin_get_cbdata(e);
    910924  owl_function_aimlogin(user,
     
    10031017  }
    10041018
    1005   owl_function_debugmsg("Quitting Owl");
     1019  owl_function_debugmsg("Quitting BarnOwl");
    10061020  owl_select_quit_loop();
    10071021}
     
    12021216void G_GNUC_PRINTF(1, 2) owl_function_debugmsg(const char *fmt, ...)
    12031217{
     1218  char *tmpbuff;
    12041219  FILE *file;
    12051220  time_t now;
     
    12161231  now = time(NULL);
    12171232
    1218   fprintf(file, "[%d -  %.24s - %lds]: ",
    1219           (int) getpid(), ctime(&now), now - owl_global_get_starttime(&g));
     1233  tmpbuff = owl_util_format_time(localtime(&now));
     1234  fprintf(file, "[%d -  %s - %lds]: ",
     1235          (int) getpid(), tmpbuff, now - owl_global_get_starttime(&g));
     1236  g_free(tmpbuff);
    12201237  vfprintf(file, fmt, ap);
    12211238  putc('\n', file);
     
    13361353{
    13371354  owl_function_popless_text(
    1338     "This is barnowl version " OWL_VERSION_STRING ".\n\n"
    1339     "barnowl is a fork of the Owl zephyr client, written and\n"
     1355    "This is BarnOwl version " OWL_VERSION_STRING ".\n\n"
     1356    "BarnOwl is a fork of the Owl zephyr client, written and\n"
    13401357    "maintained by Alejandro Sedeno and Nelson Elhage at the\n"
    13411358    "Massachusetts Institute of Technology. \n"
     
    13461363    "The name 'owl' was chosen in reference to the owls in the\n"
    13471364    "Harry Potter novels, who are tasked with carrying messages\n"
    1348     "between Witches and Wizards. The name 'barnowl' was chosen\n"
     1365    "between Witches and Wizards. The name 'BarnOwl' was chosen\n"
    13491366    "because we feel our owls should live closer to our ponies.\n"
    13501367    "\n"
     
    13641381  owl_fmtext fm, attrfm;
    13651382  const owl_view *v;
     1383  char *time;
    13661384#ifdef HAVE_LIBZEPHYR
    13671385  const ZNotice_t *n;
     
    13941412  }
    13951413
    1396   owl_fmtext_appendf_normal(&fm, "  Time      : %s\n", owl_message_get_timestr(m));
     1414  time = owl_message_format_time(m);
     1415  owl_fmtext_appendf_normal(&fm, "  Time      : %s\n", time);
     1416  g_free(time);
    13971417
    13981418  if (!owl_message_is_type_admin(m)) {
     
    14081428    owl_fmtext_appendf_normal(&fm, "  Opcode    : %s\n", owl_message_get_opcode(m));
    14091429#ifdef HAVE_LIBZEPHYR
    1410     if (owl_message_is_direction_in(m)) {
    1411       char *tmpbuff;
     1430    n = owl_message_get_notice(m);
     1431    if (n != NULL) {
     1432      char *tmpbuff, *tmpbuff2;
    14121433      int i, fields;
    1413 
    1414       n=owl_message_get_notice(m);
     1434      const char *f;
    14151435
    14161436      if (!owl_message_is_pseudo(m)) {
     
    14541474        owl_fmtext_appendf_normal(&fm, "  Fields    : %i\n", fields);
    14551475
    1456         for (i = 0; i < fields; i++) {
    1457           tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1);
    1458 
    1459           g_strdelimit(tmpbuff, "\n", '~');
    1460           g_strdelimit(tmpbuff, "\r", '!');
    1461 
    1462           owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i + 1, tmpbuff);
    1463           g_free(tmpbuff);
     1476        for (i = 0, f = owl_zephyr_first_raw_field(n); f != NULL;
     1477             i++, f = owl_zephyr_next_raw_field(n, f)) {
     1478          tmpbuff = owl_zephyr_field_as_utf8(n, f);
     1479          tmpbuff2 = owl_text_indent(tmpbuff, 14, false);
     1480          owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i + 1, tmpbuff2);
     1481          g_free(tmpbuff2);
     1482          g_free(tmpbuff);
    14641483        }
    1465         owl_fmtext_appendf_normal(&fm, "  Default Fm: %s\n", n->z_default_format);
     1484        tmpbuff = owl_text_indent(n->z_default_format, 14, false);
     1485        owl_fmtext_appendf_normal(&fm, "  Default Fm: %s\n", tmpbuff);
     1486        g_free(tmpbuff);
    14661487      }
    14671488
     
    14701491  }
    14711492
    1472   owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n");
     1493  owl_fmtext_append_bold(&fm, "\nBarnOwl Message Attributes:\n");
    14731494  owl_message_attributes_tofmtext(m, &attrfm);
    14741495  owl_fmtext_append_fmtext(&fm, &attrfm);
     
    16031624void owl_function_printallvars(void)
    16041625{
     1626  const owl_variable *v;
    16051627  const char *name;
    16061628  char *var;
    1607   owl_list varnames;
    1608   int i, numvarnames;
     1629  GPtrArray *varnames;
     1630  int i;
    16091631  GString *str   = g_string_new("");
    16101632
    16111633  g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE");
    16121634  g_string_append_printf(str, "%-20s   %s\n",  "--------", "-----");
    1613   owl_list_create(&varnames);
    1614   owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
    1615   numvarnames = owl_list_get_size(&varnames);
    1616   for (i=0; i<numvarnames; i++) {
    1617     name = owl_list_get_element(&varnames, i);
     1635  varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g));
     1636  for (i = 0; i < varnames->len; i++) {
     1637    name = varnames->pdata[i];
    16181638    if (name && name[0]!='_') {
    16191639      g_string_append_printf(str, "\n%-20s = ", name);
    1620       var = owl_variable_get_tostring(owl_global_get_vardict(&g), name);
     1640      v = owl_variable_get_var(owl_global_get_vardict(&g), name);
     1641      var = owl_variable_get_tostring(v);
    16211642      if (var) {
    1622         g_string_append(str, var);
    1623         g_free(var);
     1643        g_string_append(str, var);
     1644        g_free(var);
     1645      } else {
     1646        g_string_append(str, "<null>");
    16241647      }
    16251648    }
    16261649  }
    16271650  g_string_append(str, "\n");
    1628   owl_list_cleanup(&varnames, g_free);
     1651  owl_ptr_array_free(varnames, g_free);
    16291652
    16301653  owl_function_popless_text(str->str);
     
    16341657void owl_function_show_variables(void)
    16351658{
    1636   owl_list varnames;
     1659  const owl_variable *v;
     1660  GPtrArray *varnames;
    16371661  owl_fmtext fm; 
    1638   int i, numvarnames;
     1662  int i;
    16391663  const char *varname;
    16401664
     
    16421666  owl_fmtext_append_bold(&fm,
    16431667      "Variables: (use 'show variable <name>' for details)\n");
    1644   owl_list_create(&varnames);
    1645   owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
    1646   numvarnames = owl_list_get_size(&varnames);
    1647   for (i=0; i<numvarnames; i++) {
    1648     varname = owl_list_get_element(&varnames, i);
     1668  varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g));
     1669  for (i = 0; i < varnames->len; i++) {
     1670    varname = varnames->pdata[i];
    16491671    if (varname && varname[0]!='_') {
    1650       owl_variable_describe(owl_global_get_vardict(&g), varname, &fm);
    1651     }
    1652   }
    1653   owl_list_cleanup(&varnames, g_free);
     1672      v = owl_variable_get_var(owl_global_get_vardict(&g), varname);
     1673      owl_variable_describe(v, &fm);
     1674    }
     1675  }
     1676  owl_ptr_array_free(varnames, g_free);
    16541677  owl_function_popless_fmtext(&fm);
    16551678  owl_fmtext_cleanup(&fm);
     
    16581681void owl_function_show_variable(const char *name)
    16591682{
     1683  const owl_variable *v;
    16601684  owl_fmtext fm; 
    16611685
    16621686  owl_fmtext_init_null(&fm);
    1663   owl_variable_get_help(owl_global_get_vardict(&g), name, &fm);
     1687  v = owl_variable_get_var(owl_global_get_vardict(&g), name);
     1688  if (v)
     1689    owl_variable_get_help(v, &fm);
     1690  else
     1691    owl_fmtext_append_normal(&fm, "No such variable...\n");
    16641692  owl_function_popless_fmtext(&fm);
    16651693  owl_fmtext_cleanup(&fm);
     1694}
     1695
     1696void owl_function_delete_and_expunge_by_id(int id, bool exclaim_success)
     1697{
     1698  const owl_messagelist *ml = owl_global_get_msglist(&g);
     1699  int msg = owl_messagelist_get_index_by_id(ml, id);
     1700  if (msg < 0) {
     1701    owl_function_error("No message with id %d: unable to delete", id);
     1702  } else {
     1703    owl_function_delete_and_expunge_message(msg);
     1704    if (exclaim_success)
     1705      owl_function_makemsg("Message deleted and expunged");
     1706  }
    16661707}
    16671708
     
    17201761void owl_function_status(void)
    17211762{
     1763  char *tmpbuff;
    17221764  char buff[MAXPATHLEN+1];
    17231765  time_t start;
     
    17471789  owl_fmtext_append_normal(&fm, "\n");
    17481790
    1749   owl_fmtext_appendf_normal(&fm, "  Startup Time: %s", ctime(&start));
     1791  tmpbuff = owl_util_format_time(localtime(&start));
     1792  owl_fmtext_appendf_normal(&fm, "  Startup Time: %s\n", tmpbuff);
     1793  g_free(tmpbuff);
    17501794
    17511795  up=owl_global_get_runtime(&g);
     
    18701914    if (enter) {
    18711915      owl_history *hist = owl_global_get_cmd_history(&g);
    1872       owl_history_store(hist, buff);
    1873       owl_history_reset(hist);
     1916      owl_history_store(hist, buff, false);
    18741917      owl_function_command_norv(buff);
    18751918    } else {
     
    19011944}
    19021945
    1903 void owl_callback_command(owl_editwin *e)
    1904 {
     1946void owl_callback_command(owl_editwin *e, bool success)
     1947{
     1948  if (!success) return;
    19051949  char *rv;
    19061950  const char *line = owl_editwin_get_text(e);
     
    19131957}
    19141958
    1915 void owl_function_start_command(const char *line)
     1959owl_editwin *owl_function_start_command(const char *line)
    19161960{
    19171961  owl_editwin *tw;
     
    19281972  owl_global_push_context_obj(&g, ctx);
    19291973  owl_editwin_set_callback(tw, owl_callback_command);
     1974  return tw;
    19301975}
    19311976
     
    19622007}
    19632008
    1964 char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type)
     2009CALLER_OWN char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type)
    19652010{
    19662011  /* if type == 1 display in a popup
     
    20052050}
    20062051
    2007 char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type)
     2052CALLER_OWN char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type)
    20082053{
    20092054  /* if type == 1 display in a popup
     
    20862131
    20872132/* Create a new filter, or replace an existing one
    2088  * with a new definition.
     2133 * with a new definition. Returns true on success.
    20892134 */
    2090 void owl_function_create_filter(int argc, const char *const *argv)
     2135bool owl_function_create_filter(int argc, const char *const *argv)
    20912136{
    20922137  owl_filter *f;
     
    20962141  if (argc < 2) {
    20972142    owl_function_error("Wrong number of arguments to filter command");
    2098     return;
     2143    return false;
    20992144  }
    21002145
     
    21062151  if (!strcmp(argv[1], "all")) {
    21072152    owl_function_error("You may not change the 'all' filter.");
    2108     return;
     2153    return false;
    21092154  }
    21102155
     
    21142159    if (!f) {
    21152160      owl_function_error("The filter '%s' does not exist.", argv[1]);
    2116       return;
     2161      return false;
    21172162    }
    21182163    if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) {
    21192164      owl_function_error("The color '%s' is not available.", argv[3]);
    2120       return;
     2165      return false;
    21212166    }
    21222167    owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3]));
    21232168    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    2124     return;
     2169    return false;
    21252170  }
    21262171  if (argc==4 && !strcmp(argv[2], "-b")) {
     
    21282173    if (!f) {
    21292174      owl_function_error("The filter '%s' does not exist.", argv[1]);
    2130       return;
     2175      return false;
    21312176    }
    21322177    if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) {
    21332178      owl_function_error("The color '%s' is not available.", argv[3]);
    2134       return;
     2179      return false;
    21352180    }
    21362181    owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3]));
    21372182    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    2138     return;
     2183    return true;
    21392184  }
    21402185
     
    21422187  f = owl_filter_new(argv[1], argc-2, argv+2);
    21432188  if (f == NULL) {
    2144     owl_function_error("Invalid filter");
    2145     return;
     2189    owl_function_error("Invalid filter: %s", argv[1]);
     2190    return false;
    21462191  }
    21472192
     
    21642209  }
    21652210  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
     2211  return true;
    21662212}
    21672213
     
    21752221 * Returns the name of the negated filter, which the caller must free.
    21762222 */
    2177 char *owl_function_create_negative_filter(const char *filtername)
     2223CALLER_OWN char *owl_function_create_negative_filter(const char *filtername)
    21782224{
    21792225  char *newname;
     
    22452291{
    22462292  const owl_filter *f;
    2247   const owl_list *fl;
     2293  const GPtrArray *fl;
    22482294  char *tmp;
    22492295  owl_fmtext fm;
    2250   int i, j;
     2296  int i;
    22512297
    22522298  owl_fmtext_init_null(&fm);
    22532299
    22542300  fl=owl_global_get_puntlist(&g);
    2255   j=owl_list_get_size(fl);
    22562301  owl_fmtext_append_bold(&fm, "Active zpunt filters:\n");
    22572302
    2258   for (i=0; i<j; i++) {
    2259     f=owl_list_get_element(fl, i);
     2303  for (i = 0; i < fl->len; i++) {
     2304    f = fl->pdata[i];
    22602305    owl_fmtext_appendf_normal(&fm, "[% 2d] ", i+1);
    22612306    tmp = owl_filter_print(f);
     
    22722317 * If 'related' is nonzero, encompass unclasses and .d classes as well.
    22732318 */
    2274 char *owl_function_classinstfilt(const char *c, const char *i, int related)
     2319CALLER_OWN char *owl_function_classinstfilt(const char *c, const char *i, int related)
    22752320{
    22762321  owl_filter *f;
     
    23592404 * the filter, which the caller must free.
    23602405 */
    2361 char *owl_function_zuserfilt(const char *longuser)
     2406CALLER_OWN char *owl_function_zuserfilt(const char *longuser)
    23622407{
    23632408  owl_filter *f;
     
    24052450 * Returns the name of the filter, which the caller must free.
    24062451 */
    2407 char *owl_function_aimuserfilt(const char *user)
     2452CALLER_OWN char *owl_function_aimuserfilt(const char *user)
    24082453{
    24092454  owl_filter *f;
     
    24162461  /* if it already exists then go with it.  This lets users override */
    24172462  if (owl_global_get_filter(&g, filtname)) {
    2418     return(g_strdup(filtname));
     2463    return filtname;
    24192464  }
    24202465
     
    24432488}
    24442489
    2445 char *owl_function_typefilt(const char *type)
     2490CALLER_OWN char *owl_function_typefilt(const char *type)
    24462491{
    24472492  owl_filter *f;
     
    24992544}
    25002545
    2501 static char *owl_function_smartfilter_cc(const owl_message *m) {
     2546static CALLER_OWN char *owl_function_smartfilter_cc(const owl_message *m)
     2547{
    25022548  const char *ccs;
    25032549  char *ccs_quoted;
     
    25502596 *    name to the AIM conversation with that user
    25512597 */
    2552 char *owl_function_smartfilter(int type, int invert_related)
     2598CALLER_OWN char *owl_function_smartfilter(int type, int invert_related)
    25532599{
    25542600  const owl_view *v;
     
    28092855
    28102856  owl_function_punt(argv->len, (const char *const*) argv->pdata, direction);
    2811   g_ptr_array_foreach(argv, (GFunc)g_free, NULL);
    2812   g_ptr_array_free(argv, true);
     2857  owl_ptr_array_free(argv, g_free);
    28132858}
    28142859
     
    28162861{
    28172862  owl_filter *f;
    2818   owl_list *fl;
    2819   int i, j;
     2863  GPtrArray *fl;
     2864  int i;
    28202865  fl=owl_global_get_puntlist(&g);
    28212866
     
    28282873
    28292874  /* Check for an identical filter */
    2830   j=owl_list_get_size(fl);
    2831   for (i=0; i<j; i++) {
    2832     if (owl_filter_equiv(f, owl_list_get_element(fl, i))) {
     2875  for (i = 0; i < fl->len; i++) {
     2876    if (owl_filter_equiv(f, fl->pdata[i])) {
    28332877      owl_function_debugmsg("found an equivalent punt filter");
    28342878      /* if we're punting, then just silently bow out on this duplicate */
     
    28402884      /* if we're unpunting, then remove this filter from the puntlist */
    28412885      if (direction==1) {
    2842         owl_filter_delete(owl_list_get_element(fl, i));
    2843         owl_list_remove_element(fl, i);
     2886        owl_filter_delete(g_ptr_array_remove_index(fl, i));
    28442887        owl_filter_delete(f);
    28452888        return;
     
    28512894    owl_function_debugmsg("punting");
    28522895    /* If we're punting, add the filter to the global punt list */
    2853     owl_list_append_element(fl, f);
     2896    g_ptr_array_add(fl, f);
    28542897  } else if (direction == 1) {
    28552898    owl_function_makemsg("No matching punt filter");
     
    28592902void owl_function_show_keymaps(void)
    28602903{
    2861   owl_list l;
     2904  GPtrArray *l;
    28622905  owl_fmtext fm;
    28632906  const owl_keymap *km;
    28642907  const owl_keyhandler *kh;
    2865   int i, numkm;
     2908  int i;
    28662909  const char *kmname;
    28672910
     
    28702913  owl_fmtext_append_bold(&fm, "Keymaps:   ");
    28712914  owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n");
    2872   owl_list_create(&l);
    2873   owl_keyhandler_get_keymap_names(kh, &l);
    2874   owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary);
     2915  l = owl_keyhandler_get_keymap_names(kh);
     2916  owl_fmtext_append_list(&fm, l, "\n", owl_function_keymap_summary);
    28752917  owl_fmtext_append_normal(&fm, "\n");
    28762918
    2877   numkm = owl_list_get_size(&l);
    2878   for (i=0; i<numkm; i++) {
    2879     kmname = owl_list_get_element(&l, i);
     2919  for (i = 0; i < l->len; i++) {
     2920    kmname = l->pdata[i];
    28802921    km = owl_keyhandler_get_keymap(kh, kmname);
    28812922    owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n");
     
    28852926 
    28862927  owl_function_popless_fmtext(&fm);
    2887   owl_list_cleanup(&l, g_free);
     2928  owl_ptr_array_free(l, g_free);
    28882929  owl_fmtext_cleanup(&fm);
    28892930}
    28902931
    2891 char *owl_function_keymap_summary(const char *name)
     2932CALLER_OWN char *owl_function_keymap_summary(const char *name)
    28922933{
    28932934  const owl_keymap *km
     
    30033044/* strips formatting from ztext and returns the unformatted text.
    30043045 * caller is responsible for freeing. */
    3005 char *owl_function_ztext_stylestrip(const char *zt)
     3046CALLER_OWN char *owl_function_ztext_stylestrip(const char *zt)
    30063047{
    30073048  owl_fmtext fm;
     
    30263067#ifdef HAVE_LIBZEPHYR
    30273068  int x;
    3028   owl_list anyone;
     3069  GPtrArray *anyone;
    30293070  const char *user;
    30303071  char *tmp;
     
    30463087      idle=owl_buddy_get_idle_time(b);
    30473088      if (idle!=0) {
    3048         timestr=owl_util_minutes_to_timestr(idle);
     3089        timestr=owl_util_format_minutes(idle);
    30493090      } else {
    30503091        timestr=g_strdup("");
     
    30613102    } else {
    30623103      owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n");
    3063       owl_list_create(&anyone);
    3064       ret=owl_zephyr_get_anyone_list(&anyone, filename);
    3065       if (ret) {
     3104      anyone = owl_zephyr_get_anyone_list(filename);
     3105      if (anyone == NULL) {
    30663106        if (errno == ENOENT) {
    30673107          owl_fmtext_append_normal(&fm, " You have not added any zephyr buddies.  Use the\n");
     
    30733113        }
    30743114      } else {
    3075         j=owl_list_get_size(&anyone);
    3076         for (i=0; i<j; i++) {
    3077           user=owl_list_get_element(&anyone, i);
     3115        for (i = 0; i < anyone->len; i++) {
     3116          user = anyone->pdata[i];
    30783117          ret=ZLocateUser(zstr(user), &numlocs, ZAUTH);
    30793118
     
    31073146        }
    31083147      }
    3109       owl_list_cleanup(&anyone, g_free);
     3148      owl_ptr_array_free(anyone, g_free);
    31103149    }
    31113150  }
     
    31843223    }
    31853224   
    3186     /* if it exited, fork & exec a new one */
     3225    /* if it exited, spawn a new one */
    31873226    if (owl_global_get_newmsgproc_pid(&g)==0) {
    3188       pid_t i;
    31893227      int myargc;
    3190       i=fork();
    3191       if (i) {
    3192         /* parent set the child's pid */
    3193         owl_global_set_newmsgproc_pid(&g, i);
    3194         owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i);
    3195       } else {
    3196         /* child exec's the program */
    3197         char **parsed;
    3198         parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
    3199         if (myargc < 0) {
    3200           owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g));
    3201         }
    3202         if (myargc <= 0) {
    3203           _exit(127);
    3204         }
    3205         owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc);
    3206        
    3207         execvp(parsed[0], parsed);
    3208        
    3209        
    3210         /* was there an error exec'ing? */
    3211         owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s",
    3212                               owl_global_get_newmsgproc(&g), parsed[0], strerror(errno));
    3213         _exit(127);
     3228      char **argv = owl_parseline(owl_global_get_newmsgproc(&g), &myargc);
     3229      if (myargc < 0) {
     3230        owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?",
     3231                              owl_global_get_newmsgproc(&g));
     3232      } else if (myargc > 0) {
     3233        /* Spawn the child. */
     3234        GPid pid;
     3235        GError *error = NULL;
     3236        owl_function_debugmsg("About to exec \"%s\" with %d arguments", argv[0], myargc);
     3237        if (g_spawn_async(NULL, argv, NULL,
     3238                          G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
     3239                          NULL, NULL, &pid, &error)) {
     3240          owl_global_set_newmsgproc_pid(&g, pid);
     3241          owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", pid);
     3242        } else {
     3243          owl_function_debugmsg("Cannot run newmsgproc '%s': %s",
     3244                                owl_global_get_newmsgproc(&g), error->message);
     3245          g_error_free(error);
     3246        }
    32143247      }
     3248      g_strfreev(argv);
    32153249    }
    32163250  }
     
    33813415  char *buff;
    33823416
    3383   now=time(NULL);
    3384   date=g_strdup(ctime(&now));
    3385   date[strlen(date)-1]='\0';
     3417  now = time(NULL);
     3418  date = owl_util_format_time(localtime(&now));
    33863419
    33873420  buff = g_strdup_printf("%s %s", date, string);
     
    34243457{
    34253458#ifdef HAVE_LIBZEPHYR
    3426   int i, j;
    3427   owl_list anyone;
     3459  int i;
     3460  GPtrArray *anyone;
    34283461  GList **zaldlist;
    34293462  GList *zaldptr;
     
    34453478  *zaldlist = NULL;
    34463479
    3447   owl_list_create(&anyone);
    3448   owl_zephyr_get_anyone_list(&anyone, NULL);
    3449   j = owl_list_get_size(&anyone);
    3450   for (i = 0; i < j; i++) {
    3451     user = owl_list_get_element(&anyone, i);
    3452     zald = g_new(ZAsyncLocateData_t, 1);
    3453     if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) {
    3454       *zaldlist = g_list_append(*zaldlist, zald);
    3455     } else {
    3456       g_free(zald);
    3457     }
    3458   }
    3459 
    3460   owl_list_cleanup(&anyone, g_free);
     3480  anyone = owl_zephyr_get_anyone_list(NULL);
     3481  if (anyone != NULL) {
     3482    for (i = 0; i < anyone->len; i++) {
     3483      user = anyone->pdata[i];
     3484      zald = g_new(ZAsyncLocateData_t, 1);
     3485      if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) {
     3486        *zaldlist = g_list_append(*zaldlist, zald);
     3487      } else {
     3488        g_free(zald);
     3489      }
     3490    }
     3491    owl_ptr_array_free(anyone, g_free);
     3492  }
    34613493#endif
    34623494}
    34633495
    3464 void owl_function_aimsearch_results(const char *email, owl_list *namelist)
     3496void owl_function_aimsearch_results(const char *email, GPtrArray *namelist)
    34653497{
    34663498  owl_fmtext fm;
    3467   int i, j;
     3499  int i;
    34683500
    34693501  owl_fmtext_init_null(&fm);
     
    34723504  owl_fmtext_append_normal(&fm, ":\n");
    34733505
    3474   j=owl_list_get_size(namelist);
    3475   for (i=0; i<j; i++) {
     3506  for (i = 0; i < namelist->len; i++) {
    34763507    owl_fmtext_append_normal(&fm, "  ");
    3477     owl_fmtext_append_normal(&fm, owl_list_get_element(namelist, i));
     3508    owl_fmtext_append_normal(&fm, namelist->pdata[i]);
    34783509    owl_fmtext_append_normal(&fm, "\n");
    34793510  }
Note: See TracChangeset for help on using the changeset viewer.