Changes in / [3bc7358:f4d817d]


Ignore:
Files:
2 deleted
40 edited

Legend:

Unmodified
Added
Removed
  • Makefile.in

    r7e78e49 rdf7f364  
    55prefix = @prefix@
    66exec_prefix = @exec_prefix@
     7datarootdir = @datarootdir@
    78datadir = @datadir@/barnowl
    89bindir = @bindir@
     
    2526     regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
    2627     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    27      aim.c buddy.c buddylist.c timer.c style.c errqueue.c \
    28      zbuddylist.c muxevents.c popexec.c obarray.c select.c wcwidth.c \
     28     aim.c buddy.c buddylist.c style.c errqueue.c \
     29     zbuddylist.c popexec.c obarray.c select.c wcwidth.c \
    2930     glib_compat.c
    3031OWL_SRC = owl.c
     
    5354        $(ATHSTATIC) $(CC) -o $(EXE) owl.o $(OBJS) $(LDFLAGS) $(LIBS)
    5455
    55 tester: $(AUTOGEN) $(OBJS) tester.o
     56tester: $(AUTOGEN) $(OBJS) tester.o libfaim
    5657        $(ATHSTATIC) $(CC) -o tester tester.o $(OBJS) $(LDFLAGS) $(LIBS)
    5758
  • aim.c

    re3e6cff rc675b39  
    130130}
    131131
     132void owl_aim_send_nop(owl_timer *t, void *data) {
     133    if(owl_global_is_doaimevents(&g)) {
     134        aim_session_t *sess = owl_global_get_aimsess(&g);
     135        aim_flap_nop(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS));
     136    }
     137}
     138
    132139
    133140int owl_aim_login(char *screenname, char *password)
     
    194201  owl_function_debugmsg("owl_aim_login: connecting");
    195202
     203  g.aim_nop_timer = owl_select_add_timer(30, 30, owl_aim_send_nop, NULL, NULL);
     204
    196205  return(0);
     206}
     207
     208void owl_aim_unset_ignorelogin(owl_timer *t, void *data) {      /* noproto */
     209    owl_global_unset_ignore_aimlogin(&g);
    197210}
    198211
     
    212225
    213226  /* start the ingorelogin timer */
    214   owl_timer_reset_newstart(owl_global_get_aim_login_timer(&g),
    215                            owl_global_get_aim_ignorelogin_timer(&g));
    216 
    217  
     227  owl_global_set_ignore_aimlogin(&g);
     228  owl_select_add_timer(owl_global_get_aim_ignorelogin_timer(&g),
     229                       0, owl_aim_unset_ignorelogin, NULL, NULL);
     230
    218231  /* aim_ssi_setpresence(owl_global_get_aimsess(&g), 0x00000400); */
    219232  /* aim_bos_setidle(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), 5000); */
     
    228241  owl_global_set_aimnologgedin(&g);
    229242  owl_global_set_no_doaimevents(&g);
     243  owl_select_remove_timer(g.aim_nop_timer);
    230244}
    231245
     
    239253{
    240254  if (message) {
    241     owl_function_error(message);
     255    owl_function_error("%s", message);
    242256  } else {
    243257    owl_function_error("Authentication error on login");
     
    246260  owl_global_set_aimnologgedin(&g);
    247261  owl_global_set_no_doaimevents(&g);
     262  owl_select_remove_timer(g.aim_nop_timer);
    248263}
    249264
     
    252267  int ret;
    253268
    254   ret=aim_im_sendch1(owl_global_get_aimsess(&g), to, NULL, msg);
     269  ret=aim_im_sendch1(owl_global_get_aimsess(&g), to, 0, msg);
    255270   
    256271  /* I don't know how to check for an error yet */
     
    422437  tv.tv_usec = 0;
    423438  waitingconn = aim_select(aimsess, &tv, &selstat);
    424 
    425   if (owl_global_is_aimnop_time(&g)) {
    426     aim_flap_nop(aimsess, aim_getconn_type(aimsess, AIM_CONN_TYPE_BOS));
    427     owl_global_aimnop_sent(&g);
    428   }
    429439
    430440  if (selstat == -1) {
     
    16981708 
    16991709  /* printf("snac threw error (reason 0x%04x: %s)\n", reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */
    1700   if (reason<msgerrreasonslen) owl_function_error(msgerrreasons[reason]);
     1710  if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]);
    17011711 
    17021712  return 1;
     
    17151725 
    17161726  /* printf("message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */
    1717   if (reason<msgerrreasonslen) owl_function_error(msgerrreasons[reason]);
     1727  if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]);
    17181728
    17191729  if (reason==4) {
     
    17361746 
    17371747  /* printf("user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */
    1738   if (reason<msgerrreasonslen) owl_function_error(msgerrreasons[reason]);
     1748  if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]);
    17391749 
    17401750  return 1;
     
    23092319  aim_sendcookie(sess, tstconn, redir->cookielen, redir->cookie);
    23102320  return;       
     2321}
     2322
     2323void owl_process_aim()
     2324{
     2325  if (owl_global_is_doaimevents(&g)) {
     2326    owl_aim_process_events();
     2327  }
    23112328}
    23122329
  • buddylist.c

    r257a22f rb7bb454  
    5151
    5252    /* are we ingoring login messages for a while? */
    53     if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
     53    if (owl_global_is_ignore_aimlogin(&g)) return;
    5454
    5555    /* if not, create the login message */
  • commands.c

    r451db9e rf34dd65  
    453453  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
    454454              "pops up a message in a window", "", ""),
    455 
    456   OWLCMD_VOID("openurl", owl_command_openurl, OWL_CTX_INTERACTIVE,
    457               "opens up a URL from the current message",
    458               "",
    459               "Uses the 'webbrowser' variable to determine\n"
    460               "which browser to use.  Currently, 'netscape'\n"
    461               "and 'galeon' are supported.\n"),
    462455
    463456  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
     
    641634              "show keymap <keymap>\n"
    642635              "show license\n"
     636              "show quickstart\n"
    643637              "show startup\n"
    644638              "show status\n"
     
    10461040void owl_command_version()
    10471041{
    1048   char buff[1024];
    1049 
    1050   sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
    1051   owl_function_makemsg(buff);
     1042  owl_function_makemsg("BarnOwl version %s", OWL_VERSION_STRING);
    10521043}
    10531044
     
    14611452    owl_function_aaway_on();
    14621453    owl_function_zaway_on();
    1463     owl_function_makemsg("Away messages set.", owl_global_get_aaway_msg_default(&g));
     1454    owl_function_makemsg("Away messages set.");
    14641455    return NULL;
    14651456  }
     
    16911682  }
    16921683
    1693   owl_function_debugmsg(argv[1]);
     1684  owl_function_debugmsg("%s", argv[1]);
    16941685  return(NULL);
    16951686}
     
    17351726  return(NULL);
    17361727}
    1737 
    1738 
    1739 void owl_command_zlog_out(void)
    1740 {
    1741   owl_zephyr_zlog_out();
    1742 }
    1743 
    17441728
    17451729char *owl_command_subscribe(int argc, char **argv, char *buff)
     
    22072191  } else if (!strcmp(argv[1], "license")) {
    22082192    owl_function_show_license();
     2193  } else if (!strcmp(argv[1], "quickstart")) {
     2194    owl_function_show_quickstart();
    22092195  } else if (!strcmp(argv[1], "startup")) {
    22102196    char *filename;
     
    22512237{
    22522238  owl_function_curmsg_to_popwin();
    2253 }
    2254 
    2255 void owl_command_openurl(void)
    2256 {
    2257   owl_function_openurl();
    22582239}
    22592240
     
    25802561{
    25812562    buff = skiptokens(buff, 1);
    2582     owl_function_error(buff);
     2563    owl_function_error("%s", buff);
    25832564    return NULL;
    25842565}
     
    25872568{
    25882569    buff = skiptokens(buff, 1);
    2589     owl_function_makemsg(buff);
     2570    owl_function_makemsg("%s", buff);
    25902571    return NULL;
    25912572}
  • configure.ac

    rd9337637 rd54035d  
    4646fi
    4747
    48 AC_CHECK_LIB(ncursesw, initscr,, AC_MSG_ERROR(No curses library found.))
     48AC_CHECK_LIB(ncursesw, initscr,, AC_MSG_ERROR(No libncursesw found.))
    4949AC_CHECK_LIB(com_err, com_err)
    5050AC_CHECK_LIB(nsl, gethostbyname)
  • editwin.c

    re9bb404 r50e671c  
    10421042    if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break;
    10431043
     1044    /* bail if we hit a trailing dot on the buffer */
     1045    if (e->buff[i] == '\n' && e->buff[i+1] == '.'
     1046        && ((i+2) >= e->bufflen || e->buff[i+2] == '\0'))
     1047      break;
     1048
    10441049    /* if we've travelled too far, linewrap */
    10451050    if ((e->buffx) >= e->fillcol) {
  • examples/owlconf.erik

    r5d9c664 r4f15e8e  
    147147    owl::command("set -q rxping on");
    148148    owl::command("set -q typewinsize 5");
    149     if ($ENV{"DISPLAY"} eq ":0.0") {
    150       owl::command("set -q webbrowser galeon");
    151     }
    152149    owl::command("filter me recipient %me% or ( sender %me% and class message and instance personal ) or class mail or type aim");
    153150    owl::command("filter owl instance ^owl.*");
  • examples/owlconf.simple

    r2b14303 r4f15e8e  
    9393    # owl::command('set -q view_home all');
    9494
    95 
    96     ## Which webbrowser to use to launch URLs with the 'w' key.
    97     # owl::command('set -q webbrowser netscape');
    98     # owl::command('set -q webbrowser galeon');
    99     # owl::command('set -q webbrowser none');
    10095
    10196    ## Default message to send when zaway is on (toggle with 'A')
  • filter.c

    rcdc6ff1 rf34dd65  
    33
    44static const char fileIdent[] = "$Id$";
    5 
    6 #define OWL_FILTER_MAXRECURSE 20
    75
    86int owl_filter_init_fromstring(owl_filter *f, char *name, char *string)
     
    2018{
    2119  f->name=owl_strdup(name);
    22   f->polarity=0;
    2320  f->fgcolor=OWL_COLOR_DEFAULT;
    2421  f->bgcolor=OWL_COLOR_DEFAULT;
     
    5047  /* Now check for recursion. */
    5148  if (owl_filter_is_toodeep(f)) {
    52     owl_function_error("Filter loop or exceeds recursion depth");
     49    owl_function_error("Filter loop!");
    5350    owl_filter_free(f);
    5451    return(-1);
     
    159156}
    160157
    161 void owl_filter_set_polarity_match(owl_filter *f)
    162 {
    163   f->polarity=0;
    164 }
    165 
    166 void owl_filter_set_polarity_unmatch(owl_filter *f)
    167 {
    168   f->polarity=1;
    169 }
    170 
    171158void owl_filter_set_fgcolor(owl_filter *f, int color)
    172159{
     
    207194  if(!f->root) return 0;
    208195  ret = owl_filterelement_match(f->root, m);
    209   if(f->polarity) ret = !ret;
    210196  return ret;
    211197}
     
    313299  int numfailed=0;
    314300  owl_message m;
    315   owl_filter f1, f2, f3, f4;
     301  owl_filter f1, f2, f3, f4, f5;
    316302
    317303  owl_list_create(&(g.filterlist));
     
    365351  FAIL_UNLESS("mutual recursion",   owl_filter_init_fromstring(&f4, "f4", "filter f3"));
    366352
     353  /* support referencing a filter several times */
     354  FAIL_UNLESS("DAG", !owl_filter_init_fromstring(&f5, "dag", "filter f1 or filter f1"));
     355
    367356  return 0;
    368357}
  • filterelement.c

    r0504f63 rf446454  
    279279}
    280280
     281static int fe_visiting = 0;
     282static int fe_visited  = 1;
     283
    281284int owl_filterelement_is_toodeep(owl_filter *f, owl_filterelement *fe)
    282285{
    283   int one = 1;
    284   owl_list nodes;
     286  int rv;
    285287  owl_dict filters;
    286   owl_list_create(&nodes);
    287288  owl_dict_create(&filters);
    288  
    289   owl_list_append_element(&nodes, fe);
    290   owl_dict_insert_element(&filters, f->name, &one, NULL);
    291   while(owl_list_get_size(&nodes)) {
    292     fe = owl_list_get_element(&nodes, 0);
    293     owl_list_remove_element(&nodes, 0);
    294     if(fe->left) owl_list_append_element(&nodes, fe->left);
    295     if(fe->right) owl_list_append_element(&nodes, fe->right);
    296     if(fe->match_message == owl_filterelement_match_filter) {
    297       if(owl_dict_find_element(&filters, fe->field)) return 1;
    298       owl_dict_insert_element(&filters, fe->field, &one, NULL);
     289
     290  owl_dict_insert_element(&filters, f->name, &fe_visiting, owl_dict_noop_free);
     291
     292  rv = _owl_filterelement_is_toodeep(fe, &filters);
     293
     294  owl_dict_free_simple(&filters);
     295  return rv;
     296}
     297
     298int _owl_filterelement_is_toodeep(owl_filterelement *fe, owl_dict *seen)
     299{
     300  int rv = 0;
     301  owl_filter *f;
     302
     303  if(fe->match_message == owl_filterelement_match_filter) {
     304    int *nval = owl_dict_find_element(seen, fe->field);
     305    if(nval == &fe_visiting) {
     306      return 1;
     307    } else if (nval == NULL) {
    299308      f = owl_global_get_filter(&g, fe->field);
    300       if(f) owl_list_append_element(&nodes, f->root);
     309      owl_dict_insert_element(seen, fe->field, &fe_visiting, owl_dict_noop_free);
     310      if(f) rv = _owl_filterelement_is_toodeep(f->root, seen);
     311      owl_dict_insert_element(seen, fe->field, &fe_visited, owl_dict_noop_free);
    301312    }
    302   }
    303 
    304   owl_list_free_simple(&nodes);
    305   owl_dict_free_simple(&filters);
    306   return 0;
     313  } else {
     314    if(fe->left)
     315      rv = rv || _owl_filterelement_is_toodeep(fe->left, seen);
     316    if(fe->right)
     317      rv = rv || _owl_filterelement_is_toodeep(fe->right, seen);
     318  }
     319  return rv;
    307320}
    308321
  • fmtext.c

    r6f6330b r1490327  
    9090}
    9191
     92/* Append normal, uncolored text specified by format string to 'f' */
     93void owl_fmtext_appendf_normal(owl_fmtext *f, char *fmt, ...)
     94{
     95  va_list ap;
     96  char *buff;
     97
     98  va_start(ap, fmt);
     99  buff = g_strdup_vprintf(fmt, ap);
     100  va_end(ap);
     101  if (!buff)
     102    return;
     103  owl_fmtext_append_attr(f, buff, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
     104}
     105
    92106/* Append normal text 'text' to 'f' with color 'color' */
    93107void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int fgcolor, int bgcolor)
     
    169183
    170184/* Internal function.  Append text from 'in' between index 'start' and
    171  * 'stop' to the end of 'f'
     185 * 'stop', inclusive, to the end of 'f'. This function works with
     186 * bytes.
    172187 */
    173188void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/
     
    474489        _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    475490      }
     491      else if (chwidth > 1) {
     492        /* Last char is wide, truncate. */
     493        _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
     494        owl_fmtext_append_normal(out, "\n");
     495      }
    476496      else {
    477         if (chwidth > 1) {
    478           /* Last char is wide, truncate. */
    479           _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
    480           owl_fmtext_append_normal(out, "\n");
    481         }
    482         else {
    483           /* Last char fits perfectly, leave alone.*/
    484           _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff);
    485         }
     497        /* Last char fits perfectly, We skip to the next char and back
     498         * up a byte to make sure we get it all.
     499         */
     500        ptr_c = g_utf8_next_char(ptr_c);
     501        _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1);
    486502      }
    487503    }
     
    763779 * If format_fn is specified, passes it the list element value
    764780 * and it will return a string which this needs to free. */
    765 void owl_fmtext_append_list(owl_fmtext *f, owl_list *l, char *join_with, char *(format_fn)(void*))
     781void owl_fmtext_append_list(owl_fmtext *f, owl_list *l, char *join_with, char *(format_fn)(char *))
    766782{
    767783  int i, size;
    768   void *elem;
     784  char *elem;
    769785  char *text;
    770786
  • functions.c

    r3f3ee61 rb4c270c  
    1515static const char fileIdent[] = "$Id$";
    1616
    17 void owl_function_noop(void)
    18 {
    19   return;
    20 }
    21 
    2217char *owl_function_command(char *cmdbuff)
    2318{
     
    9994}
    10095
    101 char *owl_function_style_describe(void *name) {
     96char *owl_function_style_describe(char *name) {
    10297  char *desc, *s;
    10398  owl_style *style;
     
    114109}
    115110
    116 char *owl_function_cmd_describe(void *name)
     111char *owl_function_cmd_describe(char *name)
    117112{
    118113  owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name);
     
    172167}
    173168
     169void owl_function_show_quickstart()
     170{
     171    char *message =
     172    "Move between messages with the arrow keys, and press 'r' to reply.\n"
     173    "For more info, press 'h' or visit http://barnowl.mit.edu/\n\n"
     174#ifdef HAVE_LIBZEPHYR
     175    "@b(Zephyr:)\n"
     176    "To send a message to a user, type ':zwrite @b(username)'. You can also\n"
     177    "press 'z' and then type the username. To subscribe to a class, type\n"
     178    "':sub @b(class)', and then type ':zwrite -c @b(class)' to send.\n\n"
     179#endif
     180    "@b(AIM:)\n"
     181    "Log in to AIM with ':aimlogin @b(screenname)'. Use ':aimwrite @b(screenname)',\n"
     182    "or 'a' and then the screen name, to send someone a message.\n\n"
     183    ;
     184
     185    if (owl_perlconfig_is_function("BarnOwl::Hooks::_get_quickstart")) {
     186        char *perlquickstart = owl_perlconfig_execute("BarnOwl::Hooks::_get_quickstart()");
     187        if (perlquickstart) {
     188            char *result = owl_sprintf("%s%s", message, perlquickstart);
     189            owl_function_adminmsg("BarnOwl Quickstart", result);
     190            owl_free(result);
     191            owl_free(perlquickstart);
     192            return;
     193        }
     194    }
     195    owl_function_adminmsg("BarnOwl Quickstart", message);
     196}
     197
     198
    174199/* Create an admin message, append it to the global list of messages
    175200 * and redisplay if necessary.
     
    602627
    603628  if (!found) {
    604     owl_function_makemsg("already at last%s message%s%s",
     629    owl_function_makemsg("already at last%s message%s%s%s",
    605630                         skip_deleted?" non-deleted":"",
    606                          filter?" in ":"", filter?filter:"");
     631                         filter?" in ":"", filter?filter:"",
     632                         owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g)) ?
     633                         ", press Enter to scroll" : "");
    607634    /* if (!skip_deleted) owl_function_beep(); */
    608635  }
     
    684711  owl_function_prevmsg_full(NULL, 1, 1);
    685712}
    686 
    687 void owl_function_nextmsg_personal()
    688 {
    689   owl_function_nextmsg_full("personal", 0, 0);
    690 }
    691 
    692 void owl_function_prevmsg_personal()
    693 {
    694   owl_function_prevmsg_full("personal", 0, 0);
    695 }
    696 
    697713
    698714/* if move_after is 1, moves after the delete */
     
    10191035  owl_function_debugmsg("Quitting Owl");
    10201036  exit(0);
    1021 }
    1022 
    1023 void owl_function_openurl()
    1024 {
    1025   /* visit the first url in the current message */
    1026   owl_message *m;
    1027   owl_view *v;
    1028   char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];
    1029   int webbrowser;
    1030 
    1031   webbrowser = owl_global_get_webbrowser(&g);
    1032 
    1033   if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {
    1034     owl_function_error("No browser selected");
    1035     return;
    1036   }
    1037 
    1038   v=owl_global_get_current_view(&g);
    1039  
    1040   m=owl_view_get_element(v, owl_global_get_curmsg(&g));
    1041 
    1042   if (!m || owl_view_get_size(v)==0) {
    1043     owl_function_error("No current message selected");
    1044     return;
    1045   }
    1046 
    1047   text=owl_message_get_text(m);
    1048 
    1049   /* First look for a good URL */ 
    1050   if ((ptr1=strstr(text, "http://"))!=NULL) {
    1051     ptr2=strpbrk(ptr1, " \n\t");
    1052     if (ptr2) {
    1053       strncpy(url, ptr1, ptr2-ptr1+1);
    1054       url[ptr2-ptr1+1]='\0';
    1055     } else {
    1056       strcpy(url, ptr1);
    1057     }
    1058 
    1059     /* if we had <http strip a trailing > */
    1060     if (ptr1>text && ptr1[-1]=='<') {
    1061       if (url[strlen(url)-1]=='>') {
    1062         url[strlen(url)-1]='\0';
    1063       }
    1064     }
    1065   } else if ((ptr1=strstr(text, "https://"))!=NULL) {
    1066     /* Look for an https URL */ 
    1067     ptr2=strpbrk(ptr1, " \n\t");
    1068     if (ptr2) {
    1069       strncpy(url, ptr1, ptr2-ptr1+1);
    1070       url[ptr2-ptr1+1]='\0';
    1071     } else {
    1072       strcpy(url, ptr1);
    1073     }
    1074    
    1075     /* if we had <http strip a trailing > */
    1076     if (ptr1>text && ptr1[-1]=='<') {
    1077       if (url[strlen(url)-1]=='>') {
    1078         url[strlen(url)-1]='\0';
    1079       }
    1080     }
    1081   } else if ((ptr1=strstr(text, "www."))!=NULL) {
    1082     /* if we can't find a real url look for www.something */
    1083     ptr2=strpbrk(ptr1, " \n\t");
    1084     if (ptr2) {
    1085       strncpy(url, ptr1, ptr2-ptr1+1);
    1086       url[ptr2-ptr1+1]='\0';
    1087     } else {
    1088       strcpy(url, ptr1);
    1089     }
    1090   } else {
    1091     owl_function_beep();
    1092     owl_function_error("Could not find URL to open.");
    1093     return;
    1094   }
    1095 
    1096   /* Make sure there aren't any quotes or \'s in the url */
    1097   for (ptr1 = url; *ptr1; ptr1++) {
    1098     if (*ptr1 == '"' || *ptr1 == '\\') {
    1099       owl_function_beep();
    1100       owl_function_error("URL contains invalid characters.");
    1101       return;
    1102     }
    1103   }
    1104  
    1105   /* NOTE: There are potentially serious security issues here... */
    1106 
    1107   /* open the page */
    1108   owl_function_makemsg("Opening %s", url);
    1109   if (webbrowser == OWL_WEBBROWSER_NETSCAPE) {
    1110     snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url);
    1111     system(tmpbuff);
    1112   } else if (webbrowser == OWL_WEBBROWSER_GALEON) {
    1113     snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url);
    1114     system(tmpbuff);
    1115   } else if (webbrowser == OWL_WEBBROWSER_OPERA) {
    1116     snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url);
    1117     system(tmpbuff);
    1118   }
    11191037}
    11201038
     
    13441262}
    13451263
    1346 void owl_function_refresh()
    1347 {
    1348   owl_function_resize();
    1349 }
    1350 
    13511264void owl_function_beep()
    13521265{
     
    14711384void owl_function_about()
    14721385{
    1473   char buff[5000];
    1474 
    1475   sprintf(buff, "This is barnowl version %s\n\n", OWL_VERSION_STRING);
    1476   strcat(buff, "barnowl is a fork of the Owl zephyr client, written and\n");
    1477   strcat(buff, "maintained by Alejandro Sedeno and Nelson Elhage at the\n");
    1478   strcat(buff, "Massachusetts Institute of Technology. \n");
    1479   strcat(buff, "\n");
    1480   strcat(buff, "Owl was written by James Kretchmar. The first version, 0.5, was\n");
    1481   strcat(buff, "released in March 2002.\n");
    1482   strcat(buff, "\n");
    1483   strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n");
    1484   strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n");
    1485   strcat(buff, "between Witches and Wizards. The name 'barnowl' was chosen\n");
    1486   strcat(buff, "because we feel our owls should live closer to our ponies.\n");
    1487   strcat(buff, "\n");
    1488   strcat(buff, "Copyright (c) 2006-2008 The BarnOwl Developers. All rights reserved.\n");
    1489   strcat(buff, "Copyright (c) 2004 James Kretchmar. All rights reserved.\n");
    1490   strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n");
    1491   strcat(buff, "\n");
    1492   strcat(buff, "This program is free software. You can redistribute it and/or\n");
    1493   strcat(buff,  "modify under the terms of the Sleepycat License. Use the \n");
    1494   strcat(buff,  "':show license' command to display the full license\n");
    1495   owl_function_popless_text(buff);
     1386  owl_function_popless_text(
     1387    "This is barnowl version " OWL_VERSION_STRING ".\n\n"
     1388    "barnowl is a fork of the Owl zephyr client, written and\n"
     1389    "maintained by Alejandro Sedeno and Nelson Elhage at the\n"
     1390    "Massachusetts Institute of Technology. \n"
     1391    "\n"
     1392    "Owl was written by James Kretchmar. The first version, 0.5, was\n"
     1393    "released in March 2002.\n"
     1394    "\n"
     1395    "The name 'owl' was chosen in reference to the owls in the\n"
     1396    "Harry Potter novels, who are tasked with carrying messages\n"
     1397    "between Witches and Wizards. The name 'barnowl' was chosen\n"
     1398    "because we feel our owls should live closer to our ponies.\n"
     1399    "\n"
     1400    "Copyright (c) 2006-2008 The BarnOwl Developers. All rights reserved.\n"
     1401    "Copyright (c) 2004 James Kretchmar. All rights reserved.\n"
     1402    "Copyright 2002 Massachusetts Institute of Technology\n"
     1403    "\n"
     1404    "This program is free software. You can redistribute it and/or\n"
     1405    "modify under the terms of the Sleepycat License. Use the \n"
     1406    "':show license' command to display the full license\n"
     1407  );
    14961408}
    14971409
     
    15001412  owl_message *m;
    15011413  owl_fmtext fm, attrfm;
    1502   char buff[10000];
    15031414  owl_view *v;
    15041415#ifdef HAVE_LIBZEPHYR
     
    15161427
    15171428  owl_fmtext_append_bold(&fm, "General Information:\n");
    1518   owl_fmtext_append_normal(&fm, "  Msg Id    : ");
    1519   sprintf(buff, "%i", owl_message_get_id(m));
    1520   owl_fmtext_append_normal(&fm, buff);
    1521   owl_fmtext_append_normal(&fm, "\n");
     1429  owl_fmtext_appendf_normal(&fm, "  Msg Id    : %i\n", owl_message_get_id(m));
    15221430
    15231431  owl_fmtext_append_normal(&fm, "  Type      : ");
     
    15351443  }
    15361444
    1537   owl_fmtext_append_normal(&fm, "  Time      : ");
    1538   owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
    1539   owl_fmtext_append_normal(&fm, "\n");
     1445  owl_fmtext_appendf_normal(&fm, "  Time      : %s\n", owl_message_get_timestr(m));
    15401446
    15411447  if (!owl_message_is_type_admin(m)) {
    1542     owl_fmtext_append_normal(&fm, "  Sender    : ");
    1543     owl_fmtext_append_normal(&fm, owl_message_get_sender(m));
    1544     owl_fmtext_append_normal(&fm, "\n");
    1545    
    1546     owl_fmtext_append_normal(&fm, "  Recipient : ");
    1547     owl_fmtext_append_normal(&fm, owl_message_get_recipient(m));
    1548     owl_fmtext_append_normal(&fm, "\n");
    1549   }
    1550    
     1448    owl_fmtext_appendf_normal(&fm, "  Sender    : %s\n", owl_message_get_sender(m));
     1449    owl_fmtext_appendf_normal(&fm, "  Recipient : %s\n", owl_message_get_recipient(m));
     1450  }
     1451
    15511452  if (owl_message_is_type_zephyr(m)) {
    15521453    owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n");
    15531454   
    1554     owl_fmtext_append_normal(&fm, "  Class     : ");
    1555     owl_fmtext_append_normal(&fm, owl_message_get_class(m));
    1556     owl_fmtext_append_normal(&fm, "\n");
    1557     owl_fmtext_append_normal(&fm, "  Instance  : ");
    1558     owl_fmtext_append_normal(&fm, owl_message_get_instance(m));
    1559     owl_fmtext_append_normal(&fm, "\n");
    1560     owl_fmtext_append_normal(&fm, "  Opcode    : ");
    1561     owl_fmtext_append_normal(&fm, owl_message_get_opcode(m));
    1562     owl_fmtext_append_normal(&fm, "\n");
    1563    
    1564     owl_fmtext_append_normal(&fm, "  Time      : ");
    1565     owl_fmtext_append_normal(&fm, owl_message_get_timestr(m));
    1566     owl_fmtext_append_normal(&fm, "\n");
     1455    owl_fmtext_appendf_normal(&fm, "  Class     : %s\n", owl_message_get_class(m));
     1456    owl_fmtext_appendf_normal(&fm, "  Instance  : %s\n", owl_message_get_instance(m));
     1457    owl_fmtext_appendf_normal(&fm, "  Opcode    : %s\n", owl_message_get_opcode(m));
    15671458#ifdef HAVE_LIBZEPHYR
    15681459    if (owl_message_is_direction_in(m)) {
     
    15961487        }
    15971488      }
    1598       owl_fmtext_append_normal(&fm, "  Host      : ");
    1599       owl_fmtext_append_normal(&fm, owl_message_get_hostname(m));
     1489      owl_fmtext_appendf_normal(&fm, "  Host      : %s\n", owl_message_get_hostname(m));
    16001490
    16011491      if (!owl_message_is_pseudo(m)) {
    16021492        owl_fmtext_append_normal(&fm, "\n");
    1603         sprintf(buff, "  Port      : %i\n", ntohs(n->z_port));
    1604         owl_fmtext_append_normal(&fm, buff);
    1605 
    1606         owl_fmtext_append_normal(&fm,    "  Auth      : ");
    1607         owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n));
    1608         owl_fmtext_append_normal(&fm, "\n");
    1609        
    1610         /* fix this */
    1611         sprintf(buff, "  Checkd Ath: %i\n", n->z_checked_auth);
    1612         sprintf(buff, "%s  Multi notc: %s\n", buff, n->z_multinotice);
    1613         sprintf(buff, "%s  Num other : %i\n", buff, n->z_num_other_fields);
    1614         sprintf(buff, "%s  Msg Len   : %i\n", buff, n->z_message_len);
    1615         owl_fmtext_append_normal(&fm, buff);
    1616        
    1617         sprintf(buff, "  Fields    : %i\n", owl_zephyr_get_num_fields(n));
    1618         owl_fmtext_append_normal(&fm, buff);
    1619        
     1493        owl_fmtext_appendf_normal(&fm, "  Port      : %i\n", ntohs(n->z_port));
     1494        owl_fmtext_appendf_normal(&fm, "  Auth      : %s\n", owl_zephyr_get_authstr(n));
     1495
     1496        /* FIXME make these more descriptive */
     1497        owl_fmtext_appendf_normal(&fm, "  Checkd Ath: %i\n", n->z_checked_auth);
     1498        owl_fmtext_appendf_normal(&fm, "  Multi notc: %s\n", n->z_multinotice);
     1499        owl_fmtext_appendf_normal(&fm, "  Num other : %i\n", n->z_num_other_fields);
     1500        owl_fmtext_appendf_normal(&fm, "  Msg Len   : %i\n", n->z_message_len);
     1501
    16201502        fields=owl_zephyr_get_num_fields(n);
     1503        owl_fmtext_appendf_normal(&fm, "  Fields    : %i\n", fields);
     1504
    16211505        for (i=0; i<fields; i++) {
    1622           sprintf(buff, "  Field %i   : ", i+1);
    1623          
    16241506          ptr=owl_zephyr_get_field_as_utf8(n, i+1);
    16251507          len=strlen(ptr);
     
    16331515          }
    16341516          owl_free(ptr);
    1635          
     1517
    16361518          for (j=0; j<strlen(tmpbuff); j++) {
    16371519            if (tmpbuff[j]=='\n') tmpbuff[j]='~';
    16381520            if (tmpbuff[j]=='\r') tmpbuff[j]='!';
    16391521          }
    1640          
    1641           strcat(buff, tmpbuff);
    1642           strcat(buff, "\n");
    1643           owl_fmtext_append_normal(&fm, buff);
     1522
     1523          owl_fmtext_appendf_normal(&fm, "  Field %i   : %s\n", i+1, tmpbuff);
    16441524        }
    1645         owl_fmtext_append_normal(&fm, "  Default Fm:");
    1646         owl_fmtext_append_normal(&fm, n->z_default_format);
     1525        owl_fmtext_appendf_normal(&fm, "  Default Fm: %s\n", n->z_default_format);
    16471526      }
    1648      
    1649     }
    1650 #endif   
     1527
     1528    }
     1529#endif
    16511530  }
    16521531
     
    17491628}
    17501629
    1751 void owl_function_typwin_grow()
    1752 {
    1753   int i;
    1754 
    1755   i=owl_global_get_typwin_lines(&g);
    1756   owl_function_resize_typwin(i+1);
    1757 }
    1758 
    1759 void owl_function_typwin_shrink()
    1760 {
    1761   int i;
    1762 
    1763   i=owl_global_get_typwin_lines(&g);
    1764   if (i>2) {
    1765     owl_function_resize_typwin(i-1);
    1766   }
    1767 }
    1768 
    17691630void owl_function_mainwin_pagedown()
    17701631{
     
    18031664}
    18041665
    1805 #define PABUFLEN 5000
    18061666void owl_function_printallvars()
    18071667{
    1808   char buff[PABUFLEN], *pos, *name;
     1668  char *name;
     1669  char var[LINE];
    18091670  owl_list varnames;
    1810   int i, numvarnames, rem;
    1811 
    1812   pos = buff;
    1813   pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");
    1814   pos += sprintf(pos, "%-20s   %s\n",  "--------", "-----");
     1671  int i, numvarnames;
     1672  GString *str   = g_string_new("");
     1673
     1674  g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE");
     1675  g_string_append_printf(str, "%-20s   %s\n",  "--------", "-----");
    18151676  owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames);
    1816   rem = (buff+PABUFLEN)-pos-1;
    18171677  numvarnames = owl_list_get_size(&varnames);
    18181678  for (i=0; i<numvarnames; i++) {
    18191679    name = owl_list_get_element(&varnames, i);
    18201680    if (name && name[0]!='_') {
    1821       rem = (buff+PABUFLEN)-pos-1;   
    1822       pos += snprintf(pos, rem, "\n%-20s = ", name);
    1823       rem = (buff+PABUFLEN)-pos-1;   
    1824       owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem);
    1825       pos = buff+strlen(buff);
    1826     }
    1827   }
    1828   rem = (buff+PABUFLEN)-pos-1;   
    1829   snprintf(pos, rem, "\n");
     1681      g_string_append_printf(str, "\n%-20s = ", name);
     1682      owl_variable_get_tostring(owl_global_get_vardict(&g), name, var, LINE);
     1683      g_string_append(str, var);
     1684    }
     1685  }
     1686  g_string_append(str, "\n");
    18301687  owl_variable_dict_namelist_free(&varnames);
    1831  
    1832   owl_function_popless_text(buff);
     1688
     1689  owl_function_popless_text(str->str);
     1690  g_string_free(str, TRUE);
    18331691}
    18341692
     
    19221780void owl_function_status()
    19231781{
    1924   char buff[5000];
     1782  char buff[MAXPATHLEN+1];
    19251783  time_t start;
    19261784  int up, days, hours, minutes;
     
    19421800
    19431801  owl_fmtext_append_normal(&fm, "  Current Directory: ");
    1944   (void) getcwd(buff, MAXPATHLEN);
    1945   owl_fmtext_append_normal(&fm, buff);
     1802  if(getcwd(buff, MAXPATHLEN) == NULL) {
     1803    owl_fmtext_append_normal(&fm, "<Error in getcwd>");
     1804  } else {
     1805    owl_fmtext_append_normal(&fm, buff);
     1806  }
    19461807  owl_fmtext_append_normal(&fm, "\n");
    19471808
    1948   sprintf(buff, "  Startup Time: %s", ctime(&start));
    1949   owl_fmtext_append_normal(&fm, buff);
     1809  owl_fmtext_appendf_normal(&fm, "  Startup Time: %s", ctime(&start));
    19501810
    19511811  up=owl_global_get_runtime(&g);
     
    19561816  minutes=up/60;
    19571817  up-=minutes*60;
    1958   sprintf(buff, "  Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up);
    1959   owl_fmtext_append_normal(&fm, buff);
     1818  owl_fmtext_appendf_normal(&fm, "  Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up);
    19601819
    19611820  owl_fmtext_append_normal(&fm, "\nProtocol Options:\n");
     
    20021861{
    20031862  owl_fmtext fm;
    2004   char buff[LINE];
    20051863
    20061864  owl_fmtext_init_null(&fm);
    2007   sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n",
     1865  owl_fmtext_appendf_normal(&fm, "Terminal Lines: %i\nTerminal Columns: %i\n",
    20081866          owl_global_get_lines(&g),
    20091867          owl_global_get_cols(&g));
    2010   owl_fmtext_append_normal(&fm, buff);
    20111868
    20121869  if (owl_global_get_hascolors(&g)) {
    20131870    owl_fmtext_append_normal(&fm, "Color: Yes\n");
    2014     sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
    2015     owl_fmtext_append_normal(&fm, buff);
    2016     sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
    2017     owl_fmtext_append_normal(&fm, buff);
     1871    owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g));
     1872    owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no");
    20181873  } else {
    20191874    owl_fmtext_append_normal(&fm, "Color: No\n");
     
    20521907        return;
    20531908      }
     1909    }
     1910
     1911    /* then check if it's a question and just bring up the command prompt */
     1912    if (owl_message_is_question(m)) {
     1913      owl_function_start_command("");
     1914      return;
    20541915    }
    20551916
     
    24952356  char *tmpclass, *tmpinstance = NULL;
    24962357  char *class, *instance = NULL;
    2497   int len;
    24982358
    24992359  class = owl_util_baseclass(c);
     
    25052365
    25062366  /* name for the filter */
    2507   len=strlen(class)+30;
    2508   if (instance) len+=strlen(instance);
    2509   filtname=owl_malloc(len);
    25102367  if (!instance) {
    2511     sprintf(filtname, "class-%s", class);
    2512   } else {
    2513     sprintf(filtname, "class-%s-instance-%s", class, instance);
     2368    filtname = owl_sprintf("class-%s", class);
     2369  } else {
     2370    filtname = owl_sprintf("class-%s-instance-%s", class, instance);
    25142371  }
    25152372  /* downcase it */
     
    25422399    owl_text_tr(tmpinstance, '"', '.');
    25432400  }
    2544   len = strlen(tmpclass);
    2545   if(tmpinstance) len += strlen(tmpinstance);
    2546   len += 60;
    2547   argbuff = owl_malloc(len);
    2548   sprintf(argbuff, "class ^(un)*%s(\\.d)*$", tmpclass);
     2401
     2402  argbuff = owl_sprintf("class ^(un)*%s(\\.d)*$", tmpclass);
    25492403  if (tmpinstance) {
    2550     sprintf(argbuff, "%s and ( instance ^(un)*%s(\\.d)*$ )", argbuff, tmpinstance);
     2404    char *tmp = argbuff;
     2405    argbuff = owl_sprintf("%s and ( instance ^(un)*%s(\\.d)*$ )", tmp, tmpinstance);
     2406    owl_free(tmp);
    25512407  }
    25522408  owl_free(tmpclass);
     
    25772433{
    25782434  owl_filter *f;
    2579   char *argbuff, *longuser, *shortuser, *filtname;
     2435  char *argbuff, *longuser, *esclonguser, *shortuser, *filtname;
    25802436
    25812437  /* stick the local realm on if it's not there */
     
    25842440
    25852441  /* name for the filter */
    2586   filtname=owl_malloc(strlen(shortuser)+20);
    2587   sprintf(filtname, "user-%s", shortuser);
     2442  filtname=owl_sprintf("user-%s", shortuser);
    25882443
    25892444  /* if it already exists then go with it.  This lets users override */
     
    25952450  f=owl_malloc(sizeof(owl_filter));
    25962451
    2597   argbuff=owl_malloc(strlen(longuser)+1000);
    2598   sprintf(argbuff, "( type ^zephyr$ and filter personal and ");
    2599   sprintf(argbuff, "%s ( ( direction ^in$ and sender ^%s$ ) or ( direction ^out$ and recipient ^%s$ ) ) )", argbuff, longuser, longuser);
    2600   sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) )", argbuff, longuser);
     2452  esclonguser = owl_text_quote(longuser, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
     2453
     2454  argbuff=owl_sprintf("( type ^zephyr$ and filter personal and "
     2455      "( ( direction ^in$ and sender ^%1$s$ ) or ( direction ^out$ and "
     2456      "recipient ^%1$s$ ) ) ) or ( ( class ^login$ ) and ( sender ^%1$s$ ) )",
     2457      esclonguser);
    26012458
    26022459  owl_filter_init_fromstring(f, filtname, argbuff);
     
    26082465  owl_free(argbuff);
    26092466  owl_free(longuser);
     2467  owl_free(esclonguser);
    26102468  owl_free(shortuser);
    26112469
     
    26262484
    26272485  /* name for the filter */
    2628   filtname=owl_malloc(strlen(user)+40);
    2629   sprintf(filtname, "aimuser-%s", user);
     2486  filtname=owl_sprintf("aimuser-%s", user);
    26302487
    26312488  /* if it already exists then go with it.  This lets users override */
     
    26392496  escuser = owl_text_quote(user, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
    26402497
    2641   argbuff=owl_malloc(1000);
    2642   sprintf(argbuff,
    2643           "( type ^aim$ and ( ( sender ^%s$ and recipient ^%s$ ) or ( sender ^%s$ and recipient ^%s$ ) ) )",
    2644           escuser, owl_global_get_aim_screenname_for_filters(&g),
    2645           owl_global_get_aim_screenname_for_filters(&g), escuser);
     2498  argbuff = owl_sprintf(
     2499      "( type ^aim$ and ( ( sender ^%1$s$ and recipient ^%2$s$ ) or "
     2500      "( sender ^%2$s$ and recipient ^%1$s$ ) ) )",
     2501      escuser, owl_global_get_aim_screenname_for_filters(&g));
    26462502
    26472503  owl_filter_init_fromstring(f, filtname, argbuff);
     
    26602516{
    26612517  owl_filter *f;
    2662   char *argbuff, *filtname;
     2518  char *argbuff, *filtname, *esctype;
    26632519
    26642520  /* name for the filter */
     
    26732529  f=owl_malloc(sizeof(owl_filter));
    26742530
    2675   argbuff = owl_sprintf("type ^%s$", type);
     2531  esctype = owl_text_quote(type, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
     2532
     2533  argbuff = owl_sprintf("type ^%s$", esctype);
    26762534
    26772535  owl_filter_init_fromstring(f, filtname, argbuff);
     
    26822540  /* free stuff */
    26832541  owl_free(argbuff);
     2542  owl_free(esctype);
    26842543
    26852544  return filtname;
     
    29432802void owl_function_zpunt(char *class, char *inst, char *recip, int direction)
    29442803{
    2945   char *buff;
     2804  char *puntexpr, *classexpr, *instexpr, *recipexpr;
    29462805  char *quoted;
    29472806
    2948   buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100);
    2949   strcpy(buff, "class");
    29502807  if (!strcmp(class, "*")) {
    2951     strcat(buff, " .*");
     2808    classexpr = owl_sprintf("class .*");
    29522809  } else {
    29532810    quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
     
    29552812    owl_text_tr(quoted, '\'', '.');
    29562813    owl_text_tr(quoted, '"', '.');
    2957     sprintf(buff, "%s ^(un)*%s(\\.d)*$", buff, quoted);
     2814    classexpr = owl_sprintf("class ^(un)*%s(\\.d)*$", quoted);
    29582815    owl_free(quoted);
    29592816  }
    29602817  if (!strcmp(inst, "*")) {
    2961     strcat(buff, " and instance .*");
     2818    instexpr = owl_sprintf(" and instance .*");
    29622819  } else {
    29632820    quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
     
    29652822    owl_text_tr(quoted, '\'', '.');
    29662823    owl_text_tr(quoted, '"', '.');
    2967     sprintf(buff, "%s and instance ^(un)*%s(\\.d)*$", buff, quoted);
     2824    instexpr = owl_sprintf(" and instance ^(un)*%s(\\.d)*$", quoted);
    29682825    owl_free(quoted);
    29692826  }
    2970   if (strcmp(recip, "*")) {
     2827  if (!strcmp(recip, "*")) {
     2828    recipexpr = owl_sprintf("");
     2829  } else {
    29712830    quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
    29722831    owl_text_tr(quoted, ' ', '.');
    29732832    owl_text_tr(quoted, '\'', '.');
    29742833    owl_text_tr(quoted, '"', '.');
    2975     sprintf(buff, "%s and recipient ^%s$", buff, quoted);
     2834    recipexpr = owl_sprintf(" and recipient ^%s$", quoted);
    29762835    owl_free(quoted);
    29772836  }
    29782837
    2979   owl_function_punt(buff, direction);
    2980   owl_free(buff);
     2838  puntexpr = owl_sprintf("%s %s %s", classexpr, instexpr, recipexpr);
     2839  owl_function_punt(puntexpr, direction);
     2840  owl_free(puntexpr);
     2841  owl_free(classexpr);
     2842  owl_free(instexpr);
     2843  owl_free(recipexpr);
    29812844}
    29822845
     
    30652928}
    30662929
    3067 char *owl_function_keymap_summary(void *name)
     2930char *owl_function_keymap_summary(char *name)
    30682931{
    30692932  owl_keymap *km
     
    31953058  owl_buddy *b;
    31963059  owl_list anyone;
    3197   char *foo, *timestr;
     3060  char *timestr;
    31983061#ifdef HAVE_LIBZEPHYR
    3199   char *tmp, *user, *line;
     3062  char *tmp, *user;
    32003063  ZLocations_t location[200];
    32013064  int numlocs, ret;
     
    32193082        timestr=owl_strdup("");
    32203083      }
    3221       foo=owl_sprintf("  %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr);
    3222       owl_fmtext_append_normal(&fm, foo);
     3084      owl_fmtext_appendf_normal(&fm, "  %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr);
    32233085      owl_free(timestr);
    3224       owl_free(foo);
    32253086    }
    32263087  }
     
    32503111          if (ret==0) {
    32513112            for (x=0; x<numlocs; x++) {
    3252               line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);
    32533113              tmp=short_zuser(user);
    3254               sprintf(line, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
    3255                       tmp,
    3256                       location[x].host,
    3257                       location[x].tty,
    3258                       location[x].time);
    3259               owl_fmtext_append_normal(&fm, line);
     3114              owl_fmtext_appendf_normal(&fm, "  %-10.10s %-24.24s %-12.12s  %20.20s\n",
     3115                                        tmp,
     3116                                        location[x].host,
     3117                                        location[x].tty,
     3118                                        location[x].time);
    32603119              owl_free(tmp);
    3261               owl_free(line);
    32623120            }
    32633121            if (numlocs>=200) {
     
    34913349{
    34923350  va_list ap;
    3493   char buff[2048], buff2[2048];
     3351  char *buff, *buff2;
     3352  char *nl;
    34943353  char *date;
    34953354  time_t now;
     
    35013360  va_start(ap, fmt);
    35023361
    3503   vsnprintf(buff, 2048, fmt, ap);
    3504   sprintf(buff2, "%s %s", date, buff);
     3362  buff = g_strdup_vprintf(fmt, ap);
     3363  buff2 = owl_sprintf("%s %s", date, buff);
    35053364  owl_function_debugmsg("ERROR: %s", buff);
    3506   if (owl_global_get_curs_msgwin(&g)) {
    3507     werase(owl_global_get_curs_msgwin(&g));
    3508     waddstr(owl_global_get_curs_msgwin(&g), buff); 
    3509     wnoutrefresh(owl_global_get_curs_msgwin(&g));
    3510     owl_global_set_needrefresh(&g);
     3365  nl = strchr(buff, '\n');
     3366  if(nl && *(nl + 1)) {
     3367    /* Multiline error */
     3368    owl_function_adminmsg("ERROR", buff);
     3369  } else {
     3370    owl_function_makemsg("[Error] %s", buff);
    35113371  }
    35123372  owl_errqueue_append_err(owl_global_get_errqueue(&g), buff2);
    35133373  va_end(ap);
    35143374  owl_free(date);
     3375  owl_free(buff);
     3376  owl_free(buff2);
    35153377}
    35163378
  • global.c

    rda466e0 rf34dd65  
    5151  owl_keys_setup_keymaps(&g->kh);
    5252
    53   owl_list_create(&(g->muxevents));
    5453  owl_list_create(&(g->filterlist));
    5554  owl_list_create(&(g->puntlist));
     
    10099  g->aim_screenname_for_filters=NULL;
    101100  g->aim_loggedin=0;
    102   owl_timer_create_countdown(&(g->aim_noop_timer), 30);
    103   owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
    104   owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
    105101  owl_buddylist_init(&(g->buddylist));
    106    
     102
    107103  g->havezephyr=0;
    108104  g->haveaim=0;
     105  g->ignoreaimlogin=0;
    109106  owl_global_set_no_doaimevents(g);
    110107
     
    113110
    114111  owl_zbuddylist_create(&(g->zbuddies));
    115   owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
    116112
    117113  owl_obarray_init(&(g->obarray));
     
    119115  owl_message_init_fmtext_cache();
    120116  owl_list_create(&(g->dispatchlist));
     117  g->timerlist = NULL;
    121118}
    122119
     
    139136  g->recwin=newwin(g->recwinlines, cols, 0, 0);
    140137  if (g->recwin==NULL) {
    141     owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n", g->recwinlines, cols);
     138    owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n");
    142139    endwin();
    143140    exit(50);
     
    570567  strcpy(g->startupargs, "");
    571568  for (i=0; i<argc; i++) {
    572     sprintf(g->startupargs, "%s%s ", g->startupargs, argv[i]);
     569    sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]);
    573570  }
    574571  g->startupargs[strlen(g->startupargs)-1]='\0';
     
    588585owl_history *owl_global_get_cmd_history(owl_global *g) {
    589586  return(&(g->cmdhist));
    590 }
    591 
    592 /* muxevents */
    593 
    594 owl_muxevents *owl_global_get_muxevents(owl_global *g) {
    595   return(&(g->muxevents));
    596587}
    597588
     
    719710int owl_global_get_newmsgproc_pid(owl_global *g) {
    720711  return(g->newmsgproc_pid);
    721 }
    722 
    723 void owl_global_add_to_malloced(owl_global *g, int i) {
    724   g->malloced+=i;
    725 }
    726 
    727 void owl_global_add_to_freed(owl_global *g, int i) {
    728   g->freed+=1;
    729 }
    730 
    731 int owl_global_get_malloced(owl_global *g) {
    732   return(g->malloced);
    733 }
    734 
    735 int owl_global_get_freed(owl_global *g) {
    736   return(g->freed);
    737 }
    738 
    739 int owl_global_get_meminuse(owl_global *g) {
    740   return(g->malloced-g->freed);
    741712}
    742713
     
    812783{
    813784  g->bosconn=*conn;
    814 }
    815 
    816 int owl_global_is_aimnop_time(owl_global *g)
    817 {
    818   if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
    819   return(0);
    820 }
    821 
    822 void owl_global_aimnop_sent(owl_global *g)
    823 {
    824   owl_timer_reset(&(g->aim_noop_timer));
    825 }
    826 
    827 owl_timer *owl_global_get_aim_login_timer(owl_global *g)
    828 {
    829   return(&(g->aim_ignorelogin_timer));
    830785}
    831786
     
    902857}
    903858
     859void owl_global_set_ignore_aimlogin(owl_global *g)
     860{
     861    g->ignoreaimlogin = 1;
     862}
     863
     864void owl_global_unset_ignore_aimlogin(owl_global *g)
     865{
     866    g->ignoreaimlogin = 0;
     867}
     868
     869int owl_global_is_ignore_aimlogin(owl_global *g)
     870{
     871    return g->ignoreaimlogin;
     872}
     873
    904874void owl_global_set_havezephyr(owl_global *g)
    905875{
     
    911881  if (g->havezephyr) return(1);
    912882  return(0);
    913 }
    914 
    915 owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
    916 {
    917   return(&(g->aim_buddyinfo_timer));
    918883}
    919884
     
    944909}
    945910
    946 owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
    947 {
    948   return(&(g->zephyr_buddycheck_timer));
    949 }
    950911
    951912owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
     
    968929  return &(g->dispatchlist);
    969930}
     931
     932GList **owl_global_get_timerlist(owl_global *g)
     933{
     934  return &(g->timerlist);
     935}
  • help.c

    r0398d55 r799b60e  
    1818  owl_fmtext_append_normal
    1919    (&fm,
     20     "  If you're new to BarnOwl, the first thing you should type is\n\n"
     21     "    :show quickstart\n\n"
    2022     "  For help on a specific command use 'help <command>'\n"
    2123     "  For information on advanced keys, use 'show keymaps'.\n"
  • keys.c

    r3004c9f rce56149  
    5050
    5151  BIND_CMD("LEFT",        "edit:move-left", "");
     52  BIND_CMD("M-[ D",       "edit:move-left", "");
    5253  BIND_CMD("C-b",         "edit:move-left", "");
    5354  BIND_CMD("RIGHT",       "edit:move-right", "");
     55  BIND_CMD("M-[ C",       "edit:move-right", "");
    5456  BIND_CMD("C-f",         "edit:move-right", "");
    5557
     
    6567  BIND_CMD("M-DELETE",    "edit:delete-prev-word", "");
    6668  BIND_CMD("M-d",         "edit:delete-next-word", "");
     69  BIND_CMD("M-DC",        "edit:delete-next-word", "");
    6770  BIND_CMD("M-[ 3 ; 3 ~", "edit:delete-next-word", "");
    6871
    6972  BIND_CMD("C-h",         "edit:delete-prev-char", "");
    7073  BIND_CMD("BACKSPACE",   "edit:delete-prev-char", "");
    71   BIND_CMD("DC",          "edit:delete-prev-char", "");
    7274  BIND_CMD("DELETE",      "edit:delete-prev-char", "");
     75  BIND_CMD("C-d",         "edit:delete-next-char", "");
     76  BIND_CMD("DC",          "edit:delete-next-char", "");
    7377
    7478  BIND_CMD("C-k",         "edit:delete-to-line-end", "");
     
    7983
    8084  BIND_CMD("C-l",         "( edit:recenter ; redisplay )", "");
    81 
    82   BIND_CMD("C-d",     "edit:delete-next-char", "");
    8385
    8486
     
    9395
    9496  BIND_CMD("UP",      "editmulti:move-up-line", "");
     97  BIND_CMD("M-[ A",   "editmulti:move-up-line", "");
    9598  BIND_CMD("C-p",     "editmulti:move-up-line", "");
    9699  BIND_CMD("DOWN",    "editmulti:move-down-line", "");
     100  BIND_CMD("M-[ B",   "editmulti:move-down-line", "");
    97101  BIND_CMD("C-n",     "editmulti:move-down-line", "");
    98102
     
    120124
    121125  BIND_CMD("UP",          "edit:history-prev", "");
     126  BIND_CMD("M-[ A",       "edit:history-prev", "");
    122127  BIND_CMD("C-p",         "edit:history-prev", "");
    123128  BIND_CMD("M-p",         "edit:history-prev", "");
    124129
    125130  BIND_CMD("DOWN",        "edit:history-next", "");
     131  BIND_CMD("M-[ B",       "edit:history-next", "");
    126132  BIND_CMD("C-n",         "edit:history-next", "");
    127133  BIND_CMD("M-n",         "edit:history-next", "");
     
    166172  BIND_CMD("LF",          "popless:scroll-down-line", "");
    167173  BIND_CMD("DOWN",        "popless:scroll-down-line", "");
     174  BIND_CMD("M-[ B",       "popless:scroll-down-line", "");
    168175  BIND_CMD("C-n",         "popless:scroll-down-line", "");
    169176
    170177  BIND_CMD("UP",          "popless:scroll-up-line", "");
     178  BIND_CMD("M-[ A",       "popless:scroll-up-line", "");
    171179  BIND_CMD("C-h",         "popless:scroll-up-line", "");
    172180  BIND_CMD("C-p",         "popless:scroll-up-line", "");
     
    176184
    177185  BIND_CMD("RIGHT",       "popless:scroll-right 10", "scrolls right");
     186  BIND_CMD("M-[ C",       "popless:scroll-right 10", "scrolls right");
    178187  BIND_CMD("LEFT",        "popless:scroll-left  10", "scrolls left");
     188  BIND_CMD("M-[ D",       "popless:scroll-left  10", "scrolls left");
    179189
    180190  BIND_CMD("HOME",        "popless:scroll-to-top", "");
     
    232242  BIND_CMD("M-[ D",  "recv:shiftleft", "");
    233243  BIND_CMD("RIGHT",  "recv:shiftright","");
    234   BIND_CMD("M-[ C",  "recv:shiftleft", "");
     244  BIND_CMD("M-[ C",  "recv:shiftright","");
    235245  BIND_CMD("DOWN",   "recv:next",      "");
    236246  BIND_CMD("C-n",    "recv:next",      "");
     
    282292  BIND_CMD("M-r", "reply -e",         "reply to the current message, but allow editing of recipient");
    283293  BIND_CMD("M-R", "reply -e sender",  "reply to sender of the current message, but allow editing of recipient");
    284                  
    285   BIND_CMD("w",   "openurl",          "open a URL using a webbrowser");
    286294
    287295  BIND_CMD("W",   "start-command webzephyr ", "start a webzephyr command");
  • list.c

    r50622a5 rf34dd65  
    7878}
    7979
    80 /* todo: might leak memory */
    81 int owl_list_replace_element(owl_list *l, int n, void *element)
    82 {
    83   if (n>l->size-1) return(-1);
    84 
    85   l->list[n]=element;
    86   return(0);
    87 }
    88 
    8980void owl_list_free_all(owl_list *l, void (*elefree)(void *))
    9081{
  • message.c

    r147d880 rf34dd65  
    338338}
    339339
    340 /* caller must free the return */
    341 char *owl_message_get_shorttimestr(owl_message *m)
    342 {
    343   struct tm *tmstruct;
    344   char *out;
    345 
    346   tmstruct=localtime(&(m->time));
    347   out=owl_sprintf("%2.2i:%2.2i", tmstruct->tm_hour, tmstruct->tm_min);
    348   if (out) return(out);
    349   return("??:??");
    350 }
    351 
    352340void owl_message_set_type_admin(owl_message *m)
    353341{
     
    384372{
    385373  return owl_message_is_type(m, "admin");
    386 }
    387 
    388 int owl_message_is_type_generic(owl_message *m)
    389 {
    390   char * t = owl_message_get_attribute_value(m, "type");
    391   return (t == NULL);
    392374}
    393375
     
    573555}
    574556
    575 int owl_message_is_from_me(owl_message *m)
    576 {
    577   if (owl_message_is_type_zephyr(m)) {
    578     if (!strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {
    579       return(1);
    580     } else {
    581       return(0);
    582     }
    583   } else if (owl_message_is_type_aim(m)) {
    584     if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {
    585       return(1);
    586     } else {
    587       return(0);
    588     }
    589   } else if (owl_message_is_type_admin(m)) {
    590     return(0);
    591   }
    592   return(0);
    593 }
    594 
    595557int owl_message_is_mail(owl_message *m)
    596558{
    597559  if (owl_message_is_type_zephyr(m)) {
    598560    if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
    599       return(1);
    600     } else {
    601       return(0);
    602     }
    603   }
    604   return(0);
    605 }
    606 
    607 int owl_message_is_ping(owl_message *m)
    608 {
    609   if (owl_message_is_type_zephyr(m)) {
    610     if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
    611561      return(1);
    612562    } else {
     
    964914  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
    965915  if (owl_zwrite_get_numrecips(&z)>0) {
     916    char *longzuser = long_zuser(owl_zwrite_get_recip_n(&z, 0));
    966917    owl_message_set_recipient(m,
    967                               long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */
     918                              longzuser); /* only gets the first user, must fix */
     919    owl_free(longzuser);
    968920  }
    969921  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
     
    990942}
    991943
    992 void owl_message_pretty_zsig(owl_message *m, char *buff)
    993 {
    994   /* stick a one line version of the zsig in buff */
    995   char *ptr;
    996 
    997   strcpy(buff, owl_message_get_zsig(m));
    998   ptr=strchr(buff, '\n');
    999   if (ptr) ptr[0]='\0';
    1000 }
    1001 
    1002944void owl_message_free(owl_message *m)
    1003945{
  • owl.c

    rc1d2e6c r28fa23c  
    4646  int newmsgs, nexttimediff;
    4747  struct sigaction sigact;
    48   char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
     48  char *configfile, *tty, *perlout, *perlerr, **argvsave;
    4949  char *confdir;
    5050  owl_filter *f;
     
    5555  struct termios tio;
    5656  owl_message *m;
    57 #if OWL_STDERR_REDIR
    58   int newstderr;
    59 #endif
    60  
     57
    6158  if (!GLIB_CHECK_VERSION (2, 12, 0))
    6259    g_error ("GLib version 2.12.0 or above is needed.");
     
    191188    d->fd = STDIN;
    192189    d->cfunc = &owl_process_input;
    193     d->pfunc = NULL;
     190    d->destroy = NULL;
    194191    owl_select_add_dispatch(d);
    195192  }
     
    202199    d->fd = ZGetFD();
    203200    d->cfunc = &owl_zephyr_process_events;
    204     d->pfunc = NULL;
     201    d->destroy = NULL;
    205202    owl_select_add_dispatch(d);
    206203    owl_global_set_havezephyr(&g);
     
    211208#if OWL_STDERR_REDIR
    212209  /* Do this only after we've started curses up... */
    213   owl_function_debugmsg("startup: doing stderr redirection");
    214   newstderr = stderr_replace();
    215   owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ,
    216                     stderr_redirect_handler, NULL);
    217 #endif   
     210  {
     211    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     212    owl_function_debugmsg("startup: doing stderr redirection");
     213    d->fd = stderr_replace();
     214    d->cfunc = stderr_redirect_handler;
     215    d->destroy = NULL;
     216    owl_select_add_dispatch(d);
     217  }
     218#endif
    218219
    219220  /* create the owl directory, in case it does not exist */
     
    320321  /* welcome message */
    321322  owl_function_debugmsg("startup: creating splash message");
    322   strcpy(startupmsg, "-----------------------------------------------------------------------\n");
    323   sprintf(buff,      "Welcome to barnowl version %s.  Press 'h' for on-line help.            \n", OWL_VERSION_STRING);
    324   strcat(startupmsg, buff);
    325   strcat(startupmsg, "                                                                       \n");
    326   strcat(startupmsg, "BarnOwl is free software. Type ':show license' for more                \n");
    327   strcat(startupmsg, "information.                                                           \n");
    328   strcat(startupmsg, "                                                                 ^ ^   \n");
    329   strcat(startupmsg, "                                                                 OvO   \n");
    330   strcat(startupmsg, "Please report any bugs or suggestions to bug-barnowl@mit.edu    (   )  \n");
    331   strcat(startupmsg, "-----------------------------------------------------------------m-m---\n");
    332   owl_function_adminmsg("", startupmsg);
     323  owl_function_adminmsg("",
     324    "-----------------------------------------------------------------------\n"
     325    "Welcome to barnowl version " OWL_VERSION_STRING ".  Press 'h' for on-line help.\n"
     326    "To see a quick introduction, type ':show quickstart'.                  \n"
     327    "                                                                       \n"
     328    "BarnOwl is free software. Type ':show license' for more                \n"
     329    "information.                                                     ^ ^   \n"
     330    "                                                                 OvO   \n"
     331    "Please report any bugs or suggestions to bug-barnowl@mit.edu    (   )  \n"
     332    "-----------------------------------------------------------------m-m---\n"
     333  );
    333334  sepbar(NULL);
    334335
     
    395396  nexttime=time(NULL);
    396397
    397 #ifdef HAVE_LIBZEPHYR
    398   /* Check for any zephyrs that have come in while we've done init. */
    399   owl_zephyr_process_events();
    400 #endif
    401  
     398
     399  owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
     400
     401  /* If we ever deprecate the mainloop hook, remove this. */
     402  owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL, NULL);
     403
     404
    402405  owl_function_debugmsg("startup: entering main loop");
    403406  /* main loop */
     
    414417
    415418    followlast=owl_global_should_followlast(&g);
    416    
    417     owl_perlconfig_mainloop();
    418419
    419420    /* little hack */
     
    442443    }
    443444
    444     /* is it time to check zbuddies? */
    445     if (owl_global_is_pseudologins(&g)) {
    446       if (owl_timer_is_expired(owl_global_get_zephyr_buddycheck_timer(&g))) {
    447         owl_function_debugmsg("Doing zephyr buddy check");
    448         owl_function_zephyr_buddy_check(1);
    449         owl_timer_reset(owl_global_get_zephyr_buddycheck_timer(&g));
    450       }
    451     }
    452 
    453     /* dispatch any muxevents */
    454     owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0);
    455 
    456445    /* follow the last message if we're supposed to */
    457446    if (newmsgs && followlast) {
     
    511500      int signum;
    512501      if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) {
    513         owl_function_error("Got unexpected signal: %d %s  (code: %d band: %d  errno: %d)",
     502        owl_function_error("Got unexpected signal: %d %s  (code: %d band: %ld  errno: %d)",
    514503                           signum, signum==SIGPIPE?"SIGPIPE":"SIG????",
    515504                           si.si_code, si.si_band, si.si_errno);
     
    614603}
    615604
    616 void owl_process_aim()
    617 {
    618   if (owl_global_is_doaimevents(&g)) {
    619     owl_aim_process_events();
    620    
    621     if (owl_global_is_aimloggedin(&g)) {
    622       if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
    623         /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
    624         owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
    625       }
    626     }
    627   }
    628 }
    629 
    630 void owl_process_input()
     605void owl_process_input(owl_dispatch *d)
    631606{
    632607  int ret;
     
    773748
    774749/* Sends stderr (read from rfd) messages to the error console */
    775 void stderr_redirect_handler(int handle, int rfd, int eventmask, void *data)
     750void stderr_redirect_handler(owl_dispatch *d)
    776751{
    777752  int navail, bread;
    778   char *buf;
    779   /*owl_function_debugmsg("stderr_redirect: called with rfd=%d\n", rfd);*/
     753  char buf[4096];
     754  int rfd = d->fd;
    780755  if (rfd<0) return;
    781756  if (-1 == ioctl(rfd, FIONREAD, (void*)&navail)) {
     
    783758  }
    784759  /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/
    785   if (navail<=0) return;
    786   if (navail>256) { navail = 256; }
    787   buf = owl_malloc(navail+1);
     760  if (navail <= 0) return;
     761  if (navail > sizeof(buf)-1) {
     762    navail = sizeof(buf)-1;
     763  }
    788764  bread = read(rfd, buf, navail);
    789765  if (buf[navail-1] != '\0') {
    790766    buf[navail] = '\0';
    791767  }
    792   owl_function_error("Err: %s", buf);
    793   owl_free(buf);
     768  owl_function_error("[stderr]\n%s", buf);
    794769}
    795770
    796771#endif /* OWL_STDERR_REDIR */
     772
     773void owl_zephyr_buddycheck_timer(owl_timer *t, void *data)
     774{
     775  if (owl_global_is_pseudologins(&g)) {
     776    owl_function_debugmsg("Doing zephyr buddy check");
     777    owl_function_zephyr_buddy_check(1);
     778  }
     779}
  • owl.h

    r43a306c rf34dd65  
    320320
    321321typedef struct _owl_pair {
    322   void *key;
    323   void *value;
     322  char *key;
     323  char *value;
    324324} owl_pair;
    325325
     
    377377  int active;
    378378  int needsfirstrefresh;
    379   void (*handler) (int ch);
    380379} owl_popwin;
    381 
    382 typedef struct _owl_popexec {
    383   int refcount;
    384   owl_viewwin *vwin;
    385   int winactive;
    386   int pid;                      /* or 0 if it has terminated */
    387   int rfd; 
    388 } owl_popexec;
    389380
    390381typedef struct _owl_messagelist {
     
    412403typedef struct _owl_filter {
    413404  char *name;
    414   int polarity;
    415405  owl_filterelement * root;
    416406  int fgcolor;
     
    453443} owl_editwin;
    454444
    455 typedef struct _owl_mux {
    456   int handle;                   /* for referencing this */
    457   int active;                   /* has this been deleted? */
    458   int fd;                     
    459   int eventmask;                /* bitmask of OWL_MUX_* */
    460   void (*handler_fn)(int handle, int fd, int eventmask, void *data);
    461   void *data;                   /* data reference to pass to callback */
    462 } owl_mux;
    463 typedef owl_list owl_muxevents;
    464 
    465445typedef struct _owl_keybinding {
    466446  int  *j;                      /* keypress stack (0-terminated) */ 
     
    505485
    506486typedef struct _owl_timer {
    507   int direction;
    508   time_t starttime;
    509   int start;
     487  time_t time;
     488  int interval;
     489  void (*callback)(struct _owl_timer *, void *);
     490  void (*destroy)(struct _owl_timer *);
     491  void *data;
    510492} owl_timer;
    511493
     
    524506
    525507typedef struct _owl_dispatch {
    526   int fd;           /* FD to watch for dispatch. */
    527   void (*cfunc)();  /* C function to dispatch to. */
    528   SV *pfunc;        /* Perl function to dispatch to. */
     508  int fd;                                 /* FD to watch for dispatch. */
     509  int needs_gc;
     510  void (*cfunc)(struct _owl_dispatch*);   /* C function to dispatch to. */
     511  void (*destroy)(struct _owl_dispatch*); /* Destructor */
     512  void *data;
    529513} owl_dispatch;
     514
     515typedef struct _owl_popexec {
     516  int refcount;
     517  owl_viewwin *vwin;
     518  int winactive;
     519  int pid;                      /* or 0 if it has terminated */
     520  owl_dispatch dispatch;
     521} owl_popexec;
    530522
    531523typedef struct _owl_global {
     
    537529  owl_list filterlist;
    538530  owl_list puntlist;
    539   owl_muxevents muxevents;      /* fds to dispatch on */
    540531  owl_vardict vars;
    541532  owl_cmddict cmds;
     
    583574  owl_timer aim_noop_timer;
    584575  owl_timer aim_ignorelogin_timer;
    585   owl_timer aim_buddyinfo_timer;
    586576  int aim_loggedin;         /* true if currently logged into AIM */
    587577  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
     
    594584  int havezephyr;
    595585  int haveaim;
     586  int ignoreaimlogin;
    596587  int got_err_signal;       /* 1 if we got an unexpected signal */
    597588  siginfo_t err_signal_info;
     
    601592  owl_obarray obarray;
    602593  owl_list dispatchlist;
     594  GList *timerlist;
     595  owl_timer *aim_nop_timer;
    603596} owl_global;
    604597
  • pair.c

    r160ea47 rde1c8a5  
    11#include "owl.h"
    22
    3 void owl_pair_create(owl_pair *p, void *key, void *value) {
     3void owl_pair_create(owl_pair *p, char *key, char *value) {
    44  p->key=key;
    55  p->value=value;
    66}
    77
    8 void owl_pair_set_key(owl_pair *p, void *key) {
     8void owl_pair_set_key(owl_pair *p, char *key) {
    99  p->key=key;
    1010}
    1111
    12 void owl_pair_set_value(owl_pair *p, void *value) {
     12void owl_pair_set_value(owl_pair *p, char *value) {
    1313  p->value=value;
    1414}
    1515
    16 void *owl_pair_get_key(owl_pair *p) {
     16char *owl_pair_get_key(owl_pair *p) {
    1717  return(p->key);
    1818}
    1919
    20 void *owl_pair_get_value(owl_pair *p) {
     20char *owl_pair_get_value(owl_pair *p) {
    2121  return(p->value);
    2222}
  • perl/modules/IRC/lib/BarnOwl/Message/IRC.pm

    r38a7f22 rf79d6a2  
    3333        @filter  =
    3434             (qw{( type ^irc$ and filter personal and },
    35               qw{( ( direction ^in$ and sender}, "^$who\$",
    36               qw{ ) or ( direction ^out$ and recipient}, "^$who\$",
     35              qw{( ( direction ^in$ and sender}, "^\Q$who\E\$",
     36              qw{ ) or ( direction ^out$ and recipient}, "^\Q$who\E\$",
    3737              qw{) ) ) });
    3838        BarnOwl::command("filter", "$filter", @filter);
     
    4747            $filter = "irc-$network-channel-$channel-$sender-$1";
    4848            @filter =
    49                  (qw{type ^irc$ and network}, "^$network\$",
    50                   qw{and channel}, "^$channel\$",
    51                   qw{and ( sender}, "^$sender\$",
    52                   qw{or sender}, "^$1\$",qq{)});
     49                 (qw{type ^irc$ and network}, "^\Q$network\E\$",
     50                  qw{and channel}, "^\Q$channel\E\$",
     51                  qw{and ( sender}, "^\Q$sender\E\$",
     52                  qw{or sender}, "^\Q$1\E\$",qq{)});
    5353        } else {
    5454            $filter = "irc-$network-channel-$channel";
    55             @filter = (qw{type ^irc$ and network}, "^$network\$",
    56                        qw{and channel}, "^$channel\$");
     55            @filter = (qw{type ^irc$ and network}, "^\Q$network\E\$",
     56                       qw{and channel}, "^\Q$channel\E\$");
    5757        }
    5858        BarnOwl::command("filter", "$filter", @filter);
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    r167044b r56d0189  
    214214    if ($body =~ /^\/me (.*)/) {
    215215        $conn->conn->me($to, $1);
    216         $body = BarnOwl::Style::boldify($conn->nick.' '.$1);
     216        $body = '* '.$conn->nick.' '.$1;
    217217    } else {
    218218        $conn->conn->privmsg($to, $body);
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r4789b17 r3048f1f  
    107107    my $nick = $self->nick;
    108108    BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/;
    109     $body = BarnOwl::Style::boldify($evt->nick.' '.$body) if $evt->type eq 'caction';
     109    $body = '* '.$evt->nick.' '.$body if $evt->type eq 'caction';
    110110    my $msg = $self->new_message($evt,
    111111        direction   => 'in',
  • perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm

    r96134cb r9375f8c  
    7070        $filter = "jabber-room-$room";
    7171        BarnOwl::command(qw[filter], $filter,
    72                          qw[type ^jabber$ and room], "^$room\$");
     72                         qw[type ^jabber$ and room], "^\Q$room\E\$");
    7373        return $filter;
    7474    } elsif ($self->login ne 'none') {
     
    8484    my $filter = "jabber-user-$user";
    8585    BarnOwl::command(qw[filter], $filter, qw[type ^jabber$],
    86                      qw[and ( ( direction ^in$ and from], "^$user",
    87                      qw[) or ( direction ^out$ and to ], "^$user",
     86                     qw[and ( ( direction ^in$ and from], "^\Q$user\E(/.*)?\$",
     87                     qw[) or ( direction ^out$ and to ], "^\Q$user\E(/.*)?\$",
    8888                     qw[ ) ) ]);
    8989    return $filter;
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    re979da9 rb73ce70  
    7070        $BarnOwl::Hooks::mainLoop->add("BarnOwl::Module::Jabber::onMainLoop");
    7171        $BarnOwl::Hooks::getBuddyList->add("BarnOwl::Module::Jabber::onGetBuddyList");
     72        $BarnOwl::Hooks::getQuickstart->add("BarnOwl::Module::Jabber::onGetQuickstart");
    7273        $vars{show} = '';
    7374        BarnOwl::new_variable_bool("jabber:show_offline_buddies",
     
    222223}
    223224
     225sub onGetQuickstart {
     226    return <<'EOF'
     227@b(Jabber:)
     228Type ':jabberlogin @b(username@mit.edu)' to log in to Jabber. The command
     229':jroster sub @b(somebody@gmail.com)' will request that they let you message
     230them. Once you get a message saying you are subscribed, you can message
     231them by typing ':jwrite @b(somebody@gmail.com)' or just 'j @b(somebody)'.
     232EOF
     233}
     234
    224235################################################################################
    225236### Owl Commands
     
    435446
    436447sub cmd_logout {
     448    return "You are not logged into jabber." unless ($conn->connected() > 0);
    437449    # Logged into multiple accounts
    438450    if ( $conn->connected() > 1 ) {
     
    11121124sub process_presence_subscribed {
    11131125    my ( $sid, $p ) = @_;
    1114     queue_admin_msg("ignoring:".$p->GetXML());
     1126    queue_admin_msg("ignoring:".$p->GetXML()) if BarnOwl::getvar('jabber:spew') eq 'on';
    11151127    # RFC 3921 says we should respond to this with a "subscribe"
    11161128    # but this causes a flood of sub/sub'd presence packets with
     
    11221134sub process_presence_unsubscribed {
    11231135    my ( $sid, $p ) = @_;
    1124     queue_admin_msg("ignoring:".$p->GetXML());
     1136    queue_admin_msg("ignoring:".$p->GetXML()) if BarnOwl::getvar('jabber:spew') eq 'on';
    11251137    # RFC 3921 says we should respond to this with a "subscribe"
    11261138    # but this causes a flood of unsub/unsub'd presence packets with
  • perlconfig.c

    rc1d2e6c re8c6d8f  
    4444  h = newHV();
    4545
    46 #define MSG2H(h,field) hv_store(h, #field, strlen(#field), \
    47                               newSVpv(owl_message_get_##field(m),0), 0)
     46#define MSG2H(h,field) (void)hv_store(h, #field, strlen(#field),        \
     47                                      newSVpv(owl_message_get_##field(m),0), 0)
    4848
    4949  if (owl_message_is_type_zephyr(m)
     
    5959      owl_free(ptr);
    6060    }
    61     hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0);
    62 
    63     hv_store(h, "auth", strlen("auth"),
    64              newSVpv(owl_zephyr_get_authstr(owl_message_get_notice(m)),0),0);
     61    (void)hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0);
     62
     63    (void)hv_store(h, "auth", strlen("auth"),
     64                   newSVpv(owl_zephyr_get_authstr(owl_message_get_notice(m)),0),0);
    6565  }
    6666
     
    6868  for(i=0; i<j; i++) {
    6969    pair=owl_list_get_element(&(m->attributes), i);
    70     hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)),
    71              newSVpv(owl_pair_get_value(pair),0),0);
     70    (void)hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)),
     71                   newSVpv(owl_pair_get_value(pair),0),0);
    7272  }
    7373 
     
    8888    MSG2H(h, header);
    8989  }
    90   hv_store(h, "time", strlen("time"), newSVpv(owl_message_get_timestr(m),0),0);
    91   hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);
    92   hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0);
    93   hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
    94   hv_store(h, "should_wordwrap",
    95            strlen("should_wordwrap"), newSViv(
    96                                               owl_filter_message_match(wrap, m)),0);
     90  (void)hv_store(h, "time", strlen("time"), newSVpv(owl_message_get_timestr(m),0),0);
     91  (void)hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);
     92  (void)hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0);
     93  (void)hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);
     94  (void)hv_store(h, "should_wordwrap",
     95                 strlen("should_wordwrap"), newSViv(
     96                                                    owl_filter_message_match(wrap, m)),0);
    9797
    9898  type = owl_message_get_type(m);
     
    102102  blessas = owl_sprintf("BarnOwl::Message::%s", type);
    103103
    104   hr = sv_2mortal(newRV_noinc((SV*)h));
     104  hr = newRV_noinc((SV*)h);
    105105  stash =  gv_stashpv(blessas,0);
    106106  if(!stash) {
     
    182182  dSP ;
    183183  int count;
    184   unsigned int len;
    185184  SV *msgref, *srv;
    186   char *out, *preout;
     185  char *out;
    187186 
    188187  ENTER ;
     
    191190  PUSHMARK(SP) ;
    192191  msgref = owl_perlconfig_message2hashref(m);
    193   XPUSHs(msgref);
     192  XPUSHs(sv_2mortal(msgref));
    194193  PUTBACK ;
    195194 
     
    199198
    200199  if (SvTRUE(ERRSV)) {
    201     STRLEN n_a;
    202     owl_function_error("Perl Error: '%s'", SvPV(ERRSV, n_a));
     200    owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV));
    203201    /* and clear the error */
    204202    sv_setsv (ERRSV, &PL_sv_undef);
     
    213211
    214212  if (srv) {
    215     preout=SvPV(srv, len);
    216     out = owl_malloc(strlen(preout)+1);
    217     strncpy(out, preout, len);
    218     out[len] = '\0';
     213    out = owl_strdup(SvPV_nolen(srv));
    219214  } else {
    220215    out = NULL;
     
    235230{
    236231  dSP;
    237   unsigned int count, len, i;
     232  unsigned int count, i;
    238233  SV *msgref, *srv;
    239   char *out, *preout;
     234  char *out;
    240235
    241236  msgref = owl_perlconfig_message2hashref(m);
     
    245240
    246241  PUSHMARK(SP);
    247   XPUSHs(msgref);
     242  XPUSHs(sv_2mortal(msgref));
    248243  for(i=0;i<argc;i++) {
    249244    XPUSHs(sv_2mortal(newSVpv(argv[i], 0)));
     
    261256
    262257  if (SvTRUE(ERRSV)) {
    263     STRLEN n_a;
    264     owl_function_error("Error: '%s'", SvPV(ERRSV, n_a));
     258    owl_function_error("Error: '%s'", SvPV_nolen(ERRSV));
    265259    /* and clear the error */
    266260    sv_setsv (ERRSV, &PL_sv_undef);
     
    270264
    271265  if (srv) {
    272     preout=SvPV(srv, len);
    273     out = owl_malloc(strlen(preout)+1);
    274     strncpy(out, preout, len);
    275     out[len] = '\0';
     266    out = owl_strdup(SvPV_nolen(srv));
    276267  } else {
    277268    out = NULL;
     
    301292  owl_global_set_no_have_config(&g);
    302293
    303 
    304294  ret=perl_parse(p, owl_perl_xs_init, 2, args, NULL);
    305295  if (ret || SvTRUE(ERRSV)) {
    306     STRLEN n_a;
    307     err=owl_strdup(SvPV(ERRSV, n_a));
     296    err=owl_strdup(SvPV_nolen(ERRSV));
    308297    sv_setsv(ERRSV, &PL_sv_undef);     /* and clear the error */
    309298    return(err);
     
    312301  ret=perl_run(p);
    313302  if (ret || SvTRUE(ERRSV)) {
    314     STRLEN n_a;
    315     err=owl_strdup(SvPV(ERRSV, n_a));
     303    err=owl_strdup(SvPV_nolen(ERRSV));
    316304    sv_setsv(ERRSV, &PL_sv_undef);     /* and clear the error */
    317305    return(err);
     
    321309
    322310  /* create legacy variables */
    323   perl_get_sv("BarnOwl::id", TRUE);
    324   perl_get_sv("BarnOwl::class", TRUE);
    325   perl_get_sv("BarnOwl::instance", TRUE);
    326   perl_get_sv("BarnOwl::recipient", TRUE);
    327   perl_get_sv("BarnOwl::sender", TRUE);
    328   perl_get_sv("BarnOwl::realm", TRUE);
    329   perl_get_sv("BarnOwl::opcode", TRUE);
    330   perl_get_sv("BarnOwl::zsig", TRUE);
    331   perl_get_sv("BarnOwl::msg", TRUE);
    332   perl_get_sv("BarnOwl::time", TRUE);
    333   perl_get_sv("BarnOwl::host", TRUE);
    334   perl_get_av("BarnOwl::fields", TRUE);
     311  get_sv("BarnOwl::id", TRUE);
     312  get_sv("BarnOwl::class", TRUE);
     313  get_sv("BarnOwl::instance", TRUE);
     314  get_sv("BarnOwl::recipient", TRUE);
     315  get_sv("BarnOwl::sender", TRUE);
     316  get_sv("BarnOwl::realm", TRUE);
     317  get_sv("BarnOwl::opcode", TRUE);
     318  get_sv("BarnOwl::zsig", TRUE);
     319  get_sv("BarnOwl::msg", TRUE);
     320  get_sv("BarnOwl::time", TRUE);
     321  get_sv("BarnOwl::host", TRUE);
     322  get_av("BarnOwl::fields", TRUE);
    335323
    336324  if(file) {
     
    339327  }
    340328
    341   perl_eval_pv(owl_perlwrap_codebuff, FALSE);
     329  eval_pv(owl_perlwrap_codebuff, FALSE);
    342330
    343331  if (SvTRUE(ERRSV)) {
    344     STRLEN n_a;
    345     err=owl_strdup(SvPV(ERRSV, n_a));
     332    err=owl_strdup(SvPV_nolen(ERRSV));
    346333    sv_setsv (ERRSV, &PL_sv_undef);     /* and clear the error */
    347334    return(err);
     
    358345/* returns whether or not a function exists */
    359346int owl_perlconfig_is_function(char *fn) {
    360   if (perl_get_cv(fn, FALSE)) return(1);
     347  if (get_cv(fn, FALSE)) return(1);
    361348  else return(0);
    362 }
    363 
    364 /* returns 0 on success */
    365 int owl_perlconfig_get_hashkeys(char *hashname, owl_list *l)
    366 {
    367   HV *hv;
    368   HE *he;
    369   char *key;
    370   I32 i;
    371 
    372   if (owl_list_create(l)) return(-1);
    373   hv = get_hv(hashname, FALSE);
    374   if (!hv) return(-1);
    375   i = hv_iterinit(hv);
    376   while ((he = hv_iternext(hv))) {
    377     key = hv_iterkey(he, &i);
    378     if (key) {
    379       owl_list_append_element(l, owl_strdup(key));
    380     }
    381   }
    382   return(0);
    383349}
    384350
     
    392358  if (!owl_global_have_config(&g)) return NULL;
    393359
     360  ENTER;
     361  SAVETMPS;
    394362  /* execute the subroutine */
    395   response = perl_eval_pv(line, FALSE);
     363  response = eval_pv(line, FALSE);
    396364
    397365  if (SvTRUE(ERRSV)) {
    398     STRLEN n_a;
    399     owl_function_error("Perl Error: '%s'", SvPV(ERRSV, n_a));
     366    owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV));
    400367    sv_setsv (ERRSV, &PL_sv_undef);     /* and clear the error */
    401368  }
    402369
    403370  preout=SvPV(response, len);
    404   /* leave enough space in case we have to add a newline */
    405   out = owl_malloc(strlen(preout)+2);
    406   strncpy(out, preout, len);
    407   out[len] = '\0';
    408   if (!strlen(out) || out[strlen(out)-1]!='\n') {
    409     strcat(out, "\n");
    410   }
     371  if (len == 0 || preout[len - 1] != '\n')
     372    out = owl_sprintf("%s\n", preout);
     373  else
     374    out = owl_strdup(preout);
     375  FREETMPS;
     376  LEAVE;
    411377
    412378  return(out);
     
    439405  char * ret = NULL;
    440406  SV *rv;
    441   STRLEN n_a;
    442407  dSP;
    443408
     
    458423
    459424  if(SvTRUE(ERRSV)) {
    460     owl_function_error("%s", SvPV(ERRSV, n_a));
     425    owl_function_error("%s", SvPV_nolen(ERRSV));
    461426    (void)POPs;
    462427  } else {
     
    465430    rv = POPs;
    466431    if(SvTRUE(rv)) {
    467       ret = owl_strdup(SvPV(rv, n_a));
     432      ret = owl_strdup(SvPV_nolen(rv));
    468433    }
    469434  }
     
    482447void owl_perlconfig_dispatch_free(owl_dispatch *d)
    483448{
    484   SvREFCNT_dec(d->pfunc);
     449  SvREFCNT_dec(d->data);
     450  owl_free(d);
    485451}
    486452
     
    489455  SV *cb = (SV*)(e->cbdata);
    490456  SV *text;
    491   unsigned int n_a;
    492457  dSP;
    493458
     
    508473
    509474  if(SvTRUE(ERRSV)) {
    510     owl_function_error("%s", SvPV(ERRSV, n_a));
     475    owl_function_error("%s", SvPV_nolen(ERRSV));
    511476  }
    512477
     
    526491  call_pv("BarnOwl::Hooks::_mainloop_hook", G_DISCARD|G_EVAL);
    527492  if(SvTRUE(ERRSV)) {
    528     STRLEN n_a;
    529     owl_function_error("%s", SvPV(ERRSV, n_a));
     493    owl_function_error("%s", SvPV_nolen(ERRSV));
    530494  }
    531495  return;
    532496}
    533497
    534 void owl_perlconfig_do_dispatch(owl_dispatch *d)
    535 {
    536   SV *cb = d->pfunc;
    537   unsigned int n_a;
     498void owl_perlconfig_dispatch(owl_dispatch *d)
     499{
     500  SV *cb = d->data;
    538501  dSP;
    539502  if(cb == NULL) {
    540503    owl_function_error("Perl callback is NULL!");
     504    return;
    541505  }
    542506
     
    550514
    551515  if(SvTRUE(ERRSV)) {
    552     owl_function_error("%s", SvPV(ERRSV, n_a));
     516    owl_function_error("%s", SvPV_nolen(ERRSV));
    553517  }
    554518
     
    556520  LEAVE;
    557521}
     522
     523void owl_perlconfig_perl_timer(owl_timer *t, void *data)
     524{
     525  SV *obj = data;
     526
     527  if(!SvROK(obj)) {
     528    return;
     529  }
     530
     531  dSP;
     532  ENTER;
     533  SAVETMPS;
     534
     535  PUSHMARK(SP);
     536  XPUSHs(obj);
     537  PUTBACK;
     538
     539  call_method("do_callback", G_DISCARD|G_KEEPERR|G_EVAL);
     540
     541  SPAGAIN;
     542
     543  if (SvTRUE(ERRSV)) {
     544    owl_function_error("Error in calback: '%s'", SvPV_nolen(ERRSV));
     545    sv_setsv (ERRSV, &PL_sv_undef);
     546  }
     547
     548  PUTBACK;
     549  FREETMPS;
     550  LEAVE;
     551}
     552
     553void owl_perlconfig_perl_timer_destroy(owl_timer *t)
     554{
     555  if(SvOK((SV*)t->data)) {
     556    SvREFCNT_dec((SV*)t->data);
     557  }
     558}
  • perlglue.xs

    r740d5f7 r1631825  
    2424         * complex argument processing or something, we define a
    2525         * simple version here that takes arguments in as flat a
    26          * manner as possible, to simplify the XS code, with a name
    27          * with a trailing `_internal', and write a perl wrapper in
    28          * perlwrap.pm that munges the arguments as appropriate and
    29          * calls the internal version.
     26         * manner as possible, to simplify the XS code, put it in
     27         * BarnOwl::Intenal::, and write a perl wrapper in perlwrap.pm
     28         * that munges the arguments as appropriate and calls the
     29         * internal version.
    3030         */
    3131
     
    6262getcurmsg()
    6363        CODE:
    64                 ST(0) = owl_perlconfig_curmessage2hashref();
     64                RETVAL = owl_perlconfig_curmessage2hashref();
     65        OUTPUT:
     66                RETVAL
    6567
    6668int
     
    141143                if (rv) owl_free(rv);
    142144
    143 void
    144 new_command_internal(name, func, summary, usage, description)
     145void queue_message(msg)
     146        SV *msg
     147        PREINIT:
     148                owl_message *m;
     149        CODE:
     150        {
     151                if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
     152                        croak("Usage: BarnOwl::queue_message($message)");
     153                }
     154
     155                m = owl_perlconfig_hashref2message(msg);
     156
     157                owl_global_messagequeue_addmsg(&g, m);
     158        }
     159
     160void admin_message(header, body)
     161        char *header
     162        char *body
     163        CODE:
     164        {
     165                owl_function_adminmsg(header, body);           
     166        }
     167
     168void start_question(line, callback)
     169        char *line
     170        SV *callback
     171        PREINIT:
     172        CODE:
     173        {
     174                if(!SV_IS_CODEREF(callback))
     175                        croak("Callback must be a subref");
     176
     177                owl_function_start_question(line);
     178
     179                SvREFCNT_inc(callback);
     180                owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
     181                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
     182        }
     183
     184void start_password(line, callback)
     185        char *line
     186        SV *callback
     187        PREINIT:
     188        CODE:
     189        {
     190                if(!SV_IS_CODEREF(callback))
     191                        croak("Callback must be a subref");
     192
     193                owl_function_start_password(line);
     194
     195                SvREFCNT_inc(callback);
     196                owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
     197                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
     198        }
     199
     200void start_edit_win(line, callback)
     201        char *line
     202        SV *callback
     203        PREINIT:
     204                owl_editwin * e;
     205                char buff[1024];
     206        CODE:
     207        {
     208                if(!SV_IS_CODEREF(callback))
     209                        croak("Callback must be a subref");
     210
     211                e = owl_global_get_typwin(&g);
     212                owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
     213                                      owl_global_get_msg_history(&g));
     214                owl_editwin_clear(e);
     215                owl_editwin_set_dotsend(e);
     216                snprintf(buff, 1023, "----> %s\n", line);
     217                owl_editwin_set_locktext(e, buff);
     218
     219                owl_global_set_typwin_active(&g);
     220
     221                SvREFCNT_inc(callback);
     222                owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
     223                owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
     224        }
     225
     226
     227char *
     228get_data_dir ()
     229        CODE:
     230                RETVAL = (char *) owl_get_datadir();
     231        OUTPUT:
     232        RETVAL
     233
     234char *
     235get_config_dir ()
     236        CODE:
     237                RETVAL = (char *) owl_global_get_confdir(&g);
     238        OUTPUT:
     239        RETVAL 
     240
     241void
     242popless_text(text)
     243        char *text
     244        CODE:
     245        {
     246                owl_function_popless_text(text);
     247        }
     248
     249void
     250popless_ztext(text)
     251        char *text
     252        CODE:
     253        {
     254                owl_fmtext fm;
     255                owl_fmtext_init_null(&fm);
     256                owl_fmtext_append_ztext(&fm, text);
     257                owl_function_popless_fmtext(&fm);
     258                owl_fmtext_free(&fm);
     259        }
     260
     261void
     262error(text)
     263        char *text
     264        CODE:
     265        {
     266                owl_function_error("%s", text);
     267        }
     268
     269void
     270create_style(name, object)
     271     char *name
     272     SV  *object
     273     PREINIT:
     274                owl_style *s;
     275     CODE:
     276        {
     277                s = owl_malloc(sizeof(owl_style));
     278                owl_style_create_perl(s, name, object);
     279                owl_global_add_style(&g, s);
     280        }
     281
     282int
     283getnumcolors()
     284        CODE:
     285                RETVAL = owl_function_get_color_count();
     286        OUTPUT:
     287                RETVAL
     288
     289void
     290_remove_filter(filterName)
     291        char *filterName
     292        CODE:
     293        {
     294                /* Don't delete the current view, or the 'all' filter */
     295                if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g)))
     296                    && strcmp(filterName, "all")) {
     297                        owl_global_remove_filter(&g,filterName);
     298                }
     299        }
     300
     301char *
     302wordwrap(in, cols)
     303        char *in
     304        int cols
     305        PREINIT:
     306                char *rv = NULL;
     307        CODE:
     308                rv = owl_text_wordwrap(in, cols);
     309                RETVAL = rv;   
     310        OUTPUT:
     311                RETVAL
     312        CLEANUP:
     313                if (rv) owl_free(rv);
     314
     315void
     316add_dispatch(fd, cb)
     317        int fd
     318        SV * cb
     319        CODE:
     320        SvREFCNT_inc(cb);
     321        owl_select_add_perl_dispatch(fd, cb);
     322
     323void
     324remove_dispatch(fd)
     325        int fd
     326        CODE:
     327        owl_select_remove_perl_dispatch(fd);
     328
     329MODULE = BarnOwl                PACKAGE = BarnOwl::Internal
     330
     331
     332void
     333new_command(name, func, summary, usage, description)
    145334        char *name
    146335        SV *func
     
    172361           }
    173362
    174 void queue_message(msg)
    175         SV *msg
    176         PREINIT:
    177                 owl_message *m;
    178         CODE:
    179         {
    180                 if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) {
    181                         croak("Usage: BarnOwl::queue_message($message)");
    182                 }
    183 
    184                 m = owl_perlconfig_hashref2message(msg);
    185 
    186                 owl_global_messagequeue_addmsg(&g, m);
    187         }
    188 
    189 void admin_message(header, body)
    190         char *header
    191         char *body
    192         CODE:
    193         {
    194                 owl_function_adminmsg(header, body);           
    195         }
    196 
    197 void start_question(line, callback)
    198         char *line
    199         SV *callback
    200         PREINIT:
    201         CODE:
    202         {
    203                 if(!SV_IS_CODEREF(callback))
    204                         croak("Callback must be a subref");
    205 
    206                 owl_function_start_question(line);
    207 
    208                 SvREFCNT_inc(callback);
    209                 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
    210                 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
    211         }
    212 
    213 void start_password(line, callback)
    214         char *line
    215         SV *callback
    216         PREINIT:
    217         CODE:
    218         {
    219                 if(!SV_IS_CODEREF(callback))
    220                         croak("Callback must be a subref");
    221 
    222                 owl_function_start_password(line);
    223 
    224                 SvREFCNT_inc(callback);
    225                 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
    226                 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
    227         }
    228 
    229 void start_edit_win(line, callback)
    230         char *line
    231         SV *callback
    232         PREINIT:
    233                 owl_editwin * e;
    234                 char buff[1024];
    235         CODE:
    236         {
    237                 if(!SV_IS_CODEREF(callback))
    238                         croak("Callback must be a subref");
    239 
    240                 e = owl_global_get_typwin(&g);
    241                 owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
    242                                       owl_global_get_msg_history(&g));
    243                 owl_editwin_clear(e);
    244                 owl_editwin_set_dotsend(e);
    245                 snprintf(buff, 1023, "----> %s\n", line);
    246                 owl_editwin_set_locktext(e, buff);
    247 
    248                 owl_global_set_typwin_active(&g);
    249 
    250                 SvREFCNT_inc(callback);
    251                 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback);
    252                 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback);
    253         }
    254 
    255 
    256 char *
    257 get_data_dir ()
    258         CODE:
    259                 RETVAL = (char *) owl_get_datadir();
    260         OUTPUT:
    261         RETVAL
    262 
    263 char *
    264 get_config_dir ()
    265         CODE:
    266                 RETVAL = (char *) owl_global_get_confdir(&g);
    267         OUTPUT:
    268         RETVAL 
    269 
    270 void
    271 popless_text(text)
    272         char *text
    273         CODE:
    274         {
    275                 owl_function_popless_text(text);
    276         }
    277 
    278 void
    279 popless_ztext(text)
    280         char *text
    281         CODE:
    282         {
    283                 owl_fmtext fm;
    284                 owl_fmtext_init_null(&fm);
    285                 owl_fmtext_append_ztext(&fm, text);
    286                 owl_function_popless_fmtext(&fm);
    287                 owl_fmtext_free(&fm);
    288         }
    289 
    290 void
    291 error(text)
    292         char *text
    293         CODE:
    294         {
    295                 owl_function_error("%s", text);
    296         }
    297 
    298 void
    299 create_style(name, object)
    300      char *name
    301      SV  *object
    302      PREINIT:
    303                 owl_style *s;
    304      CODE:
    305         {
    306                 s = owl_malloc(sizeof(owl_style));
    307                 owl_style_create_perl(s, name, object);
    308                 owl_global_add_style(&g, s);
    309         }
    310 
    311 int
    312 getnumcolors()
    313         CODE:
    314                 RETVAL = owl_function_get_color_count();
    315         OUTPUT:
    316                 RETVAL
    317 
    318 void
    319 _remove_filter(filterName)
    320         char *filterName
    321         CODE:
    322         {
    323                 /* Don't delete the current view, or the 'all' filter */
    324                 if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g)))
    325                     && strcmp(filterName, "all")) {
    326                         owl_global_remove_filter(&g,filterName);
    327                 }
    328         }
    329 
    330 char *
    331 wordwrap(in, cols)
    332         char *in
    333         int cols
    334         PREINIT:
    335                 char *rv = NULL;
    336         CODE:
    337                 rv = owl_text_wordwrap(in, cols);
    338                 RETVAL = rv;   
    339         OUTPUT:
    340                 RETVAL
    341         CLEANUP:
    342                 if (rv) owl_free(rv);
    343 
    344 void
    345 new_variable_string_internal(name, ival, summ, desc)
     363void
     364new_variable_string(name, ival, summ, desc)
    346365        char * name
    347366        char * ival
     
    356375
    357376void
    358 new_variable_int_internal(name, ival, summ, desc)
     377new_variable_int(name, ival, summ, desc)
    359378        char * name
    360379        int ival
     
    369388
    370389void
    371 new_variable_bool_internal(name, ival, summ, desc)
     390new_variable_bool(name, ival, summ, desc)
    372391        char * name
    373392        int ival
     
    381400                                      ival);
    382401
    383 void
    384 add_dispatch(fd, cb)
    385         int fd
    386         SV * cb
    387         CODE:
    388         SvREFCNT_inc(cb);
    389         owl_select_add_perl_dispatch(fd, cb);
    390 
    391 void
    392 remove_dispatch(fd)
    393         int fd
    394         CODE:
    395         owl_select_remove_perl_dispatch(fd);
     402IV
     403add_timer(after, interval, cb)
     404        int after
     405        int interval
     406        SV *cb
     407        PREINIT:
     408                SV *ref;
     409                owl_timer *t;
     410        CODE:
     411                ref = sv_rvweaken(newSVsv(cb));
     412                t = owl_select_add_timer(after,
     413                                         interval,
     414                                         owl_perlconfig_perl_timer,
     415                                         owl_perlconfig_perl_timer_destroy,
     416                                         ref);
     417        owl_function_debugmsg("Created timer %p", t);
     418        RETVAL = (IV)t;
     419        OUTPUT:
     420                RETVAL
     421
     422void
     423remove_timer(timer)
     424        IV timer
     425        PREINIT:
     426                owl_timer *t;
     427        CODE:
     428                t = (owl_timer*)timer;
     429                owl_function_debugmsg("Freeing timer %p", t);
     430                                owl_select_remove_timer(t);
  • perlwrap.pm

    r740d5f7 re9708d2  
    242242    );
    243243
    244     BarnOwl::new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});
     244    BarnOwl::Internal::new_command($name, $func, $args{summary}, $args{usage}, $args{description});
    245245}
    246246
     
    275275
    276276sub new_variable_int {
    277     unshift @_, \&BarnOwl::new_variable_int_internal, 0;
     277    unshift @_, \&BarnOwl::Internal::new_variable_int, 0;
    278278    goto \&_new_variable;
    279279}
    280280
    281281sub new_variable_bool {
    282     unshift @_, \&BarnOwl::new_variable_bool_internal, 0;
     282    unshift @_, \&BarnOwl::Internal::new_variable_bool, 0;
    283283    goto \&_new_variable;
    284284}
    285285
    286286sub new_variable_string {
    287     unshift @_, \&BarnOwl::new_variable_string_internal, "";
     287    unshift @_, \&BarnOwl::Internal::new_variable_string, "";
    288288    goto \&_new_variable;
    289289}
     
    795795=item $receiveMessage
    796796
    797 Called with a C<BarnOwl::Message> object every time BarnOwl appends a
    798 new message to its message list
     797Called with a C<BarnOwl::Message> object every time BarnOwl receives a
     798new incoming message.
     799
     800=item $newMessage
     801
     802Called with a C<BarnOwl::Message> object every time BarnOwl appends
     803I<any> new message to the message list.
    799804
    800805=item $mainLoop
     
    810815displayed in a popup window, with zephyr formatting parsed.
    811816
     817=item $getQuickstart
     818
     819Called by :show quickstart to display 2-5 lines of help on how to
     820start using the protocol. The result from every function registered
     821with this hook will be appended and displayed in an admin message,
     822with zephyr formatting parsed. The format should be
     823"@b(Protocol:)\nSome text.\nMore text.\n"
     824
    812825=back
    813826
     
    818831our @EXPORT_OK = qw($startup $shutdown
    819832                    $receiveMessage $newMessage
    820                     $mainLoop $getBuddyList);
     833                    $mainLoop $getBuddyList
     834                    $getQuickstart);
    821835
    822836our %EXPORT_TAGS = (all => [@EXPORT_OK]);
     
    828842our $mainLoop = BarnOwl::Hook->new;
    829843our $getBuddyList = BarnOwl::Hook->new;
     844our $getQuickstart = BarnOwl::Hook->new;
    830845
    831846# Internal startup/shutdown routines called by the C code
     
    921936}
    922937
     938sub _get_quickstart {
     939    return join("\n", $getQuickstart->run);
     940}
     941
    923942################################################################################
    924943# Built-in perl styles
     
    12141233}
    12151234
     1235package BarnOwl::Timer;
     1236
     1237sub new {
     1238    my $class = shift;
     1239    my $args = shift;
     1240
     1241    my $cb = $args->{cb};
     1242    die("Invalid callback pased to BarnOwl::Timer\n") unless ref($cb) eq 'CODE';
     1243
     1244    my $self = {cb => $cb};
     1245
     1246    bless($self, $class);
     1247
     1248    $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0,
     1249                                                  $args->{interval} || 0,
     1250                                                  $self);
     1251    return $self;
     1252}
     1253
     1254sub do_callback {
     1255    my $self = shift;
     1256    $self->{cb}->($self);
     1257}
     1258
     1259sub DESTROY {
     1260    my $self = shift;
     1261    if(defined($self->{timer})) {
     1262        BarnOwl::Internal::remove_timer($self->{timer});
     1263    }
     1264}
     1265
    12161266
    12171267# switch to package main when we're done
  • popexec.c

    r1971b59 r40c6657  
    5151    return NULL;
    5252  } else if (pid != 0) {
     53    close(child_write_fd);
    5354    /* still in owl */
    54     int muxhandle;
    5555    pe->pid=pid;
    5656    pe->winactive=1;
    57     pe->rfd = parent_read_fd;
    58     close(child_write_fd);
    59     muxhandle = owl_muxevents_add(owl_global_get_muxevents(&g),
    60                                   parent_read_fd, OWL_MUX_READ|OWL_MUX_EXCEPT,
    61                                   owl_popexec_inputhandler, (void*)pe);
     57    pe->dispatch.fd = parent_read_fd;
     58    pe->dispatch.cfunc = owl_popexec_inputhandler;
     59    pe->dispatch.destroy = owl_popexec_free_dispatch;
     60    pe->dispatch.data = pe;
     61    owl_select_add_dispatch(&pe->dispatch);
    6262    pe->refcount++;
    6363  } else {
     
    7373    dup2(child_write_fd, 2 /*stderr*/);
    7474    close(child_write_fd);
    75    
    76     while(0) {
    77       write(child_write_fd, "meep\n", 5);
    78       sleep(1);
    79     }
    8075
    8176    argv[0] = "sh";
     
    9085}
    9186
    92 void owl_popexec_inputhandler(int handle, int fd, int eventmask, void *data)
     87void owl_popexec_inputhandler(owl_dispatch *d)
    9388{
    94   owl_popexec *pe = (owl_popexec*)data;
     89  owl_popexec *pe = d->data;
    9590  int navail, bread, rv_navail;
    9691  char *buf;
     
    10196  /* If pe->winactive is 0 then the vwin has closed.
    10297   * If pe->pid is 0 then the child has already been reaped.
    103    * if pe->rfd is -1 then the fd has been closed out.
     98   * if d->fd is -1 then the fd has been closed out.
    10499   * Under these cases we want to get to a state where:
    105100   *   - data read until end if child running
     
    110105
    111106  /* the viewwin has closed */
    112   if (pe->rfd<0 && !pe->pid && !pe->winactive) {
    113     owl_muxevents_remove(owl_global_get_muxevents(&g), handle);
    114     owl_function_debugmsg("unref of %p from input handler at A", pe);
    115     owl_popexec_unref(pe);
     107  if (!pe->pid && !pe->winactive) {
     108    owl_select_remove_dispatch(d->fd);
    116109    return;
    117110  }
    118111
    119   if (0 != (rv_navail = ioctl(fd, FIONREAD, (void*)&navail))) {
     112  if (0 != (rv_navail = ioctl(d->fd, FIONREAD, (void*)&navail))) {
    120113    owl_function_debugmsg("ioctl error");
    121114  }
     
    130123      owl_viewwin_redisplay(pe->vwin, 1);
    131124    }
    132     if (pe->rfd>0) {
    133       close(pe->rfd);
    134       pe->rfd = -1;
    135     }
    136     owl_muxevents_remove(owl_global_get_muxevents(&g), handle);
    137     owl_function_debugmsg("unref of %p from input handler at B", pe);
    138     owl_popexec_unref(pe);
     125    owl_select_remove_dispatch(d->fd);
    139126    return;
    140127  }
    141128
    142   if (pe->rfd<0 || !pe->pid || !pe->winactive || rv_navail) {
     129  if (d->fd<0 || !pe->pid || !pe->winactive || rv_navail) {
    143130    owl_function_error("popexec should not have reached this point");
    144131    return;
     
    148135  if (navail>1024) { navail = 1024; }
    149136  buf = owl_malloc(navail+1);
    150   owl_function_debugmsg("about to read %d\n", navail);
    151   bread = read(fd, buf, navail);
     137  owl_function_debugmsg("about to read %d", navail);
     138  bread = read(d->fd, buf, navail);
    152139  if (bread<0) {
    153140    perror("read");
     
    157144    buf[navail] = '\0';
    158145  }
    159   owl_function_debugmsg("got data:  <%s>\n", buf);
     146  owl_function_debugmsg("got data:  <%s>", buf);
    160147  if (pe->winactive) {
    161148    owl_viewwin_append_text(pe->vwin, buf);
     
    166153}
    167154
     155void owl_popexec_free_dispatch(owl_dispatch *d)
     156{
     157  owl_popexec *pe = d->data;
     158  close(d->fd);
     159  owl_popexec_unref(pe);
     160}
     161
    168162void owl_popexec_viewwin_onclose(owl_viewwin *vwin, void *data)
    169163{
     
    172166
    173167  pe->winactive = 0;
    174   if (pe->rfd>0) {
    175     close(pe->rfd);
    176     pe->rfd = -1;
     168  if (pe->dispatch.fd>0) {
     169    owl_select_remove_dispatch(pe->dispatch.fd);
    177170  }
    178171  if (pe->pid) {
  • popwin.c

    r818a073 rf34dd65  
    5757}
    5858
    59 int owl_popwin_display_text(owl_popwin *pw, char *text)
    60 {
    61   waddstr(pw->popwin, text);
    62   wnoutrefresh(pw->popwin);
    63   touchwin(pw->borderwin);
    64   wnoutrefresh(pw->borderwin);
    65   owl_global_set_needrefresh(&g);
    66   return(0);
    67 }             
    68 
    6959int owl_popwin_close(owl_popwin *pw)
    7060{
     
    9686}
    9787
    98 void owl_popwin_set_handler(owl_popwin *pw, void (*func)(int ch))
    99 {
    100   pw->handler=func;
    101 }
    102 
    103 void owl_popwin_unset_handler(owl_popwin *pw)
    104 {
    105   pw->handler=NULL;
    106 }
    107 
    10888WINDOW *owl_popwin_get_curswin(owl_popwin *pw)
    10989{
  • regex.c

    r8b7466b r554a2b8  
    1313{
    1414  int ret;
    15   char buff1[LINE], buff2[LINE];
     15  char buff1[LINE];
    1616  char *ptr;
    1717 
     
    2929  if (ret) {
    3030    regerror(ret, NULL, buff1, LINE);
    31     sprintf(buff2, "Error in regular expression: %s", buff1);
    32     owl_function_makemsg(buff2);
     31    owl_function_makemsg("Error in regular expression: %s", buff1);
    3332    owl_free(re->string);
    3433    re->string=NULL;
  • select.c

    r2f69081 r1895c29  
    22
    33static const char fileIdent[] = "$Id: select.c 894 2008-01-17 07:13:44Z asedeno $";
     4
     5static int dispatch_active = 0;
     6
     7int _owl_select_timer_cmp(owl_timer *t1, owl_timer *t2) {
     8  return t1->time - t2->time;
     9}
     10
     11int _owl_select_timer_eq(owl_timer *t1, owl_timer *t2) {
     12  return t1 == t2;
     13}
     14
     15owl_timer *owl_select_add_timer(int after, int interval, void (*cb)(owl_timer *, void *), void (*destroy)(owl_timer*), void *data)
     16{
     17  owl_timer *t = owl_malloc(sizeof(owl_timer));
     18  GList **timers = owl_global_get_timerlist(&g);
     19
     20  t->time = time(NULL) + after;
     21  t->interval = interval;
     22  t->callback = cb;
     23  t->destroy = destroy;
     24  t->data = data;
     25
     26  *timers = g_list_insert_sorted(*timers, t,
     27                                 (GCompareFunc)_owl_select_timer_cmp);
     28  return t;
     29}
     30
     31void owl_select_remove_timer(owl_timer *t)
     32{
     33  GList **timers = owl_global_get_timerlist(&g);
     34  if (t && g_list_find(*timers, t)) {
     35    *timers = g_list_remove(*timers, t);
     36    if(t->destroy) {
     37      t->destroy(t);
     38    }
     39    owl_free(t);
     40  }
     41}
     42
     43void owl_select_process_timers(struct timeval *timeout)
     44{
     45  time_t now = time(NULL);
     46  GList **timers = owl_global_get_timerlist(&g);
     47
     48  while(*timers) {
     49    owl_timer *t = (*timers)->data;
     50    int remove = 0;
     51
     52    if(t->time > now)
     53      break;
     54
     55    /* Reschedule if appropriate */
     56    if(t->interval > 0) {
     57      t->time = now + t->interval;
     58      *timers = g_list_remove(*timers, t);
     59      *timers = g_list_insert_sorted(*timers, t,
     60                                     (GCompareFunc)_owl_select_timer_cmp);
     61    } else {
     62      remove = 1;
     63    }
     64
     65    /* Do the callback */
     66    t->callback(t, t->data);
     67    if(remove) {
     68      owl_select_remove_timer(t);
     69    }
     70  }
     71
     72  if(*timers) {
     73    owl_timer *t = (*timers)->data;
     74    timeout->tv_sec = t->time - now;
     75    if (timeout->tv_sec > 60)
     76      timeout->tv_sec = 60;
     77  } else {
     78    timeout->tv_sec = 60;
     79  }
     80
     81  timeout->tv_usec = 0;
     82}
    483
    584/* Returns the index of the dispatch for the file descriptor. */
     
    1998}
    2099
     100void owl_select_remove_dispatch_at(int elt) /* noproto */
     101{
     102  owl_list *dl;
     103  owl_dispatch *d;
     104
     105  dl = owl_global_get_dispatchlist(&g);
     106  d = (owl_dispatch*)owl_list_get_element(dl, elt);
     107  owl_list_remove_element(dl, elt);
     108  if (d->destroy) {
     109    d->destroy(d);
     110  }
     111}
     112
    21113/* Adds a new owl_dispatch to the list, replacing existing ones if needed. */
    22114void owl_select_add_dispatch(owl_dispatch *d)
     
    24116  int elt;
    25117  owl_list *dl;
     118
     119  d->needs_gc = 0;
    26120
    27121  elt = owl_select_find_dispatch(d->fd);
     
    34128       replace the old dispatch. */
    35129    if (d_old != d) {
    36       owl_list_replace_element(dl, elt, d);
    37       owl_free(d_old);
    38     }
    39   }
    40   else {
    41     owl_list_append_element(dl, d);
    42   }
     130      owl_select_remove_dispatch_at(elt);
     131    }
     132  }
     133  owl_list_append_element(dl, d);
    43134}
    44135
     
    48139  int elt;
    49140  owl_list *dl;
     141  owl_dispatch *d;
    50142
    51143  elt = owl_select_find_dispatch(fd);
    52   dl = owl_global_get_dispatchlist(&g);
    53  
    54   if (elt != -1) {
    55     owl_dispatch *d;
     144  if(elt == -1) {
     145    return;
     146  } else if(dispatch_active) {
     147    /* Defer the removal until dispatch is done walking the list */
     148    dl = owl_global_get_dispatchlist(&g);
    56149    d = (owl_dispatch*)owl_list_get_element(dl, elt);
    57     owl_list_remove_element(dl, elt);
    58     if (d->pfunc) {
    59       owl_perlconfig_dispatch_free(d);
    60     }
    61     owl_free(d);
     150    d->needs_gc = 1;
     151  } else {
     152    owl_select_remove_dispatch_at(elt);
    62153  }
    63154}
     
    75166  if (elt != -1) {
    76167    d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
    77     if (d->pfunc == NULL) {
     168    if (d->cfunc != owl_perlconfig_dispatch) {
    78169      /* don't mess with non-perl dispatch functions from here. */
    79170      return 1;
     
    83174  d = malloc(sizeof(owl_dispatch));
    84175  d->fd = fd;
    85   d->cfunc = NULL;
    86   d->pfunc = cb;
     176  d->cfunc = owl_perlconfig_dispatch;
     177  d->destroy = owl_perlconfig_dispatch_free;
     178  d->data = cb;
    87179  owl_select_add_dispatch(d);
    88180  return 0;
     
    97189  if (elt != -1) {
    98190    d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
    99     if (d->pfunc != NULL) {
    100       owl_select_remove_dispatch(fd);
     191    if (d->cfunc == owl_perlconfig_dispatch) {
     192      owl_select_remove_dispatch_at(elt);
    101193      return 0;
    102194    }
     
    125217}
    126218
     219void owl_select_gc()
     220{
     221  int i;
     222  owl_list *dl;
     223
     224  dl = owl_global_get_dispatchlist(&g);
     225  /*
     226   * Count down so we aren't set off by removing items from the list
     227   * during the iteration.
     228   */
     229  for(i = owl_list_get_size(dl) - 1; i >= 0; i--) {
     230    owl_dispatch *d = owl_list_get_element(dl, i);
     231    if(d->needs_gc) {
     232      owl_select_remove_dispatch_at(i);
     233    }
     234  }
     235}
     236
    127237void owl_select_dispatch(fd_set *fds, int max_fd)
    128238{
     
    133243  dl = owl_global_get_dispatchlist(&g);
    134244  len = owl_select_dispatch_count();
     245
     246  dispatch_active = 1;
     247
    135248  for(i = 0; i < len; i++) {
    136249    d = (owl_dispatch*)owl_list_get_element(dl, i);
    137250    /* While d shouldn't normally be null, the list may be altered by
    138251     * functions we dispatch to. */
    139     if (d != NULL && FD_ISSET(d->fd, fds)) {
     252    if (d != NULL && !d->needs_gc && FD_ISSET(d->fd, fds)) {
    140253      if (d->cfunc != NULL) {
    141         (d->cfunc)();
     254        d->cfunc(d);
    142255      }
    143       else if (d->pfunc != NULL) {
    144         owl_perlconfig_do_dispatch(d);
    145       }
    146     }
    147   }
     256    }
     257  }
     258
     259  dispatch_active = 0;
     260  owl_select_gc();
    148261}
    149262
     
    182295  struct timeval timeout;
    183296
    184   timeout.tv_sec = 1;
    185   timeout.tv_usec = 0;
     297  owl_select_process_timers(&timeout);
    186298
    187299  max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e);
  • tester.c

    r1cf3f8d3 r3381399  
    66
    77owl_global g;
    8 
    9 void screeninit()
    10 {
    11   char buff[1024];
    12  
    13   sprintf(buff, "TERMINFO=%s", TERMINFO);
    14   putenv(buff);
    15 
    16   initscr();
    17   start_color();
    18   /* cbreak(); */
    19   raw();
    20   noecho();
    21   intrflush(stdscr,FALSE);
    22   keypad(stdscr,TRUE);
    23   nodelay(stdscr,1);
    24   clear();
    25   refresh();
    26   meta(stdscr, TRUE);
    27 }
    28 
    29 void test1()
    30 {
    31   int j;
    32   owl_editwin e;
    33 
    34   screeninit();
    35 
    36   owl_editwin_init(&e, stdscr, LINES, COLS, OWL_EDITWIN_STYLE_MULTILINE, NULL);
    37   /* owl_editwin_set_locktext(&e, "Here is some locktext:\n");*/
    38   doupdate();
    39   while (1) {
    40     usleep(50);
    41 
    42     j=getch();
    43 
    44     if (j==ERR) continue;
    45 
    46     if (j==3) break;
    47 
    48     if (j==27) {
    49       j=getch();
    50       if (j==ERR) continue;
    51       owl_editwin_process_char(&e, j);
    52       doupdate();
    53     } else {
    54       owl_editwin_process_char(&e, j);
    55       doupdate();
    56     }
    57   }
    58   endwin();
    59   printf("Had:\n%s", owl_editwin_get_text(&e));
    60 }
    61 
    62 void test2(char *in)
    63 {
    64   owl_fmtext t;
    65 
    66   screeninit();
    67 
    68   owl_fmtext_init_null(&t);
    69   owl_fmtext_append_ztext(&t, in);
    70   owl_fmtext_curs_waddstr(&t, stdscr);
    71   wrefresh(stdscr);
    72   sleep(5000);
    73   endwin();
    74 }
    75 
    76 void test3()
    77 {
    78   ZNotice_t *n;
    79 
    80   printf("%i\n", sizeof(n->z_uid.zuid_addr));
    81   /* gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); */
    82 }
    83 
    84 void colorinfo()
    85 {
    86   char buff[1024];
    87  
    88   screeninit();
    89   sprintf(buff, "Have %i COLOR_PAIRS\n", COLOR_PAIRS);
    90   addstr(buff);
    91   refresh();
    92   sleep(10);
    93   endwin(); 
    94 }
    95 
    96 void test4()
    97 {
    98   int j;
    99   char buff[1024];
    100 
    101   screeninit();
    102  
    103   while (1) {
    104     usleep(100);
    105 
    106     j=getch();
    107 
    108     if (j==ERR) continue;
    109 
    110     if (j==3) break;
    111     sprintf(buff, "%o\n", j);
    112     addstr(buff);
    113   }
    114   endwin();
    115 }
    116 
    117 void test_keypress()
    118 {
    119   int j, rev;
    120   char buff[1024], buff2[64];
    121 
    122   screeninit();
    123  
    124   while (1) {
    125     usleep(100);
    126 
    127     j=wgetch(stdscr);
    128 
    129     if (j==ERR) continue;
    130 
    131     if (j==3) break;
    132     if (0 == owl_keypress_tostring(j, 0, buff2, 1000)) {
    133       rev = owl_keypress_fromstring(buff2);
    134       sprintf(buff, "%s : 0x%x 0%o %d %d %s\n", buff2, j, j, j, rev,
    135               (j==rev?"matches":"*** WARNING: Does Not Reverse"));
    136     } else {
    137       sprintf(buff, "UNKNOWN : 0x%x 0%o %d\n", j, j, j);
    138     }
    139       addstr(buff);
    140   }
    141   endwin();
    142 }
    143 
    1448
    1459#define OWL_DICT_NTESTS  20
     
    15519
    15620  int numfailures=0;
    157   if (argc==1 || (argc==2 && 0==strcmp(argv[1],"reg"))) {
    158     printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS
    159            +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS);
    160     numfailures += owl_util_regtest();
    161     numfailures += owl_dict_regtest();
    162     numfailures += owl_variable_regtest();
    163     numfailures += owl_filter_regtest();
    164     numfailures += owl_obarray_regtest();
    165     if (numfailures) {
     21  printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS
     22         +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS);
     23  numfailures += owl_util_regtest();
     24  numfailures += owl_dict_regtest();
     25  numfailures += owl_variable_regtest();
     26  numfailures += owl_filter_regtest();
     27  numfailures += owl_obarray_regtest();
     28  if (numfailures) {
    16629      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
    167     }
    168     return(numfailures);
    169   } else if (argc==2 && 0==strcmp(argv[1],"test1")) {
    170     test1();
    171   } else if (argc==2 && 0==strcmp(argv[1],"colorinfo")) {
    172     colorinfo();
    173   } else if (argc==2 && 0==strcmp(argv[1],"test4")) {
    174     test4();
    175   } else if (argc==2 && 0==strcmp(argv[1],"keypress")) {
    176     test_keypress();
    177   } else {
    178     fprintf(stderr, "No test specified.  Current options are: reg test1\n");
    17930  }
    180   return(0);
     31  return(numfailures);
    18132}
  • text.c

    r3bcf125 rf34dd65  
    66
    77static const char fileIdent[] = "$Id$";
    8 
    9 /* start with line aline (where the first line is 1) and print 'lines'
    10  *  lines
    11  */
    12 int owl_text_truncate_lines(char *out, char *in, int aline, int lines)
    13 {
    14   char *ptr1, *ptr2;
    15   int i;
    16 
    17   strcpy(out, "");
    18  
    19   if (aline==0) aline=1; /* really illegal use */
    20 
    21   /* find the starting line */
    22   ptr1=in;
    23   if (aline!=1) {
    24      for (i=0; i<aline-1; i++) {
    25       ptr1=strchr(ptr1, '\n');
    26       if (!ptr1) return(-1);
    27       ptr1++;
    28     }
    29   }
    30   /* ptr1 now holds the starting point */
    31 
    32   /* copy in the next 'lines' lines */
    33   if (lines<1) return(-1);
    34  
    35   for (i=0; i<lines; i++) {
    36     ptr2=strchr(ptr1, '\n');
    37     if (!ptr2) {
    38       strcat(out, ptr1);
    39       return(-1);
    40     }
    41     strncat(out, ptr1, ptr2-ptr1+1);
    42     ptr1=ptr2+1;
    43   }
    44   return(0);
    45 }
    46 
    47  
    48 /* the first column is column 0.  The message is expected to end in a
    49  * new line for now */
    50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)
    51 {
    52   char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;
    53   int col, cnt, padding;
    54  
    55   tmpbuff=owl_malloc(strlen(in)+20);
    56 
    57   strcpy(tmpbuff, "");
    58   last=in+strlen(in)-1;
    59   ptr_s=in;
    60   while (ptr_s<last) {
    61     ptr_e=strchr(ptr_s, '\n');
    62     if (!ptr_e) {
    63       /* but this shouldn't happen if we end in a \n */
    64       break;
    65     }
    66    
    67     if (ptr_e==ptr_s) {
    68       strcat(tmpbuff, "\n");
    69       ptr_s++;
    70       continue;
    71     }
    72 
    73     col = 0;
    74     cnt = 0;
    75     padding = 0;
    76     ptr_c = ptr_s;
    77     while(col < bcol && ptr_c < ptr_e) {
    78       gunichar c = g_utf8_get_char(ptr_c);
    79       if (col + mk_wcwidth(c) > bcol) break;
    80       col += mk_wcwidth(c);
    81       ptr_c = g_utf8_next_char(ptr_c);
    82       if (col >= acol) {
    83         if (cnt == 0) {
    84           ptr_s = ptr_c;
    85           padding = col - acol;
    86         }
    87         ++cnt;
    88       }
    89     }
    90     if (cnt) {
    91       while(padding-- > 0) {
    92         strcat(tmpbuff, " ");
    93       }
    94       strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);
    95     }
    96     strcat(tmpbuff, "\n");
    97     ptr_s = ptr_e + 1;
    98 #if 0
    99     /* we need to check that we won't run over here */
    100     if ( (ptr_e-ptr_s) < (bcol-acol) ) {
    101       len=ptr_e-(ptr_s+acol);
    102     } else {
    103       len=bcol-acol;
    104     }
    105     if ((ptr_s+len)>=last) {
    106       len-=last-(ptr_s+len);
    107     }
    108 
    109     strncat(tmpbuff, ptr_s+acol, len);
    110     strcat(tmpbuff, "\n");
    111 
    112     ptr_s=ptr_e+1;
    113 #endif
    114   }
    115   strcpy(out, tmpbuff);
    116   owl_free(tmpbuff);
    117 }
    118 
    1198
    1209void owl_text_indent(char *out, char *in, int n)
  • util.c

    r601733d rf34dd65  
    125125  wattroff(sepwin, A_REVERSE);
    126126  wnoutrefresh(sepwin);
    127 }
    128 
    129 
    130 void pophandler_quit(int ch)
    131 {
    132   if (ch=='q') {
    133     owl_popwin_close(owl_global_get_popwin(&g));
    134   }
    135127}
    136128
     
    373365
    374366  if (days>0) {
    375     out=owl_sprintf("%i d %2.2i:%2.2i", days, hours, run);
     367    out=owl_sprintf("%i d %2.2i:%2.2li", days, hours, run);
    376368  } else {
    377     out=owl_sprintf("    %2.2i:%2.2i", hours, run);
     369    out=owl_sprintf("    %2.2i:%2.2li", hours, run);
    378370  }
    379371  return(out);
    380 }
    381 
    382 /* return the index of the last char before a change from the first one */
    383 int owl_util_find_trans(char *in, int len)
    384 {
    385   int i;
    386   for (i=1; i<len; i++) {
    387     if (in[i] != in[0]) return(i-1);
    388   }
    389   return(i);
    390 }
    391 
    392 int owl_util_find_trans_short(short *in, int len)
    393 {
    394   int i;
    395   for (i=1; i<len; i++) {
    396     if (in[i] != in[0]) return(i-1);
    397   }
    398   return(i);
    399 }
    400 
    401 /* Caller must free response.
    402  * Takes in strings which are space-separated lists of tokens
    403  * and returns a single string containing no token more than once.
    404  * If prohibit is non-null, no token may start with a character
    405  * in prohibit.
    406  */
    407 char *owl_util_uniq(char *A, char *B, char *prohibit)
    408 {
    409  
    410   char *cat, **tok;
    411   int toklen, i, j, first=1;
    412   cat = owl_malloc(strlen(A)+strlen(B)+3);
    413   strcpy(cat, A);
    414   strcat(cat, " ");
    415   strcat(cat, B);
    416   tok = atokenize(cat, " ", &toklen);
    417   strcpy(cat, "");
    418   for (i=0; i<toklen; i++) {
    419     int dup=0;
    420     for (j=0; j<i; j++) {
    421       if (!strcmp(tok[i], tok[j])) dup=1;
    422     }
    423     if (!dup && (!prohibit || !strchr(prohibit, tok[i][0]))) {
    424       if (!first) {
    425         strcat(cat, " ");
    426       }
    427       first=0;
    428       strcat(cat, tok[i]);
    429     }
    430   }
    431   atokenize_free(tok, toklen);
    432   return(cat);
    433372}
    434373
     
    641580      owl_function_error("Error opening file %s for writing", backupfilename);
    642581      owl_free(backupfilename);
     582      fclose(file);
    643583      return;
    644584    }
    645     owl_free(backupfilename);
    646585  }
    647586
     
    682621    owl_function_error("WARNING: Error opening %s for writing.  Use %s to restore.", filename, backupfilename);
    683622    owl_function_beep();
    684     owl_free(line);
    685     return;
    686   }
    687 
    688   fputs(text, file);
    689   fclose(file);
    690 }
    691 
    692 /* add the string 'str' to the list 'list' of strings, only if it
    693  * is not already present
    694  */
    695 void owl_util_list_add_unique_string(owl_list *list, char *str)
    696 {
    697   int i, j;
    698 
    699   j=owl_list_get_size(list);
    700   for (i=0; i<j; i++) {
    701     if (!strcmp(str, owl_list_get_element(list, i))) return;
    702   }
    703   owl_list_append_element(list, owl_strdup(str));
    704 }
    705 
    706 int owl_util_common_strings_in_lists(owl_list *a, owl_list *b)
    707 {
    708   int i, j, x, y;
    709 
    710   j=owl_list_get_size(a);
    711   for (i=0; i<j; i++) {
    712     y=owl_list_get_size(b);
    713     for (x=0; x<y; x++) {
    714       if (!strcmp(owl_list_get_element(a, i), owl_list_get_element(b, x))) return(1);
    715     }
    716   }
    717   return(0);
     623  } else {
     624    fputs(text, file);
     625    fclose(file);
     626  }
     627
     628  if (backup)
     629    owl_free(backupfilename);
     630  owl_free(text);
    718631}
    719632
     
    881794              !strcmp("meep", skiptokens("foo 'bar quux' meep", 2)));
    882795
    883   FAIL_UNLESS("owl_util_uniq 1",
    884               !strcmp("foo bar x", owl_util_uniq("foo", "bar x", "-")));
    885   FAIL_UNLESS("owl_util_uniq 2",
    886               !strcmp("foo bar x", owl_util_uniq("foo", "bar -y x", "-")));
    887   FAIL_UNLESS("owl_util_uniq 3",
    888               !strcmp("meep foo bar", owl_util_uniq("meep foo", "bar foo meep", "-")));
    889 
    890796  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
    891797  printf("# END testing owl_util (%d failures)\n", numfailed);
  • variable.c

    r451db9e r4f15e8e  
    351351               "                 the cursor will be near the center.\n",
    352352               "normal,top,neartop,center,paged,pagedcenter" ),
    353 
    354   OWLVAR_ENUM( "webbrowser" /* %OwlVarStub */, OWL_WEBBROWSER_NETSCAPE,
    355                "web browser to use to launch URLs",
    356                "When the 'w' key is pressed, this browser is used\n"
    357                "to display the requested URL.\n",
    358                "none,netscape,galeon,opera" ),
    359353
    360354
     
    10561050  FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize"));
    10571051
    1058   FAIL_UNLESS("get enum", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
    1059   FAIL_UNLESS("get enum as string 1", 0==owl_variable_get_tostring(&vd,"webbrowser", buf, 1024));
    1060   FAIL_UNLESS("get enum as string 2", 0==strcmp(buf,"netscape"));
    1061   FAIL_UNLESS("set enum 1", 0==owl_variable_set_int(&vd,"webbrowser",OWL_WEBBROWSER_GALEON));
    1062   FAIL_UNLESS("get enum 2", OWL_WEBBROWSER_GALEON==owl_variable_get_int(&vd,"webbrowser"));
    1063   FAIL_UNLESS("set enum 1b", -1==owl_variable_set_int(&vd,"webbrowser",-3));
    1064   FAIL_UNLESS("set enum 1b", -1==owl_variable_set_int(&vd,"webbrowser",209));
    1065   FAIL_UNLESS("get enum 2b", OWL_WEBBROWSER_GALEON==owl_variable_get_int(&vd,"webbrowser"));
    1066   FAIL_UNLESS("set enum 3", 0==owl_variable_set_fromstring(&vd,"webbrowser","none",0,0));
    1067   FAIL_UNLESS("get enum 4", OWL_WEBBROWSER_NONE==owl_variable_get_int(&vd,"webbrowser"));
    1068   FAIL_UNLESS("set enum 5", 0==owl_variable_set_fromstring(&vd,"webbrowser","netscape",0,0));
    1069   FAIL_UNLESS("get enum 6", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
    1070   FAIL_UNLESS("set enum 7", -1==owl_variable_set_fromstring(&vd,"webbrowser","xxx",0,0));
    1071   FAIL_UNLESS("set enum 8", -1==owl_variable_set_fromstring(&vd,"webbrowser","",0,0));
    1072   FAIL_UNLESS("set enum 9", -1==owl_variable_set_fromstring(&vd,"webbrowser","netscapey",0,0));
    1073   FAIL_UNLESS("get enum 10", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));
    1074 
    10751052  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
    10761053  FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING)));
  • wcwidth.c

    r47519e1b r49a8434  
    6262#include <wchar.h>
    6363
    64 static struct interval {
     64struct interval {               /* noproto */
    6565  int first;
    6666  int last;
  • zcrypt.c

    r34509d5 rf34dd65  
    6666#define M_RANDOMIZE       4
    6767#define M_SETKEY          5
    68 
    69 int zcrypt(int argc, char *argv[]) {
    70   char *fname = NULL;
    71   int error = FALSE;
    72   int zephyr = FALSE;
    73   char *class = NULL, *instance = NULL;
    74   int mode = M_NONE;
    75 
    76   extern int optind, opterr;
    77   extern char *optarg;
    78   char c;
    79 
    80   int messageflag = FALSE;
    81   ZWRITEOPTIONS zoptions;
    82   zoptions.flags = 0;
    83 
    84   while ((c = getopt(argc, argv, "ZDERSF:c:i:advqtluons:f:m")) != (char)EOF) {
    85     switch(c) {
    86       case 'Z':
    87         /* Zephyr encrypt */
    88         mode = M_ZEPHYR_ENCRYPT;
    89         break;
    90       case 'D':
    91         /* Decrypt */
    92         mode = M_DECRYPT;
    93         break;
    94       case 'E':
    95         /* Encrypt */
    96         mode = M_ENCRYPT;
    97         break;
    98       case 'R':
    99         /* Randomize the keyfile */
    100         mode = M_RANDOMIZE;
    101         break;
    102       case 'S':
    103         /* Set a new key value from stdin */
    104         mode = M_SETKEY;
    105         break;
    106       case 'F':
    107         /* Specify the keyfile explicitly */
    108         if (fname != NULL) error = TRUE;
    109         fname = optarg;
    110         break;
    111       case 'c':
    112         /* Zwrite/zcrypt: class name */
    113         if (class != NULL) error = TRUE;
    114         class = optarg;
    115         break;
    116       case 'i':
    117         /* Zwrite/zcrypt: instance name */
    118         if (instance != NULL) error = TRUE;
    119         instance = optarg;
    120         break;
    121       case 'a':
    122         /* Zwrite: authenticate (default) */
    123         zoptions.flags &= ~ZWRITE_OPT_NOAUTH;
    124         break;
    125       case 'd':
    126         /* Zwrite: do not authenticate */
    127         zoptions.flags |= ZWRITE_OPT_NOAUTH;
    128         break;
    129       case 'v':
    130         /* Zwrite: verbose */
    131         zoptions.flags |= ZWRITE_OPT_VERBOSE;
    132         break;
    133       case 'q':
    134         /* Zwrite: quiet */
    135         zoptions.flags |= ZWRITE_OPT_QUIET;
    136         break;
    137       case 't':
    138         /* Zwrite: no expand tabs (ignored) */
    139         break;
    140       case 'l':
    141         /* Zwrite: ignore '.' on a line by itself (ignored) */
    142         zoptions.flags |= ZCRYPT_OPT_IGNOREDOT;
    143         break;
    144       case 'u':
    145         /* Zwrite: urgent message */
    146         instance = "URGENT";
    147         break;
    148       case 'o':
    149         /* Zwrite: ignore zephyr variables zwrite-class, zwrite-inst, */
    150         /*         zwrite-opcode */
    151         zoptions.flags |= ZWRITE_OPT_IGNOREVARS;
    152         break;
    153       case 'n':
    154         /* Zwrite: prevent PING message (always used) */
    155         break;
    156       case 's':
    157         /* Zwrite: signature */
    158         zoptions.flags |= ZWRITE_OPT_SIGNATURE;
    159         zoptions.signature = optarg;
    160         break;
    161       case 'f':
    162         /* Zwrite: file system specification (ignored) */
    163         break;
    164       case 'm':
    165         /* Message on rest of line */
    166         messageflag = TRUE;
    167         break;
    168       case '?':
    169         error = TRUE;
    170         break;
    171     }
    172     if (error || messageflag) break;
    173   }
    174 
    175   if (class != NULL || instance != NULL) {
    176     zephyr = TRUE;
    177   }
    178 
    179   if (messageflag) {
    180     zoptions.flags |= ZCRYPT_OPT_MESSAGE;
    181     zoptions.message = BuildArgString(argv, optind, argc);
    182     if (!zoptions.message)
    183     {
    184       printf("Memory allocation error.\n");
    185       error = TRUE;
    186     }
    187   } else if (optind < argc) {
    188     error = TRUE;
    189   }
    190 
    191   if (mode == M_NONE) mode = (zephyr?M_ZEPHYR_ENCRYPT:M_ENCRYPT);
    192 
    193   if (mode == M_ZEPHYR_ENCRYPT && !zephyr) error = TRUE;
    194 
    195   if (!error && fname == NULL && (class != NULL || instance != NULL)) {
    196     fname = GetZephyrVarKeyFile(argv[0], class, instance);
    197   }
    198 
    199  
    200   if (error || fname == NULL) {
    201     printf("Usage: %s [-Z|-D|-E|-R|-S] [-F Keyfile] [-c class] [-i instance]\n", argv[0]);
    202     printf("       [-advqtluon] [-s signature] [-f arg] [-m message]\n");
    203     printf("  One or more of class, instance, and keyfile must be specified.\n");
    204   } else {
    205     if (mode == M_RANDOMIZE) {
    206       /* Choose a new, random key */
    207 /*
    208       FILE *fkey = fopen(fname, "w");
    209       if (!fkey)
    210         printf("Could not open key file for writing: %s\n", fname);
    211       else
    212       {
    213         char string[100];
    214         fputs(fkey, string);
    215         fclose(fkey);
    216         }
    217  */
    218       printf("Feature not yet implemented.\n");
    219     } else if (mode == M_SETKEY) {
    220       /* Set a new, user-entered key */
    221       char newkey[MAX_KEY];
    222       FILE *fkey;
    223      
    224       if (isatty(0)) {
    225         printf("Enter new key: ");
    226         /* Really should read without echo!!! */
    227         fgets(newkey, MAX_KEY - 1, stdin);
    228       } else {
    229         fgets(newkey, MAX_KEY - 1, stdin);
    230       }
    231 
    232       fkey = fopen(fname, "w");
    233       if (!fkey) {
    234         printf("Could not open key file for writing: %s\n", fname);
    235       } else {
    236         if (fputs(newkey, fkey) != strlen(newkey) || putc('\n', fkey) != '\n') {
    237           printf("Error writing to key file.\n");
    238           fclose(fkey);
    239         } else {
    240           fclose(fkey);
    241           printf("Key update complete.\n");
    242         }
    243       }
    244     } else {
    245       /* Encrypt/decrypt */
    246       FILE *fkey = fopen(fname, "r");
    247       if (!fkey) {
    248         printf("Could not open key file: %s\n", fname);
    249       } else {
    250         char keystring[MAX_KEY];
    251         fgets(keystring, MAX_KEY-1, fkey);
    252         if (mode == M_ZEPHYR_ENCRYPT || mode == M_ENCRYPT) {
    253           do_encrypt(keystring, (mode == M_ZEPHYR_ENCRYPT), class, instance,
    254                      &zoptions, fname);
    255         } else {
    256           do_decrypt(keystring);
    257         }
    258         fclose(fkey);
    259       }
    260     }
    261   }
    262 
    263   /* Always print the **END** message if -D is specified. */
    264   if (mode == M_DECRYPT) printf("**END**\n");
    265 
    266   exit(0);
    267 }
    26868
    26969/* The 'owl_zcrypt_decrypt' function was written by kretch for Owl.
     
    375175
    376176    for (i = 0; i < 8; i++) {
    377       sprintf(out, "%s%c", out, ((output[i] & 0xf0) >> 4) + BASE_CODE);
    378       sprintf(out, "%s%c", out, (output[i] & 0x0f)        + BASE_CODE);
     177      sprintf(out + strlen(out), "%c", ((output[i] & 0xf0) >> 4) + BASE_CODE);
     178      sprintf(out + strlen(out), "%c", (output[i] & 0x0f)        + BASE_CODE);
    379179    }
    380180
     
    384184}
    385185
    386 /* Build a space-separated string from argv from elements between start  *
    387  * and end - 1.  owl_malloc()'s the returned string. */
    388 char *BuildArgString(char **argv, int start, int end) {
    389   int len = 1;
    390   int i;
    391   char *result;
    392 
    393   /* Compute the length of the string.  (Plus 1 or 2) */
    394   for (i = start; i < end; i++) {
    395     len += strlen(argv[i]) + 1;
    396   }
    397 
    398   /* Allocate memory */
    399   result = (char *)owl_malloc(len);
    400   if (result) {
    401     /* Build the string */
    402     char *ptr = result;
    403     /* Start with an empty string, in case nothing is copied. */
    404     *ptr = '\0';
    405     /* Copy the arguments */
    406     for (i = start; i < end; i++) {
    407       char *temp = argv[i];
    408       /* Add a space, if not the first argument */
    409       if (i != start) *ptr++ = ' ';
    410       /* Copy argv[i], leaving ptr pointing to the '\0' copied from temp */
    411       while ((*ptr = *temp++)!=0) {
    412         ptr++;
    413       }
    414     }
    415   }
    416 
    417   return(result);
    418 }
    419186
    420187#define MAX_BUFF 258
     
    423190char *GetZephyrVarKeyFile(char *whoami, char *class, char *instance) {
    424191  char *keyfile = NULL;
    425   char varname[MAX_SEARCH][128];
     192  char *varname[MAX_SEARCH];
    426193  int length[MAX_SEARCH], i;
    427194  char buffer[MAX_BUFF];
    428   char filename[MAX_BUFF];
     195  char *filename;
    429196  char result[MAX_SEARCH][MAX_BUFF];
    430197  int numsearch = 0;
    431198  FILE *fsearch;
    432199
     200  memset(varname, 0, sizeof(varname));
     201
    433202  /* Determine names to look for in .crypt-table */
    434203  if (instance) {
    435     sprintf(varname[numsearch++], "crypt-%s-%s:", (class?class:"message"), instance);
     204    varname[numsearch++] = owl_sprintf("crypt-%s-%s:", (class?class:"message"), instance);
    436205  }
    437206  if (class) {
    438     sprintf(varname[numsearch++], "crypt-%s:", class);
    439   }
    440   sprintf(varname[numsearch++], "crypt-default:");
     207    varname[numsearch++] = owl_sprintf("crypt-%s:", class);
     208  }
     209  varname[numsearch++] = owl_strdup("crypt-default:");
    441210
    442211  /* Setup the result array, and determine string lengths */
     
    447216
    448217  /* Open~/.crypt-table */
    449   sprintf(filename, "%s/.crypt-table", getenv("HOME"));
     218  filename = owl_sprintf("%s/.crypt-table", getenv("HOME"));
    450219  fsearch = fopen(filename, "r");
    451220  if (fsearch) {
     
    495264  }
    496265
     266  for(i = 0; i < MAX_SEARCH; i++) {
     267    owl_free(varname[i]);
     268  }
     269
     270  owl_free(filename);
     271
    497272  return(keyfile);
    498273}
     
    500275static pid_t zephyrpipe_pid = 0;
    501276
    502 /* Open a pipe to zwrite */
    503 static FILE *GetZephyrPipe(char *class, char *instance, ZWRITEOPTIONS *zoptions) {
    504   int fildes[2];
    505   pid_t pid;
    506   FILE *result;
    507   char *argv[20];
    508   int argc = 0;
    509 
    510   if (pipe(fildes) < 0) return(NULL);
    511   pid = fork();
    512 
    513   if (pid < 0) {
    514     /* Error: clean up */
    515     close(fildes[0]);
    516     close(fildes[1]);
    517     result = NULL;
    518   } else if (pid == 0) {
    519     /* Setup child process */
    520     argv[argc++] = "zwrite";
    521     argv[argc++] = "-n";     /* Always send without ping */
    522     if (class) {
    523       argv[argc++] = "-c";
    524       argv[argc++] = class;
    525     }
    526     if (instance) {
    527       argv[argc++] = "-i";
    528       argv[argc++] = instance;
    529     }
    530     if (zoptions->flags & ZWRITE_OPT_NOAUTH) argv[argc++] = "-d";
    531     if (zoptions->flags & ZWRITE_OPT_QUIET) argv[argc++] = "-q";
    532     if (zoptions->flags & ZWRITE_OPT_VERBOSE) argv[argc++] = "-v";
    533     if (zoptions->flags & ZWRITE_OPT_SIGNATURE) {
    534       argv[argc++] = "-s";
    535       argv[argc++] = zoptions->signature;
    536     }
    537     argv[argc++] = "-O";
    538     argv[argc++] = "crypt";
    539     argv[argc] = NULL;
    540     close(fildes[1]);
    541     if (fildes[0] != STDIN_FILENO) {
    542       if (dup2(fildes[0], STDIN_FILENO) != STDIN_FILENO) exit(0);
    543       close(fildes[0]);
    544     }
    545     close(fildes[0]);
    546     execvp(argv[0], argv);
    547     printf("Exec error: could not run zwrite\n");
    548     exit(0);
    549   } else {
    550     close(fildes[0]);
    551     /* Create a FILE * for the zwrite pipe */
    552     result = (FILE *)fdopen(fildes[1], "w");
    553     zephyrpipe_pid = pid;
    554   }
    555 
    556   return(result);
    557 }
    558 
    559 /* Close the pipe to zwrite */
    560 void CloseZephyrPipe(FILE *pipe) {
    561   fclose(pipe);
    562   waitpid(zephyrpipe_pid, NULL, 0);
    563   zephyrpipe_pid = 0;
    564 }
    565 
    566 #define MAX_RESULT 2048
    567 
    568 
    569 void block_to_ascii(char *output, FILE *outfile) {
    570   int i;
    571   for (i = 0; i < 8; i++) {
    572     putc(((output[i] & 0xf0) >> 4) + BASE_CODE, outfile);
    573     putc( (output[i] & 0x0f)       + BASE_CODE, outfile);
    574   }
    575 }
    576 
    577 #define MAX_LINE 128
    578 
    579 /* Encrypt stdin, with prompt if isatty, and send to stdout, or to zwrite
    580    if zephyr is set. */
    581 static int do_encrypt(char *keystring, int zephyr, char *class, char *instance, ZWRITEOPTIONS *zoptions, char* keyfile) {
    582   des_cblock key;
    583   des_key_schedule schedule;
    584   char input[8], output[8];
    585   int size;
    586   FILE *outfile = stdout;
    587   int error = FALSE;
    588   char *inbuff = NULL, *inptr;
    589   int freein = FALSE;
    590   int use_buffer = FALSE;
    591   int num_blocks=0, last_block_size=0;
    592 
    593   des_string_to_key(keystring, key);
    594   des_key_sched(key, schedule);
    595 
    596   if (zephyr) {
    597     if (zoptions->flags & ZCRYPT_OPT_MESSAGE) {
    598       /* Use the -m message */
    599       int length;
    600       inbuff = zoptions->message;     
    601       length = strlen(inbuff);
    602       num_blocks = (length + 7) / 8;
    603       last_block_size = ((length + 7) % 8) + 1;
    604       use_buffer = TRUE;
    605     } else if (isatty(0)) {
    606       /* tty input, so show the "Type your message now..." message */
    607       if (zoptions->flags & ZCRYPT_OPT_IGNOREDOT) {
    608         printf("Type your message now.  End with the end-of-file character.\n");
    609       } else {
    610         printf("Type your message now.  End with control-D or a dot on a line by itself.\n");
    611       }
    612       use_buffer = TRUE;
    613       if ((inptr = inbuff = (char *)owl_malloc(MAX_RESULT)) == NULL) {
    614         printf("Memory allocation error\n");
    615         return FALSE;
    616       }
    617       while (inptr - inbuff < MAX_RESULT - MAX_LINE - 20) {
    618         fgets(inptr, MAX_LINE, stdin);
    619         if (inptr[0]) {
    620           if (inptr[0] == '.' && inptr[1] == '\n' &&
    621               !(zoptions->flags & ZCRYPT_OPT_IGNOREDOT)) {
    622             inptr[0] = '\0';
    623             break;
    624           } else {
    625             inptr += strlen(inptr);
    626           }
    627         } else {
    628           break;
    629         }
    630       }
    631       num_blocks = (inptr - inbuff + 7) / 8;
    632       last_block_size = ((inptr - inbuff + 7) % 8) + 1;
    633       freein = TRUE;
    634     }
    635 
    636     /* if (zephyr) */
    637     outfile = GetZephyrPipe(class, instance, zoptions);
    638     if (!outfile) {
    639       printf("Could not run zwrite\n");
    640       if (freein && inbuff) {
    641         owl_free(inbuff);
    642       }
    643       return(FALSE);
    644     }
    645   }
    646 
    647   inptr = inbuff;
    648 
    649   /* Encrypt the input (inbuff or stdin) and send it to outfile */
    650   while (TRUE) {
    651     if (use_buffer) {
    652       /* Get 8 bytes from buffer */
    653       if (num_blocks > 1) {
    654         size = 8;
    655         memcpy(input, inptr, size);
    656         inptr += 8;
    657         num_blocks--;
    658       } else if (num_blocks == 1) {
    659         size = last_block_size;
    660         memcpy(input, inptr, size);
    661         num_blocks--;
    662       } else {
    663         size = 0;
    664       }
    665     } else {
    666       /* Get 8 bytes from stdin */
    667       size = fread(input, 1, 8, stdin);
    668     }
    669 
    670     /* Check for EOF and pad the string to 8 chars, if needed */
    671     if (size == 0) break;     /* END OF INPUT: BREAK FROM while LOOP! */
    672      
    673     if (size < 8) memset(input + size, 0, 8 - size);
    674 
    675     /* Encrypt and output the block */
    676     des_ecb_encrypt(input, output, schedule, TRUE);
    677     block_to_ascii(output, outfile);
    678 
    679     if (size < 8) break;
    680   }
    681 
    682   /* Close out the output */
    683   if (!error) putc('\n', outfile);
    684   if (zephyr) CloseZephyrPipe(outfile);
    685 
    686   /* Free the input buffer, if necessary */
    687   if (freein && inbuff) owl_free(inbuff);
    688 
    689   return(!error);
    690 }
    691 
    692 /* Read a half-byte from stdin, skipping invalid characters.  Returns -1
    693    if at EOF or file error */
    694 int read_ascii_nybble() {
    695   char c;
    696 
    697   while (TRUE) {
    698     if (fread(&c, 1, 1, stdin) == 0) {
    699       return(-1);
    700     } else if (c >= BASE_CODE && c <= LAST_CODE) {
    701       return(c - BASE_CODE);
    702     }
    703   }
    704 }
    705 
    706 /* Read both halves of the byte and return the single byte.  Returns -1
    707    if at EOF or file error. */
    708 int read_ascii_byte() {
    709   int c1, c2;
    710   c1 = read_ascii_nybble();
    711   if (c1 >= 0) {
    712     c2 = read_ascii_nybble();
    713     if (c2 >= 0) {
    714       return c1 * 0x10 + c2;
    715     }
    716   }
    717   return(-1);
    718 }
    719 
    720 /* Read an 8-byte DES block from stdin */
    721 int read_ascii_block(char *input) {
    722   int c, i;
    723 
    724   for (i = 0; i < 8; i++) {
    725     c = read_ascii_byte();
    726     if (c < 0) return(FALSE);
    727     input[i] = c;
    728   }
    729 
    730   return(TRUE);
    731 }
    732 
    733 /* Decrypt stdin */
    734 int do_decrypt(char *keystring) {
    735   des_cblock key;
    736   des_key_schedule schedule;
    737   char input[8], output[9];
    738 
    739   output[0] = '\0';    /* In case no message at all                 */
    740   output[8] = '\0';    /* NULL at end will limit string length to 8 */
    741 
    742   des_string_to_key(keystring, key);
    743   des_key_sched(key, schedule);
    744 
    745   while (read_ascii_block(input)) {
    746     des_ecb_encrypt(input, output, schedule, FALSE);
    747     printf("%s", output);
    748   }
    749 
    750   if (output[0]) {
    751     if (output[strlen(output)-1] != '\n') {
    752       printf("\n");
    753     }
    754   } else {
    755     printf("\n");
    756   }
    757   return(0);
    758 }
    759 
    760 #endif
     277#endif
  • zephyr.c

    r451db9e re2a620b  
    516516  }
    517517  /* deal with MIT Discuss messages */
    518   else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4")) {
     518  else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4") ||
     519           !strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4")) {
    519520    char *msg, *field1, *field2, *field3, *field4, *field5;
    520521   
     
    814815    ZGetLocations(&locations,&one);
    815816    myuser=short_zuser(user);
    816     sprintf(out, "%s%s: %s\t%s\t%s\n", out, myuser,
     817    sprintf(out + strlen(out), "%s: %s\t%s\t%s\n", myuser,
    817818            locations.host ? locations.host : "?",
    818819            locations.tty ? locations.tty : "?",
     
    12031204
    12041205#ifdef HAVE_LIBZEPHYR
    1205 void owl_zephyr_process_events() {
     1206void owl_zephyr_process_events(owl_dispatch *d) {
    12061207  int zpendcount=0;
    12071208  ZNotice_t notice;
     
    12351236
    12361237#else
    1237 void owl_zephyr_process_events() {
    1238  
    1239 }
    1240 #endif
     1238void owl_zephyr_process_events(owl_dispatch *d) {
     1239 
     1240}
     1241#endif
  • zwrite.c

    r3f3ee61 r823671c  
    195195{
    196196  int i, j;
    197   char to[LINE];
     197  char *to;
    198198
    199199  if (z->noping) return;
     
    209209  for (i=0; i<j; i++) {
    210210    if (strcmp(z->realm, "")) {
    211       sprintf(to, "%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
     211      to = owl_sprintf("%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
    212212    } else {
    213       strcpy(to, owl_list_get_element(&(z->recips), i));
     213      to = owl_strdup(owl_list_get_element(&(z->recips), i));
    214214    }
    215215    send_ping(to);
     216    owl_free(to);
    216217  }
    217218
     
    221222{
    222223  int i, j;
    223   char toline[LINE];
     224  char *toline = NULL;
    224225  char *tmp = NULL;
    225226
     
    228229  j=owl_list_get_size(&(z->recips));
    229230  if (j>0 && z->cc) {
    230     strcpy(toline, "CC: ");
     231    toline = owl_strdup( "CC: ");
    231232    for (i=0; i<j; i++) {
     233      tmp = toline;
    232234      if (strcmp(z->realm, "")) {
    233         sprintf(toline, "%s%s@%s ", toline, (char *) owl_list_get_element(&(z->recips), i), z->realm);
     235        toline = owl_sprintf( "%s%s@%s ", toline, (char *) owl_list_get_element(&(z->recips), i), z->realm);
    234236      } else {
    235         sprintf(toline, "%s%s ", toline, (char *) owl_list_get_element(&(z->recips), i));
    236       }
     237        toline = owl_sprintf( "%s%s ", toline, (char *) owl_list_get_element(&(z->recips), i));
     238      }
     239      owl_free(tmp);
     240      tmp = NULL;
    237241    }
    238242    tmp = owl_get_iso_8859_1_if_possible(msg);
    239243    z->message=owl_sprintf("%s\n%s", toline, tmp);
     244    owl_free(toline);
    240245  } else {
    241246    z->message=owl_get_iso_8859_1_if_possible(msg);
     
    259264{
    260265  int i, j;
    261   char to[LINE];
     266  char *to = NULL;
    262267
    263268  if (z->message==NULL) return(-1);
     
    267272    for (i=0; i<j; i++) {
    268273      if (strcmp(z->realm, "")) {
    269         sprintf(to, "%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
     274        to = owl_sprintf("%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
    270275      } else {
    271         strcpy(to, owl_list_get_element(&(z->recips), i));
     276        to = owl_strdup( owl_list_get_element(&(z->recips), i));
    272277      }
    273278      send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
     279      owl_free(to);
     280      to = NULL;
    274281    }
    275282  } else {
    276     sprintf(to, "@%s", z->realm);
     283    to = owl_sprintf( "@%s", z->realm);
    277284    send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
    278285  }
     286  owl_free(to);
    279287  return(0);
    280288}
Note: See TracChangeset for help on using the changeset viewer.