Changeset dab82f29 for owl.c


Ignore:
Timestamp:
Mar 28, 2009, 5:00:34 PM (15 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
owl
Children:
4de643d
Parents:
5189631
Message:
Don't crash on mobile device AIM messages [BZ 20]
Don't crash when sending to someone not on AIM buddy list [BZ 94]
Fix overflow vulerability in zwrite.c and zcrypt.c
Add stack protector and -D_FORTIFY_SOURCE=2 where possible
Fix hang [barnowl 4c46dfdebc294ca24fef59924f01688b8ee07dee]
Fix segfault on missing subs [barnowl 99dabeed7de6d19acb50f1e73aa0bfe5f9469c02]
Fix zcrypt bufffer size bug [barnowl 559076cd86edc3a8317819814dd5877b8bc7c3cb]
Fix double free [barnowl e97c4a306ae2c9d2147d83da29fee59918198e70]
Memory leak fix [barnowl c0a90c2c7ab97b9465c9873757faf312faa0021e]
Memory leak fix [barnowl 95caa16b2e9ba10770d87d0955198c14c2d0e16a]
Memory leak fix [barnowl 1716fed8c2650e46892cf6571555eac937266c6e]
Add getstyle command [barnowl 216c73421653e3ef0e957aa9a9804e208a77c80e]
Binary search for msgid [barnowl 0c8ab5eadbb6ecc97a120c91b9a824b33538c764]
File-handle leak [barnowl e78397d6ac5da0de31a4e269c0ba7f3d691857a3]
Fix delay in jump from top to bottom [barnowl 801b7ac63b962640debbcfd422cb9a60da5fea31]
Load subs in chunks [barnowl 93e883d60051b80bf6d35391f9d76fd7dfd198e3]
Load subs in chunks [barnowl f6050ee9b0a171a5031f84409eb181062afacd18]
Better zsig logging [barnowl d857b667a5a9b108b1a2a26b4a5513bef2b53f80]
free() -> owlfree() [barnowl d524c838ac7c115628424b8ac171c3489622ea3a]
Escape AIM users in smartfilters [barnowl af9b92e3e7ccb7de276a94b5c7e5861b24e71eff]
Better regex escape chars [barnowl 80e54a7631f091be8c9762adb9746bad38104738]
Deal with quotes in smart filters [barnowl 4099cf83702763fa8d1efc4f1582a605431bdb77]
Deal with 0 length zephyr fields [barnowl 128171aaf7cefa91a4bb1eada93a19d8fd0c355c]
Deal with 0 length zephyr fields [barnowl 50e29e35c64d64e223d378d350a7bc4f038d78f5]
Deal with 0 length zephyr fields [barnowl 804ab8af8b6d00bcd7e2402df892db8fbd61a3ec]
Leave curmsg on screen after resize [barnowl c0f9e3009bc03e80a44de64cd5f2b4033290236e]
Rip out brower stuff [barnowl 8e5935d11c699a7ce5a3e6e9a47799564c696d6a]
Rip out browser stuff [barnowl 4f15e8e9ceada0d4b2cc969ebf43b0a1fb3709ea]
No passwords in command history [barnowl 6e400cc71aa59e041dce677aadf50dc1f25228e2]
Format NOC mssages [barnowl a1bb1980e4bca23b8329cc0e7c0bd5027055ea0a]
Expand ~ in loadsubs [barnowl 27d8d835dc6d58c08fae10e75aae306c49215143]
Expand ~ in source [barnowl 10d67d57cb29221f63a43a30643c697fc7b38911]
Only use resizeterm() if it's available
Debian backports
Change license to GPLv3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r176d3443 rdab82f29  
    1 /*  Copyright (c) 2004 James Kretchmar. All rights reserved.
     1/* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar
    22 *
    3  *  Redistribution and use in source and binary forms, with or without
    4  *  modification, are permitted provided that the following conditions are
    5  *  met:
    6  * 
    7  *    * Redistributions of source code must retain the above copyright
    8  *      notice, this list of conditions and the following disclaimer.
    9  * 
    10  *    * Redistributions in binary form must reproduce the above copyright
    11  *      notice, this list of conditions and the following disclaimer in
    12  *      the documentation and/or other materials provided with the
    13  *      distribution.
    14  * 
    15  *    * Redistributions in any form must be accompanied by information on
    16  *      how to obtain complete source code for the Owl software and any
    17  *      accompanying software that uses the Owl software. The source code
    18  *      must either be included in the distribution or be available for no
    19  *      more than the cost of distribution plus a nominal fee, and must be
    20  *      freely redistributable under reasonable conditions. For an
    21  *      executable file, complete source code means the source code for
    22  *      all modules it contains. It does not include source code for
    23  *      modules or files that typically accompany the major components of
    24  *      the operating system on which the executable file runs.
    25  * 
     3 * This file is part of Owl.
     4 *
     5 * Owl is free software: you can redistribute it and/or modify
     6 * it under the terms of the GNU General Public License as published by
     7 * the Free Software Foundation, either version 3 of the License, or
     8 * (at your option) any later version.
     9 *
     10 * Owl is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 * GNU General Public License for more details.
     14 *
     15 * You should have received a copy of the GNU General Public License
     16 * along with Owl.  If not, see <http://www.gnu.org/licenses/>.
     17 *
     18 * ---------------------------------------------------------------
    2619 *
    27  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    28  *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    29  *  WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
    30  *  NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
    31  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    32  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    33  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
    34  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    35  *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    36  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
    37  *  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     20 * As of Owl version 2.1.12 there are patches contributed by
     21 * developers of the the branched BarnOwl project, Copyright (c)
     22 * 2006-2008 The BarnOwl Developers. All rights reserved.
    3823 */
    3924
     
    6045#endif
    6146
     47#define STDIN 0
     48
    6249static const char fileIdent[] = "$Id$";
    6350
     
    6956  owl_editwin *tw;
    7057  owl_popwin *pw;
    71   int j, ret, initialsubs, debug, argcsave, followlast;
    72   int newmsgs, zpendcount, nexttimediff;
     58  int ret, initialsubs, debug, argcsave, followlast;
     59  int newmsgs, nexttimediff;
    7360  struct sigaction sigact;
    7461  char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
     
    7966  char *dir;
    8067  struct termios tio;
    81 #ifdef HAVE_LIBZEPHYR
    82   ZNotice_t notice;
    83 #endif
    8468#if OWL_STDERR_REDIR
    8569  int newstderr;
     
    200184  owl_function_debugmsg("startup: first available debugging message");
    201185  owl_global_set_startupargs(&g, argcsave, argvsave);
     186  owl_global_set_haveaim(&g);
     187
     188  /* prepare stdin dispatch */
     189  {
     190    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     191    owl_function_debugmsg("startup: creating input selector");
     192    d->fd = STDIN;
     193    d->cfunc = &owl_process_input;
     194    d->destroy = NULL;
     195    owl_select_add_dispatch(d);
     196  }
     197
    202198#ifdef HAVE_LIBZEPHYR
    203199  owl_global_set_havezephyr(&g);
     200  if (!ret) {
     201    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     202    owl_function_debugmsg("startup: creating zephyr selector");
     203    d->fd = ZGetFD();
     204    d->cfunc = &owl_zephyr_process_events;
     205    d->destroy = NULL;
     206    owl_select_add_dispatch(d);
     207    owl_global_set_havezephyr(&g);
     208  }
    204209#endif
    205   owl_global_set_haveaim(&g);
    206210
    207211#if OWL_STDERR_REDIR
    208212  /* Do this only after we've started curses up... */
    209   owl_function_debugmsg("startup: doing stderr redirection");
    210   newstderr = stderr_replace();
    211   owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ,
    212                     stderr_redirect_handler, NULL);
     213  {
     214    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     215    owl_function_debugmsg("startup: doing stderr redirection");
     216    d->fd = stderr_replace();
     217    d->cfunc = stderr_redirect_handler;
     218    d->destroy = NULL;
     219    owl_function_debugmsg("testing: 1");
     220    owl_select_add_dispatch(d);
     221    owl_function_debugmsg("testing: 2");
     222  }
     223
    213224#endif   
    214225
     
    463474    /* Grab incoming messages. */
    464475    newmsgs=0;
    465     zpendcount=0;
    466     while(owl_zephyr_zpending() || owl_global_messagequeue_pending(&g)) {
    467 #ifdef HAVE_LIBZEPHYR
    468       struct sockaddr_in from;
    469 #endif
     476    while(owl_global_messagequeue_pending(&g)) {
    470477      owl_message *m=NULL;
    471478      owl_filter *f;
    472479
    473       /* grab the new message, stick it in 'm' */
    474       if (owl_zephyr_zpending()) {
    475 #ifdef HAVE_LIBZEPHYR
    476         /* grab a zephyr notice, but if we've done 20 without stopping,
    477            take a break to process keystrokes etc. */
    478         if (zpendcount>20) break;
    479         ZReceiveNotice(&notice, &from);
    480         zpendcount++;
    481        
    482         /* is this an ack from a zephyr we sent? */
    483         if (owl_zephyr_notice_is_ack(&notice)) {
    484           owl_zephyr_handle_ack(&notice);
    485           continue;
    486         }
    487        
    488         /* if it's a ping and we're not viewing pings then skip it */
    489         if (!owl_global_is_rxping(&g) && !strcasecmp(notice.z_opcode, "ping")) {
    490           continue;
    491         }
    492 
    493         /* create the new message */
    494         m=owl_malloc(sizeof(owl_message));
    495         owl_message_create_from_znotice(m, &notice);
    496 #endif
    497       } else if (owl_global_messagequeue_pending(&g)) {
    498         /* pick up the non-zephyr message in the message queue */
    499         m=owl_global_messageuque_popmsg(&g);
    500       } else {
    501         /* Not supposed to happen, but we seem to get here on resizes */
    502         owl_function_debugmsg("Bottomed out looking for zephyr");
    503       }
    504 
    505       /* If we didn't pick up a message for some reason, don't go on */
    506       if (m==NULL) {
    507         owl_function_debugmsg("m is null in main loop");
    508         continue;
    509       }
     480      m=owl_global_messageuque_popmsg(&g);
    510481     
    511482      /* if this message it on the puntlist, nuke it and continue */
     
    599570    }
    600571
    601     /* dispatch any muxevents */
    602     owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0);
    603 
    604572    /* follow the last message if we're supposed to */
    605573    if (newmsgs && followlast) {
     
    651619    }
    652620
    653     /* Handle all keypresses.  If no key has been pressed, sleep for a
    654      * little bit, but otherwise do not.  This lets input be grabbed
    655      * as quickly as possbile */
    656     j=wgetch(typwin);
    657     if (j==ERR) {
    658       usleep(10);
    659     } else {
    660       /* find and activate the current keymap.
    661        * TODO: this should really get fixed by activating
    662        * keymaps as we switch between windows...
    663        */
    664       if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
    665         owl_context_set_popless(owl_global_get_context(&g),
    666                                 owl_global_get_viewwin(&g));
    667         owl_function_activate_keymap("popless");
    668       } else if (owl_global_is_typwin_active(&g)
    669                  && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
    670         /*
    671           owl_context_set_editline(owl_global_get_context(&g), tw);
    672           owl_function_activate_keymap("editline");
    673         */
    674       } else if (owl_global_is_typwin_active(&g)
    675                  && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
    676         owl_context_set_editmulti(owl_global_get_context(&g), tw);
    677         owl_function_activate_keymap("editmulti");
    678       } else {
    679         owl_context_set_recv(owl_global_get_context(&g));
    680         owl_function_activate_keymap("recv");
    681       }
    682       /* now actually handle the keypress */
    683       ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
    684       if (ret!=0 && ret!=1) {
    685         owl_function_makemsg("Unable to handle keypress");
    686       }
    687     }
     621    /* select on FDs we know about. */
     622    owl_select();
    688623
    689624    /* Log any error signals */
     
    698633    }
    699634
     635  }
     636}
     637
     638void owl_process_input(owl_dispatch *d)
     639{
     640  int ret, j;
     641  owl_popwin *pw;
     642  owl_editwin *tw;
     643  WINDOW *typwin;
     644
     645  typwin = owl_global_get_curs_typwin(&g);
     646  while (1) {
     647    j=wgetch(typwin);
     648    if (j==ERR) return;
     649
     650    pw=owl_global_get_popwin(&g);
     651    tw=owl_global_get_typwin(&g);
     652   
     653    /* find and activate the current keymap.
     654     * TODO: this should really get fixed by activating
     655     * keymaps as we switch between windows...
     656     */
     657    if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
     658      owl_context_set_popless(owl_global_get_context(&g),
     659                              owl_global_get_viewwin(&g));
     660      owl_function_activate_keymap("popless");
     661    } else if (owl_global_is_typwin_active(&g)
     662               && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
     663      /*
     664        owl_context_set_editline(owl_global_get_context(&g), tw);
     665        owl_function_activate_keymap("editline");
     666      */
     667    } else if (owl_global_is_typwin_active(&g)
     668               && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
     669      owl_context_set_editmulti(owl_global_get_context(&g), tw);
     670      owl_function_activate_keymap("editmulti");
     671    } else {
     672      owl_context_set_recv(owl_global_get_context(&g));
     673      owl_function_activate_keymap("recv");
     674    }
     675    /* now actually handle the keypress */
     676    ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
     677    if (ret!=0 && ret!=1) {
     678      owl_function_makemsg("Unable to handle keypress");
     679    }
    700680  }
    701681}
     
    743723    return -1;
    744724  }
    745     owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]);
     725    owl_function_debugmsg("stderr_replace: pipe: %d,%d", pipefds[0], pipefds[1]);
    746726  if (-1 == dup2(pipefds[1], 2 /*stderr*/)) {
    747     owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno));
     727    owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)", strerror(errno));
    748728    perror("dup2");
    749729    return -1;
Note: See TracChangeset for help on using the changeset viewer.