Changeset 2e42098 for functions.c


Ignore:
Timestamp:
Feb 5, 2014, 3:04:26 AM (10 years ago)
Author:
David Benjamin <davidben@davidben.net>
Parents:
9ae6095 (diff), 0071c88 (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 0071c88bc882ae44b235200e821626eb6e96230e into 9ae6095ed62f67742f9d4dc1008180e8d23e7b12
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r0071c88 r7dcef03  
    115115void owl_function_show_license(void)
    116116{
    117   const char *text;
    118 
    119   text=""
    120     "BarnOwl version " OWL_VERSION_STRING "\n"
     117  char *text = g_strdup_printf(
     118    "BarnOwl version %s\n"
    121119    "Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n"
    122120    "Copyright (c) 2004 James Kretchmar. All rights reserved.\n"
     
    155153    "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n"
    156154    "OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n"
    157     "IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n";
     155    "IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n",
     156    version);
    158157  owl_function_popless_text(text);
     158  g_free(text);
    159159}
    160160
     
    196196  owl_message *m;
    197197
    198   m=g_new(owl_message, 1);
     198  m=g_slice_new(owl_message);
    199199  owl_message_create_admin(m, header, body);
    200200 
     
    204204
    205205  /* do followlast if necessary */
    206   if (owl_global_should_followlast(&g)) owl_function_lastmsg_noredisplay();
     206  if (owl_global_should_followlast(&g)) owl_function_lastmsg();
    207207
    208208  /* redisplay etc. */
     
    216216void owl_function_add_outgoing_zephyrs(const owl_zwrite *z)
    217217{
    218   if (z->cc || owl_zwrite_get_numrecips(z) == 0) {
     218  if (z->cc && owl_zwrite_is_personal(z)) {
    219219    /* create the message */
    220     owl_message *m = g_new(owl_message, 1);
     220    owl_message *m = g_slice_new(owl_message);
    221221    owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0);
    222222
     
    225225    int i;
    226226    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
    227232      /* create the message */
    228       owl_message *m = g_new(owl_message, 1);
     233      m = g_slice_new(owl_message);
    229234      owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i);
    230235
     
    246251  if (!owl_global_is_aimloggedin(&g)) return(NULL);
    247252 
    248   m=g_new(owl_message, 1);
     253  m=g_slice_new(owl_message);
    249254  owl_message_create_aim(m,
    250255                         owl_global_get_aim_screenname(&g),
     
    265270
    266271  /* create the message */
    267   m=g_new(owl_message, 1);
     272  m=g_slice_new(owl_message);
    268273  owl_message_create_loopback(m, body);
    269274  owl_message_set_direction_out(m);
     
    272277}
    273278
    274 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)
    275280{
    276281  owl_editwin *e;
     
    286291  g_free(s);
    287292
    288   owl_editwin_set_cbdata(e, data, cleanup);
    289   owl_editwin_set_callback(e, callback);
    290293  ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti",
    291294                            owl_global_deactivate_editcontext, &g);
    292295  owl_global_push_context_obj(&g, ctx);
    293 
     296  return e;
    294297}
    295298
     
    309312void owl_function_zwrite_setup(owl_zwrite *z)
    310313{
     314  owl_editwin *e;
    311315  /* send a ping if necessary */
    312316  if (owl_global_is_txping(&g)) {
     
    316320
    317321  owl_function_write_setup("zephyr");
    318   owl_function_start_edit_win(z->zwriteline,
    319                               &owl_callback_zwrite,
    320                               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);
    321325}
    322326
    323327void owl_function_aimwrite_setup(const char *to)
    324328{
     329  owl_editwin *e;
    325330  /* TODO: We probably actually want an owl_aimwrite object like
    326331   * owl_zwrite. */
    327332  char *line = g_strdup_printf("aimwrite %s", to);
    328333  owl_function_write_setup("message");
    329   owl_function_start_edit_win(line,
    330                               &owl_callback_aimwrite,
    331                               g_strdup(to),
    332                               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);
    333337  g_free(line);
    334338}
     
    336340void owl_function_loopwrite_setup(void)
    337341{
     342  owl_editwin *e;
    338343  owl_function_write_setup("message");
    339   owl_function_start_edit_win("loopwrite",
    340                               &owl_callback_loopwrite,
    341                               NULL, NULL);
    342 }
    343 
    344 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;
    345351  owl_zwrite *z = owl_editwin_get_cbdata(e);
    346352  owl_function_zwrite(z, owl_editwin_get_text(e));
     
    372378  owl_function_makemsg("Waiting for ack...");
    373379
    374   /* If it's personal */
    375   if (owl_zwrite_is_personal(z)) {
    376     /* create the outgoing message */
    377     owl_function_add_outgoing_zephyrs(z);
    378   }
     380  /* create the outgoing message */
     381  owl_function_add_outgoing_zephyrs(z);
    379382}
    380383#else
     
    402405
    403406  zcrypt = g_build_filename(owl_get_bindir(), "zcrypt", NULL);
    404   argv[0] = "zcrypt";
     407  argv[0] = zcrypt;
    405408  argv[1] = "-E";
    406409  argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z);
     
    408411  argv[6] = NULL;
    409412
    410   rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status);
     413  rv = call_filter(argv, owl_zwrite_get_message(z), &cryptmsg, &status);
    411414
    412415  g_free(zcrypt);
     
    426429  owl_function_makemsg("Waiting for ack...");
    427430
    428   /* If it's personal */
    429   if (owl_zwrite_is_personal(z)) {
    430     /* Create the outgoing message. Restore the un-crypted message for display. */
    431     owl_zwrite_set_message_raw(z, old_msg);
    432     owl_function_add_outgoing_zephyrs(z);
    433   }
    434 
    435   /* 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. */
    436436  g_free(cryptmsg);
    437 }
    438 
    439 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;
    440443  char *to = owl_editwin_get_cbdata(e);
    441444  owl_function_aimwrite(to, owl_editwin_get_text(e), true);
     
    501504}
    502505
    503 void owl_callback_loopwrite(owl_editwin *e) {
     506void owl_callback_loopwrite(owl_editwin *e, bool success)
     507{
     508  if (!success) return;
    504509  owl_function_loopwrite(owl_editwin_get_text(e));
    505510}
     
    511516  /* create a message and put it on the message queue.  This simulates
    512517   * an incoming message */
    513   min=g_new(owl_message, 1);
     518  min=g_slice_new(owl_message);
    514519  mout=owl_function_make_outgoing_loopback(msg);
    515520
     
    808813}
    809814
    810 void owl_function_lastmsg_noredisplay(void)
     815void owl_function_lastmsg(void)
    811816{
    812817  int oldcurmsg, curmsg;
     
    826831    owl_global_set_curmsg(&g, curmsg+1);
    827832  }
    828   /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */
     833  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    829834  owl_global_set_direction_downwards(&g);
    830 }
    831 
    832 void owl_function_lastmsg(void)
    833 {
    834   owl_function_lastmsg_noredisplay();
    835   owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 
    836835}
    837836
     
    856855void owl_function_unsuball(void)
    857856{
    858   unsuball();
    859   owl_function_makemsg("Unsubscribed from all messages.");
     857  if (unsuball())
     858    owl_function_makemsg("Unsubscribed from all messages.");
    860859}
    861860
     
    872871void owl_function_loadsubs(const char *file)
    873872{
    874   int ret, ret2;
    875   const char *foo;
     873  int ret, ret2, ret3;
    876874  char *path;
    877875
     
    885883
    886884  /* for backwards compatibility for now */
    887   ret2=owl_zephyr_loaddefaultsubs();
     885  ret2 = owl_zephyr_loaddefaultsubs();
     886  ret3 = owl_zephyr_loadbarnowldefaultsubs();
    888887
    889888  if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
    890889
    891   foo=file?file:"file";
    892   if (ret==0 && ret2==0) {
     890  if (ret == 0 && ret2 == 0 && ret3 == 0) {
    893891    if (!file) {
    894892      owl_function_makemsg("Subscribed to messages.");
     
    896894      owl_function_makemsg("Subscribed to messages from %s", file);
    897895    }
    898   } else if (ret==-1) {
    899     owl_function_error("Could not read %s", foo);
    900   } else {
     896  } else if (ret == -1) {
     897    owl_function_error("Could not read %s", file ? file : "file");
     898  } else if (ret2 == -1) {
    901899    owl_function_error("Error subscribing to messages");
     900  } else {
     901    owl_function_error("Error subscribing to instanced personals");
    902902  }
    903903}
     
    918918}
    919919
    920 void owl_callback_aimlogin(owl_editwin *e) {
     920void owl_callback_aimlogin(owl_editwin *e, bool success)
     921{
     922  if (!success) return;
    921923  char *user = owl_editwin_get_cbdata(e);
    922924  owl_function_aimlogin(user,
     
    989991  /* owl_aim_set_awaymsg(""); */
    990992  owl_function_makemsg("AIM away off");
     993}
     994
     995bool owl_function_is_away(void)
     996{
     997  return owl_global_is_zaway(&g) ||
     998         owl_global_is_aaway(&g) ||
     999         owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL);
    9911000}
    9921001
     
    13501359void owl_function_about(void)
    13511360{
    1352   owl_function_popless_text(
    1353     "This is BarnOwl version " OWL_VERSION_STRING ".\n\n"
     1361  char *text = g_strdup_printf(
     1362    "This is BarnOwl version %s.\n\n"
    13541363    "BarnOwl is a fork of the Owl zephyr client, written and\n"
    13551364    "maintained by Alejandro Sedeno and Nelson Elhage at the\n"
     
    13701379    "This program is free software. You can redistribute it and/or\n"
    13711380    "modify under the terms of the Sleepycat License. Use the \n"
    1372     "':show license' command to display the full license\n"
    1373   );
     1381      "':show license' command to display the full license\n",
     1382      version);
     1383  owl_function_popless_text(text);
     1384  g_free(text);
    13741385}
    13751386
     
    14301441      char *tmpbuff, *tmpbuff2;
    14311442      int i, fields;
     1443      const char *f;
    14321444
    14331445      if (!owl_message_is_pseudo(m)) {
     
    14601472        owl_fmtext_append_normal(&fm, "\n");
    14611473        owl_fmtext_appendf_normal(&fm, "  Port      : %i\n", ntohs(n->z_port));
     1474        owl_fmtext_appendf_normal(&fm, "  Charset   : %s\n", owl_zephyr_get_charsetstr(n));
    14621475        owl_fmtext_appendf_normal(&fm, "  Auth      : %s\n", owl_zephyr_get_authstr(n));
    14631476
     
    14711484        owl_fmtext_appendf_normal(&fm, "  Fields    : %i\n", fields);
    14721485
    1473         for (i = 0; i < fields; i++) {
    1474           tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1);
     1486        for (i = 0, f = owl_zephyr_first_raw_field(n); f != NULL;
     1487             i++, f = owl_zephyr_next_raw_field(n, f)) {
     1488          tmpbuff = owl_zephyr_field_as_utf8(n, f);
    14751489          tmpbuff2 = owl_text_indent(tmpbuff, 14, false);
    14761490          owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i + 1, tmpbuff2);
     
    17701784
    17711785  owl_fmtext_append_normal(&fm, "  Version: ");
    1772   owl_fmtext_append_normal(&fm, OWL_VERSION_STRING);
     1786  owl_fmtext_append_normal(&fm, version);
    17731787  owl_fmtext_append_normal(&fm, "\n");
    17741788
     
    19401954}
    19411955
    1942 void owl_callback_command(owl_editwin *e)
    1943 {
     1956void owl_callback_command(owl_editwin *e, bool success)
     1957{
     1958  if (!success) return;
    19441959  char *rv;
    19451960  const char *line = owl_editwin_get_text(e);
     
    19521967}
    19531968
    1954 void owl_function_start_command(const char *line)
     1969owl_editwin *owl_function_start_command(const char *line)
    19551970{
    19561971  owl_editwin *tw;
     
    19671982  owl_global_push_context_obj(&g, ctx);
    19681983  owl_editwin_set_callback(tw, owl_callback_command);
    1969 }
    1970 
    1971 CALLER_OWN owl_editwin *owl_function_start_question(const char *line)
     1984  return tw;
     1985}
     1986
     1987owl_editwin *owl_function_start_question(const char *line)
    19721988{
    19731989  owl_editwin *tw;
     
    19842000}
    19852001
    1986 CALLER_OWN owl_editwin *owl_function_start_password(const char *line)
     2002owl_editwin *owl_function_start_password(const char *line)
    19872003{
    19882004  owl_editwin *tw;
     
    21812197  f = owl_filter_new(argv[1], argc-2, argv+2);
    21822198  if (f == NULL) {
    2183     owl_function_error("Invalid filter");
     2199    owl_function_error("Invalid filter: %s", argv[1]);
    21842200    return false;
    21852201  }
     
    34663482  while (zaldptr) {
    34673483    ZFreeALD(zaldptr->data);
    3468     g_free(zaldptr->data);
     3484    g_slice_free(ZAsyncLocateData_t, zaldptr->data);
    34693485    zaldptr = g_list_next(zaldptr);
    34703486  }
     
    34763492    for (i = 0; i < anyone->len; i++) {
    34773493      user = anyone->pdata[i];
    3478       zald = g_new(ZAsyncLocateData_t, 1);
     3494      zald = g_slice_new(ZAsyncLocateData_t);
    34793495      if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) {
    34803496        *zaldlist = g_list_append(*zaldlist, zald);
    34813497      } else {
    3482         g_free(zald);
     3498        g_slice_free(ZAsyncLocateData_t, zald);
    34833499      }
    34843500    }
Note: See TracChangeset for help on using the changeset viewer.