Changeset a006d475
- Timestamp:
- Jun 19, 2011, 12:04:19 AM (13 years ago)
- Parents:
- e93dd78 (diff), 28da2da (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 added
- 42 edited
Legend:
- Unmodified
- Added
- Removed
-
barnowl
rde18326 r9b7b535 7 7 EXE="$0.bin" 8 8 9 if ! test-x "$EXE"; then9 if test ! -x "$EXE"; then 10 10 echo "Cannot find barnowl.bin" >&2 11 11 exit 1 12 12 fi 13 13 14 export BARNOWL_DATA_DIR="$SRCDIR/perl/" 15 export BARNOWL_BIN_DIR="$SRCDIR/" 14 BARNOWL_DATA_DIR="$SRCDIR/perl/" 15 BARNOWL_BIN_DIR="$SRCDIR/" 16 export BARNOWL_DATA_DIR 17 export BARNOWL_BIN_DIR 16 18 exec "$EXE" "$@" -
configure.ac
rf97c1a6 ra006d475 8 8 9 9 AC_PROG_CC 10 AC_PROG_CC_C99 10 11 11 12 AC_ARG_WITH([stack-protector], … … 80 81 AC_HEADER_STDC 81 82 AC_HEADER_SYS_WAIT 82 AC_HEADER_STDBOOL 83 AC_CHECK_HEADERS(strings.h sys/ioctl.h sys/filio.h unistd.h) 83 AC_CHECK_HEADERS(stdbool.h strings.h sys/ioctl.h sys/filio.h unistd.h) 84 84 85 85 dnl Add CFLAGS for embeded perl … … 143 143 test "$HAVE_DES_ECB_ENCRYPT"]) 144 144 145 AM_CFLAGS="$AM_CFLAGS -D_XOPEN_SOURCE= 500"145 AM_CFLAGS="$AM_CFLAGS -D_XOPEN_SOURCE=600" 146 146 dnl Define _BSD_SOURCE because zephyr needs caddr_t. 147 147 AM_CFLAGS="$AM_CFLAGS -D_BSD_SOURCE" -
libfaim/aim.h
r63de71c r28da2da 18 18 19 19 #include "config.h" 20 #ifdef HAVE_STDBOOL_H21 20 #include <stdbool.h> 22 #else23 #ifndef HAVE__BOOL24 #define _Bool signed char25 #endif26 #define bool _Bool27 #define false 028 #define true 129 #define __bool_true_false_are_defined 130 #endif /* HAVE_STDBOOL_H */31 21 32 22 #include <stdio.h> -
owl.h
r33b6431b ra006d475 14 14 #include "compat/compat.h" 15 15 16 #ifdef HAVE_STDBOOL_H17 16 #include <stdbool.h> 18 #else19 #ifndef HAVE__BOOL20 #define _Bool signed char21 #endif22 #define bool _Bool23 #define false 024 #define true 125 #define __bool_true_false_are_defined 126 #endif /* HAVE_STDBOOL_H */27 17 28 18 #ifndef OWL_PERL 19 #define NCURSES_ENABLE_STDBOOL_H 1 29 20 #include <curses.h> 30 21 #include <panel.h> -
scripts/locker-build
r0fd5bd5 rf216307 102 102 esac 103 103 104 C FLAGS="-I$BARNOWL/include" \105 LDFLAGS="-L$BARNOWL/lib $opt_rpath$BARNOWL/lib" \104 CPPFLAGS="-I$BARNOWL/include -I/usr/athena/include" \ 105 LDFLAGS="-L$BARNOWL/lib -L/usr/athena/lib $opt_rpath$BARNOWL/lib" \ 106 106 ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \ 107 107 --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \ -
window.h
r4cc49bc ra006d475 5 5 #include <glib-object.h> 6 6 7 #ifdef HAVE_STDBOOL_H8 7 #include <stdbool.h> 9 #else10 #ifndef HAVE__BOOL11 #define _Bool signed char12 #endif13 #define bool _Bool14 #define false 015 #define true 116 #define __bool_true_false_are_defined 117 #endif /* HAVE_STDBOOL_H */18 8 19 9 G_BEGIN_DECLS -
Makefile.am
rce35060 r3535a6e 45 45 aim.c buddy.c buddylist.c style.c errqueue.c \ 46 46 zbuddylist.c popexec.c select.c wcwidth.c \ 47 glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c 47 glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c signal.c 48 48 49 49 NORMAL_SRCS = filterproc.c window.c windowcb.c -
README
raeadc74 r13ee8f2 18 18 BarnOwl currently requires the following perl modules off of CPAN: 19 19 20 AnyEvent 20 21 PAR 21 22 Net::DNS … … 30 31 The IRC module requires: 31 32 32 Net::IRC33 AnyEvent::IRC 33 34 Class::Accessor 34 35 -
aim.c
r3472845 rdc1edbd 446 446 } 447 447 448 int owl_aim_process_events(void) 449 { 450 aim_session_t *aimsess; 448 int owl_aim_process_events(aim_session_t *aimsess) 449 { 451 450 aim_conn_t *waitingconn = NULL; 452 451 struct timeval tv; … … 454 453 struct owlfaim_priv *priv; 455 454 456 aimsess=owl_global_get_aimsess(&g);457 455 priv = aimsess->aux_data; 458 456 … … 1795 1793 } 1796 1794 1797 void owl_process_aim(void) 1798 { 1799 if (owl_global_is_doaimevents(&g)) { 1800 owl_aim_process_events(); 1801 } 1802 } 1795 typedef struct _owl_aim_event_source { /*noproto*/ 1796 GSource source; 1797 aim_session_t *sess; 1798 GPtrArray *fds; 1799 } owl_aim_event_source; 1800 1801 static void truncate_pollfd_list(owl_aim_event_source *event_source, int len) 1802 { 1803 GPollFD *fd; 1804 int i; 1805 if (len < event_source->fds->len) 1806 owl_function_debugmsg("Truncating AIM PollFDs to %d, was %d", len, event_source->fds->len); 1807 for (i = len; i < event_source->fds->len; i++) { 1808 fd = event_source->fds->pdata[i]; 1809 g_source_remove_poll(&event_source->source, fd); 1810 g_free(fd); 1811 } 1812 g_ptr_array_remove_range(event_source->fds, len, event_source->fds->len - len); 1813 } 1814 1815 static gboolean owl_aim_event_source_prepare(GSource *source, int *timeout) 1816 { 1817 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1818 aim_conn_t *cur; 1819 GPollFD *fd; 1820 int i; 1821 1822 /* AIM HACK: 1823 * 1824 * The problem - I'm not sure where to hook into the owl/faim 1825 * interface to keep track of when the AIM socket(s) open and 1826 * close. In particular, the bosconn thing throws me off. So, 1827 * rather than register particular dispatchers for AIM, I look up 1828 * the relevant FDs and add them to select's watch lists, then 1829 * check for them individually before moving on to the other 1830 * dispatchers. --asedeno 1831 */ 1832 i = 0; 1833 for (cur = event_source->sess->connlist; cur; cur = cur->next) { 1834 if (cur->fd != -1) { 1835 /* Add new GPollFDs as necessary. */ 1836 if (i == event_source->fds->len) { 1837 fd = g_new0(GPollFD, 1); 1838 g_ptr_array_add(event_source->fds, fd); 1839 g_source_add_poll(source, fd); 1840 owl_function_debugmsg("Allocated new AIM PollFD, len = %d", event_source->fds->len); 1841 } 1842 fd = event_source->fds->pdata[i]; 1843 fd->fd = cur->fd; 1844 fd->events |= G_IO_IN | G_IO_HUP | G_IO_ERR; 1845 if (cur->status & AIM_CONN_STATUS_INPROGRESS) { 1846 /* Yes, we're checking writable sockets here. Without it, AIM 1847 login is really slow. */ 1848 fd->events |= G_IO_OUT; 1849 } 1850 i++; 1851 } 1852 } 1853 /* If the number of GPollFDs went down, clean up. */ 1854 truncate_pollfd_list(event_source, i); 1855 1856 *timeout = -1; 1857 return FALSE; 1858 } 1859 1860 static gboolean owl_aim_event_source_check(GSource *source) 1861 { 1862 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1863 int i; 1864 1865 for (i = 0; i < event_source->fds->len; i++) { 1866 GPollFD *fd = event_source->fds->pdata[i]; 1867 if (fd->revents & fd->events) 1868 return TRUE; 1869 } 1870 return FALSE; 1871 } 1872 1873 static gboolean owl_aim_event_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) 1874 { 1875 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1876 owl_aim_process_events(event_source->sess); 1877 return TRUE; 1878 } 1879 1880 static void owl_aim_event_source_finalize(GSource *source) 1881 { 1882 owl_aim_event_source *event_source = (owl_aim_event_source*)source; 1883 truncate_pollfd_list(event_source, 0); 1884 g_ptr_array_free(event_source->fds, TRUE); 1885 } 1886 1887 static GSourceFuncs aim_event_funcs = { 1888 owl_aim_event_source_prepare, 1889 owl_aim_event_source_check, 1890 owl_aim_event_source_dispatch, 1891 owl_aim_event_source_finalize, 1892 }; 1893 1894 GSource *owl_aim_event_source_new(aim_session_t *sess) 1895 { 1896 GSource *source; 1897 owl_aim_event_source *event_source; 1898 1899 source = g_source_new(&aim_event_funcs, sizeof(owl_aim_event_source)); 1900 event_source = (owl_aim_event_source *)source; 1901 event_source->sess = sess; 1902 /* TODO: When we depend on glib 2.22+, use g_ptr_array_new_with_free_func. */ 1903 event_source->fds = g_ptr_array_new(); 1904 return source; 1905 } -
cmd.c
r6a71113 r4c7c21f 12 12 13 13 int owl_cmddict_setup(owl_cmddict *cd) { 14 if (0 != owl_cmddict_init(cd)) return(-1);14 owl_cmddict_init(cd); 15 15 if (0 != owl_cmddict_add_from_list(cd, commands_to_init)) return(-1); 16 16 return(0); 17 17 } 18 18 19 int owl_cmddict_init(owl_cmddict *cd) { 20 if (owl_dict_create(cd)) return(-1); 21 return(0); 19 void owl_cmddict_init(owl_cmddict *cd) { 20 owl_dict_create(cd); 22 21 } 23 22 … … 135 134 void owl_cmd_cleanup(owl_cmd *cmd) 136 135 { 137 if (cmd->name)g_free(cmd->name);138 if (cmd->summary)g_free(cmd->summary);139 if (cmd->usage)g_free(cmd->usage);140 if (cmd->description)g_free(cmd->description);141 if (cmd->cmd_aliased_to)g_free(cmd->cmd_aliased_to);136 g_free(cmd->name); 137 g_free(cmd->summary); 138 g_free(cmd->usage); 139 g_free(cmd->description); 140 g_free(cmd->cmd_aliased_to); 142 141 if (cmd->cmd_perl) owl_perlconfig_cmd_cleanup(cmd); 143 142 } -
commands.c
rc809f5e r697221f 281 281 OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY, 282 282 "suppress an arbitrary filter", 283 "punt <filter- text>",284 "punt <filter-text (multiple words)> \n"283 "punt <filter-name>\n" 284 "punt <filter-text (multiple words)>", 285 285 "The punt command will suppress messages to the specified\n" 286 286 "filter\n\n" … … 289 289 OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY, 290 290 "remove an entry from the punt list", 291 "unpunt < filter-text>\n"292 "unpunt <filter- text>\n"293 "unpunt < number>\n",291 "unpunt <number>\n" 292 "unpunt <filter-name>\n" 293 "unpunt <filter-text (multiple words)>", 294 294 "The unpunt command will remove an entry from the puntlist.\n" 295 "The first two forms correspond to the firsttwo forms of the :punt\n"296 "command. The latter allows you to remove a specific entry from the\n"295 "The last two forms correspond to the two forms of the :punt\n" 296 "command. The first allows you to remove a specific entry from\n" 297 297 "the list (see :show zpunts)\n\n" 298 298 "SEE ALSO: punt, zpunt, zunpunt, show zpunts\n"), … … 1288 1288 } 1289 1289 owl_function_nextmsg_full(filter, skip_deleted, last_if_none); 1290 if (filter)g_free(filter);1290 g_free(filter); 1291 1291 return(NULL); 1292 1292 } … … 1318 1318 } 1319 1319 owl_function_prevmsg_full(filter, skip_deleted, first_if_none); 1320 if (filter)g_free(filter);1320 g_free(filter); 1321 1321 return(NULL); 1322 1322 } … … 1691 1691 commands = g_strsplit_set(newbuff, ";", 0); 1692 1692 for (i = 0; commands[i] != NULL; i++) { 1693 if (lastrv) { 1694 g_free(lastrv); 1695 } 1693 g_free(lastrv); 1696 1694 lastrv = owl_function_command(commands[i]); 1697 1695 } … … 2466 2464 owl_list * fl; 2467 2465 owl_filter * f; 2468 char * text;2469 2466 int i; 2470 2467 … … 2482 2479 return; 2483 2480 } else { 2484 owl_function_ error("No such filter number: %d", i+1);2481 owl_function_makemsg("No such filter number: %d.", i+1); 2485 2482 } 2486 2483 } 2487 text = owl_string_build_quoted("filter %q", argv[1]); 2488 owl_function_punt(text, unpunt); 2489 g_free(text); 2484 const char *filter[] = {"filter", argv[1]}; 2485 owl_function_punt(2, filter, unpunt); 2490 2486 } else { 2491 owl_function_punt(skiptokens(buff, 1), unpunt); 2487 /* Pass in argv[1]..argv[argc-1]. */ 2488 owl_function_punt(argc - 1, argv + 1, unpunt); 2492 2489 } 2493 2490 } -
dict.c
rf25df21 r4c7c21f 15 15 #define GROWBY 3 / 2 16 16 17 intowl_dict_create(owl_dict *d) {17 void owl_dict_create(owl_dict *d) { 18 18 d->size=0; 19 19 d->els=g_new(owl_dict_el, INITSIZE); 20 20 d->avail=INITSIZE; 21 if (d->els==NULL) return(-1);22 return(0);23 21 } 24 22 … … 60 58 /* Appends dictionary keys to a list. Duplicates the keys, 61 59 * so they will need to be freed by the caller. */ 62 intowl_dict_get_keys(const owl_dict *d, owl_list *l) {60 void owl_dict_get_keys(const owl_dict *d, owl_list *l) { 63 61 int i; 64 char *dupk;65 62 for (i=0; i<d->size; i++) { 66 if ((dupk = g_strdup(d->els[i].k)) == NULL) return(-1); 67 owl_list_append_element(l, dupk); 63 owl_list_append_element(l, g_strdup(d->els[i].k)); 68 64 } 69 return(0);70 65 } 71 66 … … 84 79 { 85 80 int pos, found; 86 char *dupk;87 81 found = _owl_dict_find_pos(d, k, &pos); 88 82 if (found && delete_on_replace) { … … 99 93 if (d->els==NULL) return(-1); 100 94 } 101 if ((dupk = g_strdup(k)) == NULL) return(-1);102 95 if (pos!=d->size) { 103 96 /* shift forward to leave us a slot */ … … 106 99 } 107 100 d->size++; 108 d->els[pos].k = dupk;101 d->els[pos].k = g_strdup(k); 109 102 d->els[pos].v = v; 110 103 return(0); -
editwin.c
r47e0a6a r3b8a563 317 317 } 318 318 319 if (locktext) 320 g_free(locktext); 319 g_free(locktext); 321 320 322 321 oe_set_index(e, lock); -
filterproc.c
rd564c3d re2cc848 17 17 int err = 0; 18 18 struct pollfd fds[2]; 19 struct sigaction sig = {.sa_handler = SIG_IGN}, old;20 19 21 20 fcntl(rfd, F_SETFL, O_NONBLOCK | fcntl(rfd, F_GETFL)); … … 27 26 fds[1].events = POLLOUT; 28 27 29 sigaction(SIGPIPE, &sig, &old);30 31 28 while(1) { 32 29 if(out && *out) { … … 67 64 68 65 *in = g_string_free(str, err < 0); 69 sigaction(SIGPIPE, &old, NULL);70 66 return err; 71 67 } -
fmtext.c
r4479497 r7b4f3be 184 184 } 185 185 186 static void _owl_fmtext_update_colorpair(short fg, short bg, short *pair)187 {188 if (owl_global_get_hascolors(&g)) {189 *pair = owl_fmtext_get_colorpair(fg, bg);190 }191 }192 193 186 static void _owl_fmtext_wcolor_set(WINDOW *w, short pair) 194 187 { 195 if ( owl_global_get_hascolors(&g)) {188 if (has_colors()) { 196 189 wcolor_set(w,pair,NULL); 197 190 wbkgdset(w, COLOR_PAIR(pair)); … … 221 214 bg = default_bgcolor; 222 215 _owl_fmtext_wattrset(w, attr); 223 _owl_fmtext_update_colorpair(fg, bg, &pair);216 pair = owl_fmtext_get_colorpair(fg, bg); 224 217 _owl_fmtext_wcolor_set(w, pair); 225 218 … … 270 263 if (bg == OWL_COLOR_DEFAULT) bg = default_bgcolor; 271 264 _owl_fmtext_wattrset(w, attr); 272 _owl_fmtext_update_colorpair(fg, bg, &pair);265 pair = owl_fmtext_get_colorpair(fg, bg); 273 266 _owl_fmtext_wcolor_set(w, pair); 274 267 … … 662 655 continue */ 663 656 } else if (!strcasecmp(buff, "@color") 664 && owl_global_get_hascolors(&g)665 657 && owl_global_is_colorztext(&g)) { 666 658 g_free(buff); … … 820 812 } 821 813 } 822 if ( owl_global_get_hascolors(&g)) {814 if (has_colors()) { 823 815 for(i = 0; i < 8; i++) { 824 816 short fg, bg; … … 835 827 owl_colorpair_mgr *cpmgr; 836 828 short pair; 829 830 if (!has_colors()) 831 return 0; 837 832 838 833 /* Sanity (Bounds) Check */ … … 852 847 if (!(pair != -1 && pair < cpmgr->next)) { 853 848 /* If we didn't find a pair, search for a free one to assign. */ 854 pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;849 pair = (cpmgr->next < owl_util_get_colorpairs()) ? cpmgr->next : -1; 855 850 if (pair != -1) { 856 851 /* We found a free pair, initialize it. */ -
functions.c
r4fd211f r259e60a8 32 32 char *rv; 33 33 rv=owl_function_command(cmdbuff); 34 if (rv)g_free(rv);34 g_free(rv); 35 35 } 36 36 … … 453 453 454 454 if (rv || status) { 455 if(cryptmsg)g_free(cryptmsg);455 g_free(cryptmsg); 456 456 g_free(old_msg); 457 457 owl_function_error("Error in zcrypt, possibly no key found. Message not sent."); … … 991 991 /* execute the commands in shutdown */ 992 992 ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();"); 993 if (ret)g_free(ret);993 g_free(ret); 994 994 995 995 /* signal our child process, if any */ … … 1408 1408 #ifdef HAVE_LIBZEPHYR 1409 1409 if (owl_message_is_direction_in(m)) { 1410 char * ptr, tmpbuff[1024];1411 int i, j, fields, len;1410 char *tmpbuff; 1411 int i, fields; 1412 1412 1413 1413 n=owl_message_get_notice(m); … … 1453 1453 owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); 1454 1454 1455 for (i=0; i<fields; i++) { 1456 ptr=owl_zephyr_get_field_as_utf8(n, i+1); 1457 len=strlen(ptr); 1458 if (len<30) { 1459 strncpy(tmpbuff, ptr, len); 1460 tmpbuff[len]='\0'; 1461 } else { 1462 strncpy(tmpbuff, ptr, 30); 1463 tmpbuff[30]='\0'; 1464 strcat(tmpbuff, "..."); 1465 } 1466 g_free(ptr); 1467 1468 for (j=0; j<strlen(tmpbuff); j++) { 1469 if (tmpbuff[j]=='\n') tmpbuff[j]='~'; 1470 if (tmpbuff[j]=='\r') tmpbuff[j]='!'; 1471 } 1472 1473 owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i+1, tmpbuff); 1455 for (i = 0; i < fields; i++) { 1456 tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1); 1457 1458 g_strdelimit(tmpbuff, "\n", '~'); 1459 g_strdelimit(tmpbuff, "\r", '!'); 1460 1461 owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i + 1, tmpbuff); 1462 g_free(tmpbuff); 1474 1463 } 1475 1464 owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", n->z_default_format); … … 1817 1806 owl_global_get_cols(&g)); 1818 1807 1819 if ( owl_global_get_hascolors(&g)) {1808 if (has_colors()) { 1820 1809 owl_fmtext_append_normal(&fm, "Color: Yes\n"); 1821 owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_ global_get_colorpairs(&g));1810 owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_util_get_colorpairs()); 1822 1811 owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); 1823 1812 } else { … … 2226 2215 f = fl->data; 2227 2216 owl_fmtext_append_normal(&fm, " "); 2228 if (owl_global_get_hascolors(&g)) { 2229 owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f)); 2230 } else { 2231 owl_fmtext_append_normal(&fm, owl_filter_get_name(f)); 2232 } 2217 owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), 2218 owl_filter_get_fgcolor(f), 2219 owl_filter_get_bgcolor(f)); 2233 2220 owl_fmtext_append_normal(&fm, "\n"); 2234 2221 } … … 2360 2347 done: 2361 2348 g_free(class); 2362 if (instance) { 2363 g_free(instance); 2364 } 2349 g_free(instance); 2365 2350 return(filtname); 2366 2351 } … … 2523 2508 2524 2509 filtname = g_strdup_printf("conversation-%s", ccs); 2525 owl_text_tr(filtname, ' ', '-');2510 g_strdelimit(filtname, " ", '-'); 2526 2511 2527 2512 if (owl_global_get_filter(&g, filtname)) { … … 2785 2770 void owl_function_zpunt(const char *class, const char *inst, const char *recip, int direction) 2786 2771 { 2787 G String *buf;2772 GPtrArray *argv; 2788 2773 char *quoted; 2789 2774 2790 buf = g_string_new("");2775 argv = g_ptr_array_new(); 2791 2776 if (!strcmp(class, "*")) { 2792 g_string_append(buf, "class .*"); 2777 g_ptr_array_add(argv, g_strdup("class")); 2778 g_ptr_array_add(argv, g_strdup(".*")); 2793 2779 } else { 2794 2780 quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2795 owl_string_appendf_quoted(buf, "class ^(un)*%q(\\.d)*$", quoted); 2781 g_ptr_array_add(argv, g_strdup("class")); 2782 g_ptr_array_add(argv, g_strdup_printf("^(un)*%s(\\.d)*$", quoted)); 2796 2783 g_free(quoted); 2797 2784 } 2798 2785 if (!strcmp(inst, "*")) { 2799 g_string_append(buf, " and instance .*"); 2786 g_ptr_array_add(argv, g_strdup("and")); 2787 g_ptr_array_add(argv, g_strdup("instance")); 2788 g_ptr_array_add(argv, g_strdup(".*")); 2800 2789 } else { 2801 2790 quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2802 owl_string_appendf_quoted(buf, " and instance ^(un)*%q(\\.d)*$", quoted); 2791 g_ptr_array_add(argv, g_strdup("and")); 2792 g_ptr_array_add(argv, g_strdup("instance")); 2793 g_ptr_array_add(argv, g_strdup_printf("^(un)*%s(\\.d)*$", quoted)); 2803 2794 g_free(quoted); 2804 2795 } 2805 2796 if (!strcmp(recip, "*")) { 2806 /* g_string_append(buf, "");*/2797 /* nothing */ 2807 2798 } else { 2808 2799 if(!strcmp(recip, "%me%")) { … … 2810 2801 } 2811 2802 quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2812 owl_string_appendf_quoted(buf, " and recipient ^%q$", quoted); 2803 g_ptr_array_add(argv, g_strdup("and")); 2804 g_ptr_array_add(argv, g_strdup("recipient")); 2805 g_ptr_array_add(argv, g_strdup_printf("^%s$", quoted)); 2813 2806 g_free(quoted); 2814 2807 } 2815 2808 2816 owl_function_punt(buf->str, direction); 2817 g_string_free(buf, true); 2818 } 2819 2820 void owl_function_punt(const char *filter, int direction) 2809 owl_function_punt(argv->len, (const char *const*) argv->pdata, direction); 2810 g_ptr_array_foreach(argv, (GFunc)g_free, NULL); 2811 g_ptr_array_free(argv, true); 2812 } 2813 2814 void owl_function_punt(int argc, const char *const *argv, int direction) 2821 2815 { 2822 2816 owl_filter *f; … … 2826 2820 2827 2821 /* first, create the filter */ 2828 owl_function_debugmsg("About to filter %s", filter); 2829 f = owl_filter_new_fromstring("punt-filter", filter); 2822 f = owl_filter_new("punt-filter", argc, argv); 2830 2823 if (f == NULL) { 2831 2824 owl_function_error("Error creating filter for zpunt"); … … 2854 2847 } 2855 2848 2856 owl_function_debugmsg("punting");2857 /* If we're punting, add the filter to the global punt list */2858 if (direction==0) {2849 if (direction == 0) { 2850 owl_function_debugmsg("punting"); 2851 /* If we're punting, add the filter to the global punt list */ 2859 2852 owl_list_append_element(fl, f); 2860 } 2853 } else if (direction == 1) { 2854 owl_function_makemsg("No matching punt filter"); 2855 } 2861 2856 } 2862 2857 … … 2995 2990 i--; 2996 2991 } 2997 owl_function_mask_sigint(NULL); 2998 if(owl_global_is_interrupted(&g)) { 2999 owl_global_unset_interrupted(&g); 3000 owl_function_unmask_sigint(NULL); 2992 if (owl_global_take_interrupt(&g)) { 3001 2993 owl_function_makemsg("Search interrupted!"); 3002 2994 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 3003 2995 return; 3004 2996 } 3005 owl_function_unmask_sigint(NULL);3006 2997 } 3007 2998 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); … … 3086 3077 ret=ZLocateUser(zstr(user), &numlocs, ZAUTH); 3087 3078 3088 owl_function_mask_sigint(NULL); 3089 if(owl_global_is_interrupted(&g)) { 3079 if (owl_global_take_interrupt(&g)) { 3090 3080 interrupted = 1; 3091 owl_global_unset_interrupted(&g);3092 owl_function_unmask_sigint(NULL);3093 3081 owl_function_makemsg("Interrupted!"); 3094 3082 break; 3095 3083 } 3096 3097 owl_function_unmask_sigint(NULL);3098 3084 3099 3085 if (ret!=ZERR_NONE) { … … 3256 3242 filename=owl_global_get_startupfile(&g); 3257 3243 3258 /* delete earlier copies */ 3259 owl_util_file_deleteline(filename, buff, 1); 3244 /* delete earlier copies, if the file exists */ 3245 if (g_file_test(filename, G_FILE_TEST_EXISTS)) 3246 owl_util_file_deleteline(filename, buff, 1); 3260 3247 3261 3248 file=fopen(filename, "a"); … … 3500 3487 } 3501 3488 3502 void owl_function_mask_sigint(sigset_t *oldmask) {3503 sigset_t intr;3504 3505 sigemptyset(&intr);3506 sigaddset(&intr, SIGINT);3507 sigprocmask(SIG_BLOCK, &intr, oldmask);3508 }3509 3510 void owl_function_unmask_sigint(sigset_t *oldmask) {3511 sigset_t intr;3512 3513 sigemptyset(&intr);3514 sigaddset(&intr, SIGINT);3515 sigprocmask(SIG_UNBLOCK, &intr, oldmask);3516 }3517 3518 3489 void _owl_function_mark_message(const owl_message *m) 3519 3490 { -
global.c
r47e0a6a rf97c1a6 16 16 17 17 g_type_init(); 18 g_thread_init(NULL); 19 20 owl_select_init(); 18 21 19 22 g->lines=LINES; … … 51 54 g->direction=OWL_DIRECTION_DOWNWARDS; 52 55 g->zaway=0; 53 if (has_colors()) {54 g->hascolors=1;55 }56 g->colorpairs=COLOR_PAIRS;57 56 owl_fmtext_init_colorpair_mgr(&(g->cpmgr)); 58 57 g->debug=OWL_DEBUG; … … 99 98 100 99 owl_errqueue_init(&(g->errqueue)); 101 g->got_err_signal=0;102 100 103 101 owl_zbuddylist_create(&(g->zbuddies)); … … 108 106 owl_message_init_fmtext_cache(); 109 107 owl_list_create(&(g->io_dispatch_list)); 110 owl_list_create(&(g->psa_list));111 108 g->timerlist = NULL; 112 g->interrupted = FALSE;113 109 g->kill_buffer = NULL; 110 111 g->interrupt_count = 0; 112 g->interrupt_lock = g_mutex_new(); 114 113 } 115 114 … … 348 347 349 348 void owl_global_set_resize_pending(owl_global *g) { 350 g->resizepending =1;349 g->resizepending = true; 351 350 } 352 351 … … 448 447 /* resize the screen. If lines or cols is 0 use the terminal size */ 449 448 if (!g->resizepending) return; 450 g->resizepending = 0;449 g->resizepending = false; 451 450 452 451 owl_global_get_terminal_size(&g->lines, &g->cols); … … 509 508 510 509 void owl_global_set_startupargs(owl_global *g, int argc, char **argv) { 511 if (g->startupargs)g_free(g->startupargs);510 g_free(g->startupargs); 512 511 g->startupargs = g_strjoinv(" ", argv); 513 512 } … … 574 573 owl_view *owl_global_get_current_view(owl_global *g) { 575 574 return(&(g->current_view)); 576 }577 578 /* has colors */579 580 int owl_global_get_hascolors(const owl_global *g) {581 if (g->hascolors) return(1);582 return(0);583 }584 585 /* color pairs */586 587 int owl_global_get_colorpairs(const owl_global *g) {588 return(g->colorpairs);589 575 } 590 576 … … 693 679 } 694 680 695 int owl_global_is_doaimevents(const owl_global *g) 696 { 697 if (g->aim_doprocessing) return(1); 698 return(0); 681 bool owl_global_is_doaimevents(const owl_global *g) 682 { 683 return g->aim_event_source != NULL; 699 684 } 700 685 701 686 void owl_global_set_doaimevents(owl_global *g) 702 687 { 703 g->aim_doprocessing=1; 688 if (g->aim_event_source) 689 return; 690 g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g)); 691 g_source_attach(g->aim_event_source, NULL); 704 692 } 705 693 706 694 void owl_global_set_no_doaimevents(owl_global *g) 707 695 { 708 g->aim_doprocessing=0; 696 if (!g->aim_event_source) 697 return; 698 g_source_destroy(g->aim_event_source); 699 g_source_unref(g->aim_event_source); 700 g->aim_event_source = NULL; 709 701 } 710 702 … … 764 756 } 765 757 766 intowl_global_get_style_names(const owl_global *g, owl_list *l) {767 returnowl_dict_get_keys(&(g->styledict), l);758 void owl_global_get_style_names(const owl_global *g, owl_list *l) { 759 owl_dict_get_keys(&(g->styledict), l); 768 760 } 769 761 … … 824 816 } 825 817 826 void owl_global_set_errsignal(owl_global *g, int signum, siginfo_t *siginfo)827 {828 g->got_err_signal = signum;829 if (siginfo) {830 g->err_signal_info = *siginfo;831 } else {832 siginfo_t si;833 memset(&si, 0, sizeof(si));834 g->err_signal_info = si;835 }836 }837 838 int owl_global_get_errsignal_and_clear(owl_global *g, siginfo_t *siginfo)839 {840 int signum;841 if (siginfo && g->got_err_signal) {842 *siginfo = g->err_signal_info;843 }844 signum = g->got_err_signal;845 g->got_err_signal = 0;846 return signum;847 }848 849 850 818 owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) 851 819 { … … 878 846 } 879 847 880 owl_list *owl_global_get_psa_list(owl_global *g)881 {882 return &(g->psa_list);883 }884 885 848 GList **owl_global_get_timerlist(owl_global *g) 886 849 { 887 850 return &(g->timerlist); 888 }889 890 int owl_global_is_interrupted(const owl_global *g) {891 return g->interrupted;892 }893 894 void owl_global_set_interrupted(owl_global *g) {895 g->interrupted = 1;896 }897 898 void owl_global_unset_interrupted(owl_global *g) {899 g->interrupted = 0;900 851 } 901 852 … … 965 916 g->kill_buffer = g_strndup(kill, len); 966 917 } 918 919 void owl_global_add_interrupt(owl_global *g) { 920 /* TODO: This can almost certainly be done with atomic 921 * operations. Whatever. */ 922 g_mutex_lock(g->interrupt_lock); 923 g->interrupt_count++; 924 g_mutex_unlock(g->interrupt_lock); 925 } 926 927 bool owl_global_take_interrupt(owl_global *g) { 928 bool ans = false; 929 g_mutex_lock(g->interrupt_lock); 930 if (g->interrupt_count > 0) { 931 ans = true; 932 g->interrupt_count--; 933 } 934 g_mutex_unlock(g->interrupt_lock); 935 return ans; 936 } -
keybinding.c
rd07af84 r3b8a563 69 69 void owl_keybinding_delete(owl_keybinding *kb) 70 70 { 71 if (kb->keys)g_free(kb->keys);72 if (kb->desc)g_free(kb->desc);73 if (kb->command)g_free(kb->command);71 g_free(kb->keys); 72 g_free(kb->desc); 73 g_free(kb->command); 74 74 g_free(kb); 75 75 } -
keymap.c
r47e0a6a r4c7c21f 9 9 { 10 10 if (!name || !desc) return(-1); 11 if ((km->name = g_strdup(name)) == NULL) return(-1);12 if ((km->desc = g_strdup(desc)) == NULL) return(-1);13 if (0 != owl_list_create(&km->bindings)) return(-1);11 km->name = g_strdup(name); 12 km->desc = g_strdup(desc); 13 owl_list_create(&km->bindings); 14 14 km->parent = NULL; 15 15 km->default_fn = default_fn; … … 179 179 /* NOTE: keyhandler has private access to the internals of keymap */ 180 180 181 intowl_keyhandler_init(owl_keyhandler *kh)182 { 183 if (0 != owl_dict_create(&kh->keymaps)) return(-1);181 void owl_keyhandler_init(owl_keyhandler *kh) 182 { 183 owl_dict_create(&kh->keymaps); 184 184 kh->active = NULL; 185 185 owl_keyhandler_reset(kh); 186 return(0);187 186 } 188 187 -
list.c
rddbbcffa rfda61d3 5 5 #define GROWBY 3 / 2 6 6 7 intowl_list_create(owl_list *l)7 void owl_list_create(owl_list *l) 8 8 { 9 9 l->size=0; 10 10 l->list=g_new(void *, INITSIZE); 11 11 l->avail=INITSIZE; 12 if (l->list==NULL) return(-1);13 return(0);14 12 } 15 13 -
logging.c
rfe3b017 rcc305b5 4 4 #include <ctype.h> 5 5 #include <sys/param.h> 6 7 typedef struct _owl_log_entry { /* noproto */ 8 char *filename; 9 char *message; 10 } owl_log_entry; 11 12 13 static GMainContext *log_context; 14 static GMainLoop *log_loop; 15 static GThread *logging_thread; 6 16 7 17 /* This is now the one function that should be called to log a … … 70 80 } 71 81 72 void owl_log_zephyr(const owl_message *m, FILE *file) { 73 char *tmp; 74 tmp=short_zuser(owl_message_get_sender(m)); 75 fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m)); 76 if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m)); 77 fprintf(file, "\n"); 78 fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m)); 79 fprintf(file, "From: %s <%s>\n\n", owl_message_get_zsig(m), tmp); 80 fprintf(file, "%s\n\n", owl_message_get_body(m)); 82 char *owl_log_zephyr(const owl_message *m) { 83 char *tmp = NULL; 84 GString *buffer = NULL; 85 buffer = g_string_new(""); 86 tmp = short_zuser(owl_message_get_sender(m)); 87 g_string_append_printf(buffer, "Class: %s Instance: %s", 88 owl_message_get_class(m), 89 owl_message_get_instance(m)); 90 if (strcmp(owl_message_get_opcode(m), "")) { 91 g_string_append_printf(buffer, " Opcode: %s", 92 owl_message_get_opcode(m)); 93 } 94 g_string_append_printf(buffer, "\n"); 95 g_string_append_printf(buffer, "Time: %s Host: %s\n", 96 owl_message_get_timestr(m), 97 owl_message_get_hostname(m)); 98 g_string_append_printf(buffer, "From: %s <%s>\n\n", 99 owl_message_get_zsig(m), tmp); 100 g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m)); 81 101 g_free(tmp); 82 } 83 84 void owl_log_aim(const owl_message *m, FILE *file) { 85 fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); 86 fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); 87 if (owl_message_is_login(m)) 88 fprintf(file, "LOGIN\n\n"); 89 else if (owl_message_is_logout(m)) 90 fprintf(file, "LOGOUT\n\n"); 91 else 92 fprintf(file, "%s\n\n", owl_message_get_body(m)); 93 } 94 95 void owl_log_jabber(const owl_message *m, FILE *file) { 96 fprintf(file, "From: <%s> To: <%s>\n",owl_message_get_sender(m), owl_message_get_recipient(m)); 97 fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); 98 fprintf(file, "%s\n\n",owl_message_get_body(m)); 99 } 100 101 void owl_log_generic(const owl_message *m, FILE *file) { 102 fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); 103 fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); 104 fprintf(file, "%s\n\n", owl_message_get_body(m)); 102 return g_string_free(buffer, FALSE); 103 } 104 105 char *owl_log_aim(const owl_message *m) { 106 GString *buffer = NULL; 107 buffer = g_string_new(""); 108 g_string_append_printf(buffer, "From: <%s> To: <%s>\n", 109 owl_message_get_sender(m), owl_message_get_recipient(m)); 110 g_string_append_printf(buffer, "Time: %s\n\n", 111 owl_message_get_timestr(m)); 112 if (owl_message_is_login(m)) { 113 g_string_append_printf(buffer, "LOGIN\n\n"); 114 } else if (owl_message_is_logout(m)) { 115 g_string_append_printf(buffer, "LOGOUT\n\n"); 116 } else { 117 g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m)); 118 } 119 return g_string_free(buffer, FALSE); 120 } 121 122 char *owl_log_jabber(const owl_message *m) { 123 GString *buffer = NULL; 124 buffer = g_string_new(""); 125 g_string_append_printf(buffer, "From: <%s> To: <%s>\n", 126 owl_message_get_sender(m), 127 owl_message_get_recipient(m)); 128 g_string_append_printf(buffer, "Time: %s\n\n", 129 owl_message_get_timestr(m)); 130 g_string_append_printf(buffer, "%s\n\n", owl_message_get_body(m)); 131 return g_string_free(buffer, FALSE); 132 } 133 134 char *owl_log_generic(const owl_message *m) { 135 GString *buffer; 136 buffer = g_string_new(""); 137 g_string_append_printf(buffer, "From: <%s> To: <%s>\n", 138 owl_message_get_sender(m), 139 owl_message_get_recipient(m)); 140 g_string_append_printf(buffer, "Time: %s\n\n", 141 owl_message_get_timestr(m)); 142 g_string_append_printf(buffer, "%s\n\n", 143 owl_message_get_body(m)); 144 return g_string_free(buffer, FALSE); 145 } 146 147 static void owl_log_error_main_thread(gpointer data) 148 { 149 owl_function_error("%s", (const char*)data); 150 } 151 152 static void owl_log_error(const char *message) 153 { 154 char *data = g_strdup(message); 155 owl_select_post_task(owl_log_error_main_thread, 156 data, g_free, g_main_context_default()); 157 } 158 159 static void owl_log_write_entry(gpointer data) 160 { 161 owl_log_entry *msg = (owl_log_entry*)data; 162 FILE *file = NULL; 163 file = fopen(msg->filename, "a"); 164 if (!file) { 165 owl_log_error("Unable to open file for logging"); 166 return; 167 } 168 fprintf(file, "%s", msg->message); 169 fclose(file); 170 } 171 172 static void owl_log_entry_free(void *data) 173 { 174 owl_log_entry *msg = (owl_log_entry*)data; 175 if (msg) { 176 g_free(msg->message); 177 g_free(msg->filename); 178 g_free(msg); 179 } 180 } 181 182 void owl_log_enqueue_message(const char *buffer, const char *filename) 183 { 184 owl_log_entry *log_msg = NULL; 185 log_msg = g_new(owl_log_entry,1); 186 log_msg->message = g_strdup(buffer); 187 log_msg->filename = g_strdup(filename); 188 owl_select_post_task(owl_log_write_entry, log_msg, 189 owl_log_entry_free, log_context); 105 190 } 106 191 107 192 void owl_log_append(const owl_message *m, const char *filename) { 108 FILE *file; 109 file=fopen(filename, "a"); 110 if (!file) { 111 owl_function_error("Unable to open file for logging"); 112 return; 113 } 114 if (owl_message_is_type_zephyr(m)) { 115 owl_log_zephyr(m, file); 116 } else if (owl_message_is_type_jabber(m)) { 117 owl_log_jabber(m, file); 118 } else if (owl_message_is_type_aim(m)) { 119 owl_log_aim(m, file); 120 } else { 121 owl_log_generic(m, file); 122 } 123 fclose(file); 193 char *buffer = NULL; 194 if (owl_message_is_type_zephyr(m)) { 195 buffer = owl_log_zephyr(m); 196 } else if (owl_message_is_type_jabber(m)) { 197 buffer = owl_log_jabber(m); 198 } else if (owl_message_is_type_aim(m)) { 199 buffer = owl_log_aim(m); 200 } else { 201 buffer = owl_log_generic(m); 202 } 203 owl_log_enqueue_message(buffer, filename); 204 g_free(buffer); 124 205 } 125 206 … … 151 232 } else if (owl_message_is_type_jabber(m)) { 152 233 to = g_strdup_printf("jabber:%s", owl_message_get_recipient(m)); 153 owl_text_tr(to, '/', '_');234 g_strdelimit(to, "/", '_'); 154 235 } else if (owl_message_is_type_aim(m)) { 155 236 char *temp2; … … 177 258 void owl_log_outgoing_zephyr_error(const owl_zwrite *zw, const char *text) 178 259 { 179 FILE *file;180 260 char *filename, *logpath; 181 261 char *tobuff, *recip; 182 262 owl_message *m; 183 263 GString *msgbuf; 184 264 /* create a present message so we can pass it to 185 265 * owl_log_shouldlog_message(void) … … 201 281 /* expand ~ in path names */ 202 282 logpath = owl_util_makepath(owl_global_get_logpath(&g)); 203 204 283 filename = g_strdup_printf("%s/%s", logpath, tobuff); 205 file=fopen(filename, "a"); 206 g_free(filename); 207 if (!file) { 208 owl_function_error("Unable to open file for outgoing logging"); 209 g_free(logpath); 210 g_free(tobuff); 211 return; 212 } 213 fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text); 214 if (text[strlen(text)-1]!='\n') { 215 fprintf(file, "\n"); 216 } 217 fclose(file); 284 msgbuf = g_string_new(""); 285 g_string_printf(msgbuf, "ERROR (owl): %s\n%s\n", tobuff, text); 286 if (text[strlen(text)-1] != '\n') { 287 g_string_append_printf(msgbuf, "\n"); 288 } 289 owl_log_enqueue_message(msgbuf->str, filename); 290 g_string_free(msgbuf, TRUE); 218 291 219 292 filename = g_strdup_printf("%s/all", logpath); 220 293 g_free(logpath); 221 file=fopen(filename, "a"); 222 g_free(filename); 223 if (!file) { 224 owl_function_error("Unable to open file for outgoing logging"); 225 g_free(tobuff); 226 return; 227 } 228 fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text); 229 if (text[strlen(text)-1]!='\n') { 230 fprintf(file, "\n"); 231 } 232 fclose(file); 294 msgbuf = g_string_new(""); 295 g_string_printf(msgbuf, "ERROR (owl): %s\n%s\n", tobuff, text); 296 if (text[strlen(text)-1] != '\n') { 297 g_string_append_printf(msgbuf, "\n"); 298 } 299 owl_log_enqueue_message(msgbuf->str, filename); 300 g_string_free(msgbuf, TRUE); 233 301 234 302 g_free(tobuff); … … 284 352 } else if (owl_message_is_type_jabber(m)) { 285 353 if (personal) { 286 from=frombuff=g_strdup_printf("jabber:%s",owl_message_get_sender(m)); 287 } else { 288 from=frombuff=g_strdup_printf("jabber:%s",owl_message_get_recipient(m)); 354 from=frombuff=g_strdup_printf("jabber:%s", 355 owl_message_get_sender(m)); 356 } else { 357 from=frombuff=g_strdup_printf("jabber:%s", 358 owl_message_get_recipient(m)); 289 359 } 290 360 } else { … … 355 425 g_free(logpath); 356 426 } 427 428 static gpointer owl_log_thread_func(gpointer data) 429 { 430 log_context = g_main_context_new(); 431 log_loop = g_main_loop_new(log_context, FALSE); 432 g_main_loop_run(log_loop); 433 return NULL; 434 } 435 436 void owl_log_init(void) 437 { 438 GError *error = NULL; 439 logging_thread = g_thread_create(owl_log_thread_func, 440 NULL, 441 TRUE, 442 &error); 443 if (error) { 444 endwin(); 445 fprintf(stderr, "Error spawning logging thread: %s\n", error->message); 446 fflush(stderr); 447 exit(1); 448 } 449 450 } 451 452 static void owl_log_quit_func(gpointer data) 453 { 454 g_main_loop_quit(log_loop); 455 } 456 457 void owl_log_shutdown(void) 458 { 459 owl_select_post_task(owl_log_quit_func, NULL, 460 NULL, log_context); 461 g_thread_join(logging_thread); 462 } -
message.c
r3a3863e r259e60a8 120 120 int i, j; 121 121 owl_pair *p; 122 char *buff ;122 char *buff, *tmpbuff; 123 123 124 124 owl_fmtext_init_null(fm); … … 127 127 for (i=0; i<j; i++) { 128 128 p=owl_list_get_element(&(m->attributes), i); 129 buff=g_strdup_printf(" %-15.15s: %-35.35s\n", owl_pair_get_key(p), owl_pair_get_value(p)); 129 130 tmpbuff = g_strdup(owl_pair_get_value(p)); 131 g_strdelimit(tmpbuff, "\n", '~'); 132 g_strdelimit(tmpbuff, "\r", '!'); 133 buff = g_strdup_printf(" %-15.15s: %s\n", owl_pair_get_key(p), tmpbuff); 134 g_free(tmpbuff); 135 130 136 if(buff == NULL) { 131 buff =g_strdup_printf(" %-15.15s: %-35.35s\n", owl_pair_get_key(p), "<error>");137 buff = g_strdup_printf(" %-15.15s: %s\n", owl_pair_get_key(p), "<error>"); 132 138 if(buff == NULL) 133 139 buff=g_strdup(" <error>\n"); -
owl.c
ra2a8833 rcc305b5 160 160 * was ignored due to user settings or otherwise. 161 161 */ 162 int owl_process_message(owl_message *m) {162 static int owl_process_message(owl_message *m) { 163 163 const owl_filter *f; 164 164 /* if this message it on the puntlist, nuke it and continue */ … … 245 245 } 246 246 247 static gboolean owl_process_messages_prepare(GSource *source, int *timeout) { 248 *timeout = -1; 249 return owl_global_messagequeue_pending(&g); 250 } 251 252 static gboolean owl_process_messages_check(GSource *source) { 253 return owl_global_messagequeue_pending(&g); 254 } 255 247 256 /* 248 257 * Process any new messages we have waiting in the message queue. 249 * Returns 1 if any messages were added to the message list, and 0 otherwise.250 258 */ 251 int owl_process_messages(owl_ps_action *d, void *p) 252 { 259 static gboolean owl_process_messages_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { 253 260 int newmsgs=0; 254 261 int followlast = owl_global_should_followlast(&g); … … 274 281 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 275 282 } 276 return newmsgs; 283 return TRUE; 284 } 285 286 static GSourceFuncs owl_process_messages_funcs = { 287 owl_process_messages_prepare, 288 owl_process_messages_check, 289 owl_process_messages_dispatch, 290 NULL 291 }; 292 293 void owl_process_input_char(owl_input j) 294 { 295 int ret; 296 297 owl_global_set_lastinputtime(&g, time(NULL)); 298 ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); 299 if (ret!=0 && ret!=1) { 300 owl_function_makemsg("Unable to handle keypress"); 301 } 277 302 } 278 303 … … 334 359 } 335 360 336 void sig_handler(int sig, siginfo_t *si, void *data) 337 { 338 if (sig==SIGWINCH) { 339 /* we can't inturrupt a malloc here, so it just sets a flag 340 * schedulding a resize for later 341 */ 361 static void sig_handler_main_thread(void *data) { 362 int sig = GPOINTER_TO_INT(data); 363 364 owl_function_debugmsg("Got signal %d", sig); 365 if (sig == SIGWINCH) { 342 366 owl_function_resize(); 343 } else if (sig==SIGPIPE || sig==SIGCHLD) { 344 /* Set a flag and some info that we got the sigpipe 345 * so we can record that we got it and why... */ 346 owl_global_set_errsignal(&g, sig, si); 347 } else if (sig==SIGTERM || sig==SIGHUP) { 367 } else if (sig == SIGTERM || sig == SIGHUP) { 348 368 owl_function_quit(); 349 } 350 } 351 352 void sigint_handler(int sig, siginfo_t *si, void *data) 353 { 354 owl_global_set_interrupted(&g); 355 } 356 357 static int owl_errsignal_pre_select_action(owl_ps_action *a, void *data) 358 { 359 siginfo_t si; 360 int signum; 361 if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) { 362 owl_function_error("Got unexpected signal: %d %s (code: %d band: %ld errno: %d)", 363 signum, signum==SIGPIPE?"SIGPIPE":"SIG????", 364 si.si_code, si.si_band, si.si_errno); 365 } 366 return 0; 367 } 369 } else if (sig == SIGINT && owl_global_take_interrupt(&g)) { 370 owl_input in; 371 in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR]; 372 owl_process_input_char(in); 373 } 374 } 375 376 static void sig_handler(const siginfo_t *siginfo, void *data) { 377 /* If it was an interrupt, set a flag so we can handle it earlier if 378 * needbe. sig_handler_main_thread will check the flag to make sure 379 * no one else took it. */ 380 if (siginfo->si_signo == SIGINT) { 381 owl_global_add_interrupt(&g); 382 } 383 /* Send a message to the main thread. */ 384 owl_select_post_task(sig_handler_main_thread, 385 GINT_TO_POINTER(siginfo->si_signo), 386 NULL, g_main_context_default()); 387 } 388 389 #define CHECK_RESULT(s, syscall) \ 390 G_STMT_START { \ 391 if ((syscall) != 0) { \ 392 perror((s)); \ 393 exit(1); \ 394 } \ 395 } G_STMT_END 368 396 369 397 void owl_register_signal_handlers(void) { 370 struct sigaction sigact; 371 372 /* signal handler */ 373 /*sigact.sa_handler=sig_handler;*/ 374 sigact.sa_sigaction=sig_handler; 375 sigemptyset(&sigact.sa_mask); 376 sigact.sa_flags=SA_SIGINFO; 377 sigaction(SIGWINCH, &sigact, NULL); 378 sigaction(SIGALRM, &sigact, NULL); 379 sigaction(SIGPIPE, &sigact, NULL); 380 sigaction(SIGTERM, &sigact, NULL); 381 sigaction(SIGHUP, &sigact, NULL); 382 383 sigact.sa_sigaction=sigint_handler; 384 sigaction(SIGINT, &sigact, NULL); 398 struct sigaction sig_ignore = { .sa_handler = SIG_IGN }; 399 struct sigaction sig_default = { .sa_handler = SIG_DFL }; 400 sigset_t sigset; 401 int ret, i; 402 const int signals[] = { SIGABRT, SIGBUS, SIGCHLD, SIGFPE, SIGHUP, SIGILL, 403 SIGINT, SIGQUIT, SIGSEGV, SIGTERM, SIGWINCH }; 404 405 /* Sanitize our signals; the mask and dispositions from our parent 406 * aren't really useful. Signal list taken from equivalent code in 407 * Chromium. */ 408 CHECK_RESULT("sigemptyset", sigemptyset(&sigset)); 409 if ((ret = pthread_sigmask(SIG_SETMASK, &sigset, NULL)) != 0) { 410 errno = ret; 411 perror("pthread_sigmask"); 412 } 413 for (i = 0; i < G_N_ELEMENTS(signals); i++) { 414 CHECK_RESULT("sigaction", sigaction(signals[i], &sig_default, NULL)); 415 } 416 417 /* Turn off SIGPIPE; we check the return value of write. */ 418 CHECK_RESULT("sigaction", sigaction(SIGPIPE, &sig_ignore, NULL)); 419 420 /* Register some signals with the signal thread. */ 421 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGWINCH)); 422 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGTERM)); 423 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGHUP)); 424 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGINT)); 425 owl_signal_init(&sigset, sig_handler, NULL); 385 426 } 386 427 … … 424 465 } 425 466 bread = read(rfd, buf, navail); 426 if (buf[navail-1] != '\0') { 427 buf[navail] = '\0'; 428 } 429 430 err = g_strdup_printf("[stderr]\n%s", buf); 467 if (bread == -1) 468 return; 469 470 err = g_strdup_printf("[stderr]\n%.*s", bread, buf); 431 471 432 472 owl_function_log_err(err); … … 435 475 436 476 #endif /* OWL_STDERR_REDIR */ 437 438 static int owl_refresh_pre_select_action(owl_ps_action *a, void *data)439 {440 owl_colorpair_mgr *cpmgr;441 442 /* if a resize has been scheduled, deal with it */443 owl_global_check_resize(&g);444 /* update the terminal if we need to */445 owl_window_redraw_scheduled();446 /* On colorpair shortage, reset and redraw /everything/. NOTE: if447 * the current screen uses too many colorpairs, this draws448 * everything twice. But this is unlikely; COLOR_PAIRS is 64 with449 * 8+1 colors, and 256^2 with 256+1 colors. (+1 for default.) */450 cpmgr = owl_global_get_colorpair_mgr(&g);451 if (cpmgr->overflow) {452 owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS);453 owl_fmtext_reset_colorpairs(cpmgr);454 owl_function_full_redisplay();455 owl_window_redraw_scheduled();456 }457 return 0;458 }459 460 477 461 478 int main(int argc, char **argv, char **env) … … 467 484 const char *dir; 468 485 owl_options opts; 486 GSource *source; 469 487 470 488 if (!GLIB_CHECK_VERSION (2, 12, 0)) … … 481 499 g.load_initial_subs = opts.load_initial_subs; 482 500 483 owl_register_signal_handlers();484 501 owl_start_curses(); 485 502 … … 493 510 owl_global_set_haveaim(&g); 494 511 512 owl_register_signal_handlers(); 513 495 514 /* register STDIN dispatch; throw away return, we won't need it */ 496 515 owl_select_add_io_dispatch(STDIN_FILENO, OWL_IO_READ, &owl_process_input, NULL, NULL); … … 551 570 owl_function_debugmsg("startup: executing perl startup, if applicable"); 552 571 perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();"); 553 if (perlout)g_free(perlout);572 g_free(perlout); 554 573 555 574 /* welcome message */ … … 584 603 owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL); 585 604 586 owl_select_add_pre_select_action(owl_refresh_pre_select_action, NULL, NULL); 587 owl_select_add_pre_select_action(owl_process_messages, NULL, NULL); 588 owl_select_add_pre_select_action(owl_errsignal_pre_select_action, NULL, NULL); 605 source = owl_window_redraw_source_new(); 606 g_source_attach(source, NULL); 607 g_source_unref(source); 608 609 source = g_source_new(&owl_process_messages_funcs, sizeof(GSource)); 610 g_source_attach(source, NULL); 611 g_source_unref(source); 612 613 owl_log_init(); 589 614 590 615 owl_function_debugmsg("startup: entering main loop"); … … 593 618 /* Shut down everything. */ 594 619 owl_zephyr_shutdown(); 620 owl_signal_shutdown(); 595 621 owl_shutdown_curses(); 622 owl_log_shutdown(); 596 623 return 0; 597 624 } -
perl/lib/BarnOwl.pm
rb120bd3 rf2d71cfa 38 38 use BarnOwl::Completion; 39 39 use BarnOwl::Help; 40 use BarnOwl::AnyEvent; 41 42 unshift @AnyEvent::REGISTRY, [BarnOwl => BarnOwl::AnyEvent::]; 43 require AnyEvent; 40 44 41 45 use List::Util qw(max); -
perl/modules/IRC/lib/BarnOwl/Message/IRC.pm
re04b7a1 r60b49a7 66 66 sub action {shift->{action}} 67 67 sub reason {shift->{reason}} 68 sub old_nick {shift->{old_nick}}; 68 69 69 70 # display … … 80 81 } 81 82 82 sub login_extra { 83 sub login_extra { 83 84 my $self = shift; 84 85 if ($self->action eq "quit") { 85 86 return $self->reason; 87 } elsif ($self->action eq 'nick change') { 88 return "was: " . $self->old_nick; 86 89 } else { 87 90 return $self->channel; -
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r9620c8d r5c6d661 20 20 use BarnOwl::Module::IRC::Completion; 21 21 22 use Net::IRC;22 use AnyEvent::IRC; 23 23 use Getopt::Long; 24 24 use Encode; … … 30 30 # Hash alias -> BarnOwl::Module::IRC::Connection object 31 31 our %ircnets; 32 our %channels;33 our %reconnect;34 32 35 33 sub startup { … … 70 68 71 69 register_commands(); 72 register_handlers();73 70 BarnOwl::filter(qw{irc type ^IRC$ or ( type ^admin$ and adminheader ^IRC$ )}); 74 71 } … … 76 73 sub shutdown { 77 74 for my $conn (values %ircnets) { 78 $conn->conn->disconnect( );75 $conn->conn->disconnect('Quitting'); 79 76 } 80 77 } … … 98 95 $list .= "\n"; 99 96 100 for my $chan (keys %channels) { 101 next unless grep $_ eq $conn, @{$channels{$chan}}; 97 for my $chan (keys %{$conn->conn->{channel_list}}) { 102 98 $list .= " $chan\n"; 103 99 } … … 105 101 106 102 return $list; 107 }108 109 #sub mainloop_hook {110 # return unless defined $irc;111 # eval {112 # $irc->do_one_loop();113 # };114 # return;115 #}116 117 sub OwlProcess {118 return unless defined $irc;119 eval {120 $irc->do_one_loop();121 };122 return;123 }124 125 126 sub register_handlers {127 if(!$irc) {128 $irc = Net::IRC->new;129 $irc->timeout(0);130 }131 103 } 132 104 … … 406 378 } 407 379 408 my $conn = BarnOwl::Module::IRC::Connection->new($irc, $alias, 409 Nick => $nick, 410 Server => $host, 411 Port => $port, 412 Username => $username, 413 Ircname => $ircname, 414 Port => $port, 415 Password => $password, 416 SSL => $ssl 417 ); 418 419 if ($conn->conn->connected) { 420 $conn->connected("Connected to $alias as $nick"); 421 } else { 422 die("IRC::Connection->connect failed: $!"); 423 } 424 380 my $conn = BarnOwl::Module::IRC::Connection->new($alias, $host, $port, { 381 nick => $nick, 382 user => $username, 383 real => $ircname, 384 password => $password, 385 SSL => $ssl, 386 timeout => sub {0} 387 }); 388 $ircnets{$alias} = $conn; 425 389 return; 426 390 } … … 429 393 my $cmd = shift; 430 394 my $conn = shift; 431 if ($conn->conn->connected) { 432 $conn->conn->disconnect; 433 } elsif ($reconnect{$conn->alias}) { 395 if ($conn->conn->{socket}) { 396 $conn->did_quit(1); 397 $conn->conn->disconnect("Goodbye!"); 398 } elsif ($conn->{reconnect_timer}) { 434 399 BarnOwl::admin_message('IRC', 435 400 "[" . $conn->alias . "] Reconnect cancelled"); 436 401 $conn->cancel_reconnect; 402 delete $ircnets{$conn->alias}; 437 403 } 438 404 } … … 463 429 for my $body (@msgs) { 464 430 if ($body =~ /^\/me (.*)/) { 465 $conn-> conn->me($to, Encode::encode('utf-8', $1));431 $conn->me($to, Encode::encode('utf-8', $1)); 466 432 $body = '* '.$conn->nick.' '.$1; 467 433 } else { 468 $conn->conn-> privmsg($to, Encode::encode('utf-8', $body));434 $conn->conn->send_msg('privmsg', $to, Encode::encode('utf-8', $body)); 469 435 } 470 436 my $msg = BarnOwl::Message->new( … … 491 457 my $target = shift; 492 458 $target ||= shift; 493 $conn->conn-> mode($target, @_);459 $conn->conn->send_msg(mode => $target, @_); 494 460 return; 495 461 } … … 499 465 my $conn = shift; 500 466 my $chan = shift or die("Usage: $cmd channel\n"); 501 $channels{$chan} ||= []; 502 push @{$channels{$chan}}, $conn; 503 $conn->conn->join($chan, @_); 467 $conn->conn->send_msg(join => $chan, @_); 504 468 return; 505 469 } … … 509 473 my $conn = shift; 510 474 my $chan = shift; 511 $channels{$chan} = [grep {$_ ne $conn} @{$channels{$chan} || []}]; 512 $conn->conn->part($chan); 475 $conn->conn->send_msg(part => $chan); 513 476 return; 514 477 } … … 518 481 my $conn = shift; 519 482 my $nick = shift or die("Usage: $cmd <new nick>\n"); 520 $conn->conn-> nick($nick);483 $conn->conn->send_msg(nick => $nick); 521 484 return; 522 485 } … … 527 490 my $chan = shift; 528 491 $conn->names_tmp([]); 529 $conn->conn-> names($chan);492 $conn->conn->send_msg(names => $chan); 530 493 return; 531 494 } … … 535 498 my $conn = shift; 536 499 my $who = shift || die("Usage: $cmd <user>\n"); 537 $conn->conn-> whois($who);500 $conn->conn->send_msg(whois => $who); 538 501 return; 539 502 } … … 542 505 my $cmd = shift; 543 506 my $conn = shift; 544 $conn->conn-> motd;507 $conn->conn->send_msg('motd'); 545 508 return; 546 509 } … … 560 523 my $conn = shift; 561 524 my $who = shift || die("Usage: $cmd <user>\n"); 562 BarnOwl::error("WHO $cmd $conn $who"); 563 $conn->conn->who($who); 525 $conn->conn->send_msg(who => $who); 564 526 return; 565 527 } … … 569 531 my $conn = shift; 570 532 my $type = shift || die("Usage: $cmd <chiklmouy> [server] \n"); 571 $conn->conn->s tats($type, @_);533 $conn->conn->send_msg(stats => $type, @_); 572 534 return; 573 535 } … … 577 539 my $conn = shift; 578 540 my $chan = shift; 579 $conn->conn-> topic($chan, @_ ? join(" ", @_) : undef);541 $conn->conn->send_msg(topic => $chan, @_ ? join(" ", @_) : undef); 580 542 return; 581 543 } … … 584 546 my $cmd = shift; 585 547 my $conn = shift; 586 $conn->conn->s l(join(" ", @_));548 $conn->conn->send_msg(@_); 587 549 return; 588 550 } … … 591 553 ########################### Utilities/Helpers ################################## 592 554 ################################################################################ 555 556 sub find_channel { 557 my $channel = shift; 558 my @found; 559 for my $conn (values %ircnets) { 560 if($conn->conn->{channel_list}{lc $channel}) { 561 push @found, $conn; 562 } 563 } 564 return $found[0] if(scalar @found == 1); 565 } 593 566 594 567 sub mk_irc_command { … … 614 587 $channel = $ARGV[0]; 615 588 if(defined($channel) && $channel =~ /^#/) { 616 if( $channels{$channel} && @{$channels{$channel}} == 1) {589 if(my $c = find_channel($channel)) { 617 590 shift @ARGV; 618 $conn = $channels{$channel}[0] unless $conn;591 $conn ||= $c; 619 592 } 620 593 } elsif ($m && $m->type eq 'IRC' && !$m->is_private) { … … 654 627 my $allow_disconnected = shift; 655 628 656 return $ircnets{$key} if exists $ircnets{$key}; 657 return $reconnect{$key} if $allow_disconnected && exists $reconnect{$key}; 658 die("No such ircnet: $key\n") 629 my $conn = $ircnets{$key}; 630 die("No such ircnet: $key\n") unless $conn; 631 if ($conn->conn->{registered} || $allow_disconnected) { 632 return $conn; 633 } 634 die("[@{[$conn->alias]}] Not currently connected."); 659 635 } 660 636 -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm
r955a36e rdace02a 11 11 sub complete_networks { keys %BarnOwl::Module::IRC::ircnets } 12 12 sub complete_dests { keys %users, complete_channels() } 13 sub complete_channels { keys %BarnOwl::Module::IRC::channels } 13 sub complete_channels { 14 my %channels; 15 for my $conn (values %BarnOwl::Module::IRC::ircnets) { 16 for my $chan (keys %{$conn->conn->{channel_list}}) { 17 $channels{$chan} = 1; 18 } 19 } 20 return keys %channels; 21 } 14 22 sub complete_nicks { keys %users } 15 23 sub complete_servers { keys %servers } -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
rfb6e8e3 r13ee8f2 11 11 =head1 DESCRIPTION 12 12 13 This module is a wrapper around Net::IRC::Connectionfor BarnOwl's IRC13 This module is a wrapper around AnyEvent::IRC::Client for BarnOwl's IRC 14 14 support 15 15 16 16 =cut 17 17 18 use Net::IRC::Connection; 19 20 use base qw(Class::Accessor Exporter); 21 __PACKAGE__->mk_accessors(qw(conn alias channels motd names_tmp whois_tmp)); 22 our @EXPORT_OK = qw(&is_private); 18 use AnyEvent::IRC::Client; 19 use AnyEvent::IRC::Util qw(split_prefix prefix_nick encode_ctcp); 20 21 use base qw(Class::Accessor); 22 use Exporter 'import'; 23 __PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp 24 server autoconnect_channels 25 connect_args backoff did_quit)); 26 our @EXPORT_OK = qw(is_private); 23 27 24 28 use BarnOwl; 25 29 use Scalar::Util qw(weaken); 26 30 27 BEGIN {28 no strict 'refs';29 my @delegate = qw(nick server);30 for my $meth (@delegate) {31 *{"BarnOwl::Module::IRC::Connection::$meth"} = sub {32 shift->conn->$meth(@_);33 }34 }35 };36 37 31 sub new { 38 32 my $class = shift; 39 my $irc = shift;40 33 my $alias = shift; 41 my %args = (@_); 42 my $conn = Net::IRC::Connection->new($irc, %args); 34 my $host = shift; 35 my $port = shift; 36 my $args = shift; 37 my $nick = $args->{nick}; 38 my $conn = AnyEvent::IRC::Client->new(); 43 39 my $self = bless({}, $class); 44 40 $self->conn($conn); 41 $self->autoconnect_channels([]); 45 42 $self->alias($alias); 46 $self-> channels([]);43 $self->server($host); 47 44 $self->motd(""); 48 45 $self->names_tmp(0); 46 $self->backoff(0); 49 47 $self->whois_tmp(""); 50 51 $self->conn->add_default_handler(sub { shift; $self->on_event(@_) }); 52 $self->conn->add_handler(['msg', 'notice', 'public', 'caction'], 53 sub { shift; $self->on_msg(@_) }); 54 $self->conn->add_handler(['welcome', 'yourhost', 'created', 55 'luserclient', 'luserop', 'luserchannels', 'luserme', 56 'error'], 57 sub { shift; $self->on_admin_msg(@_) }); 58 $self->conn->add_handler(['myinfo', 'map', 'n_local', 'n_global', 59 'luserconns'], 60 sub { }); 61 $self->conn->add_handler(motdstart => sub { shift; $self->on_motdstart(@_) }); 62 $self->conn->add_handler(motd => sub { shift; $self->on_motd(@_) }); 63 $self->conn->add_handler(endofmotd => sub { shift; $self->on_endofmotd(@_) }); 64 $self->conn->add_handler(join => sub { shift; $self->on_join(@_) }); 65 $self->conn->add_handler(part => sub { shift; $self->on_part(@_) }); 66 $self->conn->add_handler(quit => sub { shift; $self->on_quit(@_) }); 67 $self->conn->add_handler(disconnect => sub { shift; $self->on_disconnect(@_) }); 68 $self->conn->add_handler(nicknameinuse => sub { shift; $self->on_nickinuse(@_) }); 69 $self->conn->add_handler(cping => sub { shift; $self->on_ping(@_) }); 70 $self->conn->add_handler(topic => sub { shift; $self->on_topic(@_) }); 71 $self->conn->add_handler(topicinfo => sub { shift; $self->on_topicinfo(@_) }); 72 $self->conn->add_handler(namreply => sub { shift; $self->on_namreply(@_) }); 73 $self->conn->add_handler(endofnames=> sub { shift; $self->on_endofnames(@_) }); 74 $self->conn->add_handler(endofwhois=> sub { shift; $self->on_endofwhois(@_) }); 75 $self->conn->add_handler(mode => sub { shift; $self->on_mode(@_) }); 76 $self->conn->add_handler(nosuchchannel => sub { shift; $self->on_nosuchchannel(@_) }); 48 $self->did_quit(0); 49 50 if(delete $args->{SSL}) { 51 $conn->enable_ssl; 52 } 53 $self->connect_args([$host, $port, $args]); 54 $conn->connect($host, $port, $args); 55 $conn->{heap}{parent} = $self; 56 weaken($conn->{heap}{parent}); 57 58 sub on { 59 my $meth = "on_" . shift; 60 return sub { 61 my $conn = shift; 62 return unless $conn->{heap}{parent}; 63 $conn->{heap}{parent}->$meth(@_); 64 } 65 } 66 67 # $self->conn->add_default_handler(sub { shift; $self->on_event(@_) }); 68 $self->conn->reg_cb(registered => on("connect"), 69 connfail => sub { BarnOwl::error("Connection to $host failed!") }, 70 disconnect => on("disconnect"), 71 publicmsg => on("msg"), 72 privatemsg => on("msg"), 73 irc_error => on("error")); 74 for my $m (qw(welcome yourhost created 75 luserclient luserop luserchannels luserme 76 error)) { 77 $self->conn->reg_cb("irc_$m" => on("admin_msg")); 78 } 79 $self->conn->reg_cb(irc_375 => on("motdstart"), 80 irc_372 => on("motd"), 81 irc_376 => on("endofmotd"), 82 irc_join => on("join"), 83 irc_part => on("part"), 84 irc_quit => on("quit"), 85 irc_433 => on("nickinuse"), 86 channel_topic => on("topic"), 87 irc_333 => on("topicinfo"), 88 irc_353 => on("namreply"), 89 irc_366 => on("endofnames"), 90 irc_311 => on("whois"), 91 irc_312 => on("whois"), 92 irc_319 => on("whois"), 93 irc_320 => on("whois"), 94 irc_318 => on("endofwhois"), 95 irc_mode => on("mode"), 96 irc_401 => on("nosuch"), 97 irc_402 => on("nosuch"), 98 irc_403 => on("nosuch"), 99 nick_change => on("nick"), 100 ctcp_action => on("ctcp_action"), 101 'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} . " " . 102 join(" ", @{$_[1]->{params}})) }); 77 103 78 104 return $self; 105 } 106 107 sub nick { 108 my $self = shift; 109 return $self->conn->nick; 79 110 } 80 111 … … 83 114 my $self = shift; 84 115 return $self->conn->socket; 116 } 117 118 sub me { 119 my ($self, $to, $msg) = @_; 120 $self->conn->send_msg('privmsg', $to, 121 encode_ctcp(['ACTION', $msg])) 85 122 } 86 123 … … 92 129 my $self = shift; 93 130 my $evt = shift; 94 return BarnOwl::Message->new(131 my %args = ( 95 132 type => 'IRC', 96 133 server => $self->server, 97 134 network => $self->alias, 98 sender => $evt->nick,99 hostname => $evt->host,100 from => $evt->from,101 135 @_ 102 136 ); 137 if ($evt) { 138 my ($nick, $user, $host) = split_prefix($evt); 139 $args{sender} ||= $nick; 140 $args{hostname} ||= $host if defined($host); 141 $args{from} ||= $evt->{prefix}; 142 $args{params} ||= join(' ', @{$evt->{params}}) 143 } 144 return BarnOwl::Message->new(%args); 103 145 } 104 146 105 147 sub on_msg { 106 my ($self, $evt) = @_; 107 my ($recipient) = $evt->to; 108 my $body = strip_irc_formatting([$evt->args]->[0]); 109 my $nick = $self->nick; 110 $body = '* '.$evt->nick.' '.$body if $evt->type eq 'caction'; 148 my ($self, $recipient, $evt) = @_; 149 my $body = strip_irc_formatting($evt->{params}->[1]); 150 $self->handle_message($recipient, $evt, $body); 151 } 152 153 sub on_ctcp_action { 154 my ($self, $src, $target, $msg) = @_; 155 my $body = strip_irc_formatting($msg); 156 my $evt = { 157 params => [$src], 158 type => 'privmsg', 159 prefix => $src 160 }; 161 $self->handle_message($target, $evt, "* $body"); 162 } 163 164 sub handle_message { 165 my ($self, $recipient, $evt, $body) = @_; 111 166 my $msg = $self->new_message($evt, 112 167 direction => 'in', 113 168 recipient => $recipient, 114 body => $body,115 $evt->typeeq 'notice' ?169 body => $body, 170 ($evt->{command}||'') eq 'notice' ? 116 171 (notice => 'true') : (), 117 172 is_private($recipient) ? 118 173 (private => 'true') : (channel => $recipient), 119 174 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, 120 (is_private($recipient) ? $evt->nick: $recipient)),121 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),175 (is_private($recipient) ? prefix_nick($evt) : $recipient)), 176 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)), 122 177 ); 123 178 … … 125 180 } 126 181 127 sub on_ping {128 my ($self, $evt) = @_;129 $self->conn->ctcp_reply($evt->nick, join (' ', ($evt->args)));130 }131 182 132 183 sub on_admin_msg { 133 184 my ($self, $evt) = @_; 134 return if BarnOwl::Module::IRC->skip_msg($evt-> type);135 BarnOwl::admin_message("IRC", 136 BarnOwl::Style::boldify('IRC ' . $evt-> type. ' message from '185 return if BarnOwl::Module::IRC->skip_msg($evt->{command}); 186 BarnOwl::admin_message("IRC", 187 BarnOwl::Style::boldify('IRC ' . $evt->{command} . ' message from ' 137 188 . $self->alias) . "\n" 138 . strip_irc_formatting(join ' ', cdr($evt-> args)));189 . strip_irc_formatting(join ' ', cdr($evt->{params}))); 139 190 } 140 191 141 192 sub on_motdstart { 142 193 my ($self, $evt) = @_; 143 $self->motd(join "\n", cdr( $evt->args));194 $self->motd(join "\n", cdr(@{$evt->{params}})); 144 195 } 145 196 146 197 sub on_motd { 147 198 my ($self, $evt) = @_; 148 $self->motd(join "\n", $self->motd, cdr( $evt->args));199 $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}})); 149 200 } 150 201 151 202 sub on_endofmotd { 152 203 my ($self, $evt) = @_; 153 $self->motd(join "\n", $self->motd, cdr( $evt->args));204 $self->motd(join "\n", $self->motd, cdr(@{$evt->{params}})); 154 205 BarnOwl::admin_message("IRC", 155 206 BarnOwl::Style::boldify('MOTD for ' . $self->alias) . "\n" … … 159 210 sub on_join { 160 211 my ($self, $evt) = @_; 212 my $chan = $evt->{params}[0]; 161 213 my $msg = $self->new_message($evt, 162 214 loginout => 'login', 163 215 action => 'join', 164 channel => $ evt->to,165 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $ evt->to),166 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),216 channel => $chan, 217 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $chan), 218 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)), 167 219 ); 168 220 BarnOwl::queue_message($msg); 169 push @{$self->channels}, $evt->to;170 221 } 171 222 172 223 sub on_part { 173 224 my ($self, $evt) = @_; 225 my $chan = $evt->{params}[0]; 174 226 my $msg = $self->new_message($evt, 175 227 loginout => 'logout', 176 228 action => 'part', 177 channel => $ evt->to,178 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $ evt->to),179 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),229 channel => $chan, 230 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $chan), 231 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)), 180 232 ); 181 233 BarnOwl::queue_message($msg); 182 $self->channels([ grep {$_ ne $evt->to} @{$self->channels}]);183 234 } 184 235 … … 188 239 loginout => 'logout', 189 240 action => 'quit', 190 from => $evt-> to,191 reason => [$evt->args]->[0],192 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),193 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, $evt->nick),241 from => $evt->{prefix}, 242 reason => $evt->{params}->[0], 243 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)), 244 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, prefix_nick($evt)), 194 245 ); 195 246 BarnOwl::queue_message($msg); … … 198 249 sub disconnect { 199 250 my $self = shift; 200 delete $BarnOwl::Module::IRC::ircnets{$self->alias}; 201 for my $k (keys %BarnOwl::Module::IRC::channels) { 202 my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}}; 203 if(@conns) { 204 $BarnOwl::Module::IRC::channels{$k} = \@conns; 205 } else { 206 delete $BarnOwl::Module::IRC::channels{$k}; 207 } 208 } 209 BarnOwl::remove_io_dispatch($self->{FD}); 251 $self->conn->disconnect; 252 } 253 254 sub on_disconnect { 255 my ($self, $why) = @_; 256 BarnOwl::admin_message('IRC', 257 "[" . $self->alias . "] Disconnected from server: $why"); 210 258 $self->motd(""); 211 } 212 213 sub on_disconnect { 214 my ($self, $evt) = @_; 215 $self->disconnect; 216 BarnOwl::admin_message('IRC', 217 "[" . $self->alias . "] Disconnected from server"); 218 if ($evt->format and $evt->format eq "error") { 259 if (!$self->did_quit) { 219 260 $self->schedule_reconnect; 220 261 } else { 221 $self->channels([]); 222 } 262 delete $BarnOwl::Module::IRC::ircnets{$self->alias}; 263 } 264 } 265 266 sub on_error { 267 my ($self, $evt) = @_; 268 BarnOwl::admin_message('IRC', 269 "[" . $self->alias . "] " . 270 "Error: " . join(" ", @{$evt->{params}})); 223 271 } 224 272 … … 227 275 BarnOwl::admin_message("IRC", 228 276 "[" . $self->alias . "] " . 229 [$evt->args]->[1] . ": Nick already in use"); 230 $self->disconnect unless $self->motd; 277 $evt->{params}->[1] . ": Nick already in use"); 278 } 279 280 sub on_nick { 281 my ($self, $old_nick, $new_nick, $is_me) = @_; 282 if ($is_me) { 283 BarnOwl::admin_message("IRC", 284 "[" . $self->alias . "] " . 285 "You are now known as $new_nick"); 286 } else { 287 my $msg = $self->new_message('', 288 loginout => 'login', 289 action => 'nick change', 290 from => $new_nick, 291 sender => $new_nick, 292 replycmd => BarnOwl::quote('irc-msg', '-a', $self->alias, 293 $new_nick), 294 replysendercmd => BarnOwl::quote('irc-msg', '-a', $self->alias, 295 $new_nick), 296 old_nick => $old_nick); 297 BarnOwl::queue_message($msg); 298 } 231 299 } 232 300 233 301 sub on_topic { 234 my ($self, $evt) = @_; 235 my @args = $evt->args; 236 if (scalar @args > 1) { 302 my ($self, $channel, $topic, $who) = @_; 303 if ($channel) { 237 304 BarnOwl::admin_message("IRC", 238 "Topic for $ args[1] on " . $self->alias . " is $args[2]");305 "Topic for $channel on " . $self->alias . " is $topic"); 239 306 } else { 240 307 BarnOwl::admin_message("IRC", 241 "Topic changed to $ args[0]");308 "Topic changed to $channel"); 242 309 } 243 310 } … … 245 312 sub on_topicinfo { 246 313 my ($self, $evt) = @_; 247 my @args = $evt->args;314 my @args = @{$evt->{params}}; 248 315 BarnOwl::admin_message("IRC", 249 316 "Topic for $args[1] set by $args[2] at " . localtime($args[3])); … … 257 324 my ($self, $evt) = @_; 258 325 return unless $self->names_tmp; 259 $self->names_tmp([@{$self->names_tmp}, split(' ', [$evt->args]->[3])]); 326 $self->names_tmp([@{$self->names_tmp}, 327 map {prefix_nick($_)} split(' ', $evt->{params}[3])]); 260 328 } 261 329 … … 272 340 my ($self, $evt) = @_; 273 341 return unless $self->names_tmp; 274 my $names = BarnOwl::Style::boldify("Members of " . [$evt->args]->[1] . ":\n");342 my $names = BarnOwl::Style::boldify("Members of " . $evt->{params}->[1] . ":\n"); 275 343 for my $name (sort {cmp_user($a, $b)} @{$self->names_tmp}) { 276 344 $names .= " $name\n"; … … 282 350 sub on_whois { 283 351 my ($self, $evt) = @_; 352 my %names = ( 353 311 => 'user', 354 312 => 'server', 355 319 => 'channels', 356 330 => 'whowas', 357 ); 284 358 $self->whois_tmp( 285 $self->whois_tmp . "\n" . $evt->type. ":\n " .286 join("\n ", cdr(cdr($evt->args))) . "\n"287 );359 $self->whois_tmp . "\n" . $names{$evt->{command}} . ":\n " . 360 join("\n ", cdr(cdr(@{$evt->{params}}))) . "\n" 361 ); 288 362 } 289 363 … … 291 365 my ($self, $evt) = @_; 292 366 BarnOwl::popless_ztext( 293 BarnOwl::Style::boldify("/whois for " . [$evt->args]->[1] . ":\n") .367 BarnOwl::Style::boldify("/whois for " . $evt->{params}->[1] . ":\n") . 294 368 $self->whois_tmp 295 369 ); … … 300 374 my ($self, $evt) = @_; 301 375 BarnOwl::admin_message("IRC", 302 "[" . $self->alias . "] User " . ( $evt->nick) . + " set mode " .303 join(" ", $evt->args) . "on " . $evt->to->[0]376 "[" . $self->alias . "] User " . (prefix_nick($evt)) . + " set mode " . 377 join(" ", cdr(@{$evt->{params}})) . " on " . $evt->{params}->[0] 304 378 ); 305 379 } 306 380 307 sub on_nosuchchannel { 308 my ($self, $evt) = @_; 381 sub on_nosuch { 382 my ($self, $evt) = @_; 383 my %things = (401 => 'nick', 402 => 'server', 403 => 'channel'); 309 384 BarnOwl::admin_message("IRC", 310 385 "[" . $self->alias . "] " . 311 "No such channel: " . [$evt->args]->[1])386 "No such @{[$things{$evt->{command}}]}: @{[$evt->{params}->[1]]}") 312 387 } 313 388 … … 323 398 sub schedule_reconnect { 324 399 my $self = shift; 325 my $interval = shift || 5; 326 delete $BarnOwl::Module::IRC::ircnets{$self->alias}; 327 $BarnOwl::Module::IRC::reconnect{$self->alias} = $self; 400 my $interval = $self->backoff; 401 if ($interval) { 402 $interval *= 2; 403 $interval = 60*5 if $interval > 60*5; 404 } else { 405 $interval = 5; 406 } 407 $self->backoff($interval); 408 328 409 my $weak = $self; 329 410 weaken($weak); … … 343 424 sub cancel_reconnect { 344 425 my $self = shift; 345 delete $BarnOwl::Module::IRC::reconnect{$self->alias}; 426 346 427 if (defined $self->{reconnect_timer}) { 347 428 $self->{reconnect_timer}->stop; 348 429 } 349 430 delete $self->{reconnect_timer}; 431 } 432 433 sub on_connect { 434 my $self = shift; 435 $self->connected("Connected to " . $self->alias . " as " . $self->nick) 350 436 } 351 437 … … 355 441 BarnOwl::admin_message("IRC", $msg); 356 442 $self->cancel_reconnect; 357 $BarnOwl::Module::IRC::ircnets{$self->alias} = $self; 358 my $fd = $self->getSocket()->fileno(); 359 BarnOwl::add_io_dispatch($fd, 'r', \&BarnOwl::Module::IRC::OwlProcess); 360 $self->{FD} = $fd; 443 if ($self->autoconnect_channels) { 444 for my $c (@{$self->autoconnect_channels}) { 445 $self->conn->send_msg(join => $c); 446 } 447 $self->autoconnect_channels([]); 448 } 449 $self->conn->enable_ping(60, sub { 450 $self->on_disconnect("Connection timed out."); 451 $self->schedule_reconnect; 452 }); 453 $self->backoff(0); 361 454 } 362 455 363 456 sub reconnect { 364 457 my $self = shift; 365 my $backoff = shift; 366 367 $self->conn->connect; 368 if ($self->conn->connected) { 369 $self->connected("Reconnected to ".$self->alias); 370 my @channels = @{$self->channels}; 371 $self->channels([]); 372 $self->conn->join($_) for @channels; 373 return; 374 } 375 376 $backoff *= 2; 377 $backoff = 60*5 if $backoff > 60*5; 378 $self->schedule_reconnect( $backoff ); 458 my $backoff = $self->backoff; 459 460 $self->autoconnect_channels([keys(%{$self->{channel_list}})]); 461 $self->conn->connect(@{$self->connect_args}); 379 462 } 380 463 -
perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm
rb401ef2 ra27acf7 161 161 my ($recip, $account, $subject) = @_; 162 162 if (defined $recip) { 163 my @cmd = ('jwrite', $recip,'-a', $account);163 my @cmd = ('jwrite', '-a', $account); 164 164 if (defined $subject) { 165 165 push @cmd, '-s', $subject; 166 166 } 167 push @cmd, '--', $recip; 167 168 return BarnOwl::quote(@cmd); 168 169 } else { -
perlconfig.c
rf25df21 ra9237aa 403 403 } 404 404 405 sv_setpv(get_sv("BarnOwl::VERSION", TRUE), OWL_VERSION_STRING); 406 405 407 /* Add the system lib path to @INC */ 406 408 inc = get_av("INC", 0); … … 465 467 :"BarnOwl::_receive_msg_legacy_wrap", m); 466 468 } 467 if (ptr)g_free(ptr);469 g_free(ptr); 468 470 } 469 471 … … 476 478 :"BarnOwl::Hooks::_new_msg", m); 477 479 } 478 if (ptr)g_free(ptr);480 g_free(ptr); 479 481 } 480 482 … … 490 492 PUTBACK; 491 493 492 call_pv("BarnOwl::Hooks::_new_command", G_ SCALAR|G_VOID|G_EVAL);494 call_pv("BarnOwl::Hooks::_new_command", G_VOID|G_EVAL); 493 495 494 496 SPAGAIN; -
perlglue.xs
r6a71113 r3b8a563 57 57 RETVAL 58 58 CLEANUP: 59 if (rv)g_free(rv);59 g_free(rv); 60 60 61 61 SV * … … 114 114 RETVAL 115 115 CLEANUP: 116 if (rv)g_free(rv);116 g_free(rv); 117 117 118 118 const utf8 * … … 141 141 RETVAL 142 142 CLEANUP: 143 if (rv)g_free(rv);143 g_free(rv); 144 144 145 145 void … … 324 324 RETVAL 325 325 CLEANUP: 326 if (rv) 327 g_free(rv); 326 g_free(rv); 328 327 329 328 void -
select.c
rd4927a7 rf0781ba 1 1 #include "owl.h" 2 2 3 static GMainLoop *loop = NULL; 4 static GMainContext *main_context; 3 5 static int dispatch_active = 0; 4 static int psa_active = 0; 5 static int loop_active = 0; 6 7 int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) { 6 7 static GSource *owl_timer_source; 8 static GSource *owl_io_dispatch_source; 9 10 static int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) { 8 11 return t1->time - t2->time; 9 }10 11 int _owl_select_timer_eq(const owl_timer *t1, const owl_timer *t2) {12 return t1 == t2;13 12 } 14 13 … … 43 42 } 44 43 45 void owl_select_process_timers(struct timespec *timeout) 46 { 47 time_t now = time(NULL); 48 GList **timers = owl_global_get_timerlist(&g); 49 44 static gboolean owl_timer_prepare(GSource *source, int *timeout) { 45 GList **timers = owl_global_get_timerlist(&g); 46 GTimeVal now; 47 48 /* TODO: In the far /far/ future, g_source_get_time is what the cool 49 * kids use to get system monotonic time. */ 50 g_source_get_current_time(source, &now); 51 52 /* FIXME: bother with millisecond accuracy now that we can? */ 53 if (*timers) { 54 owl_timer *t = (*timers)->data; 55 *timeout = t->time - now.tv_sec; 56 if (*timeout <= 0) { 57 *timeout = 0; 58 return TRUE; 59 } 60 if (*timeout > 60 * 1000) 61 *timeout = 60 * 1000; 62 } else { 63 *timeout = 60 * 1000; 64 } 65 return FALSE; 66 } 67 68 static gboolean owl_timer_check(GSource *source) { 69 GList **timers = owl_global_get_timerlist(&g); 70 GTimeVal now; 71 72 /* TODO: In the far /far/ future, g_source_get_time is what the cool 73 * kids use to get system monotonic time. */ 74 g_source_get_current_time(source, &now); 75 76 /* FIXME: bother with millisecond accuracy now that we can? */ 77 if (*timers) { 78 owl_timer *t = (*timers)->data; 79 return t->time >= now.tv_sec; 80 } 81 return FALSE; 82 } 83 84 85 static gboolean owl_timer_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { 86 GList **timers = owl_global_get_timerlist(&g); 87 GTimeVal now; 88 89 /* TODO: In the far /far/ future, g_source_get_time is what the cool 90 * kids use to get system monotonic time. */ 91 g_source_get_current_time(source, &now); 92 93 /* FIXME: bother with millisecond accuracy now that we can? */ 50 94 while(*timers) { 51 95 owl_timer *t = (*timers)->data; 52 96 int remove = 0; 53 97 54 if(t->time > now )98 if(t->time > now.tv_sec) 55 99 break; 56 100 57 101 /* Reschedule if appropriate */ 58 102 if(t->interval > 0) { 59 t->time = now + t->interval;103 t->time = now.tv_sec + t->interval; 60 104 *timers = g_list_remove(*timers, t); 61 105 *timers = g_list_insert_sorted(*timers, t, … … 71 115 } 72 116 } 73 74 if(*timers) { 75 owl_timer *t = (*timers)->data; 76 timeout->tv_sec = t->time - now; 77 if (timeout->tv_sec > 60) 78 timeout->tv_sec = 60; 79 } else { 80 timeout->tv_sec = 60; 81 } 82 83 timeout->tv_nsec = 0; 84 } 85 86 static const owl_io_dispatch *owl_select_find_io_dispatch_by_fd(const int fd) 117 return TRUE; 118 } 119 120 static GSourceFuncs owl_timer_funcs = { 121 owl_timer_prepare, 122 owl_timer_check, 123 owl_timer_dispatch, 124 NULL 125 }; 126 127 /* Returns the valid owl_io_dispatch for a given file descriptor. */ 128 static owl_io_dispatch *owl_select_find_valid_io_dispatch_by_fd(const int fd) 87 129 { 88 130 int i, len; … … 93 135 for(i = 0; i < len; i++) { 94 136 d = owl_list_get_element(dl, i); 95 if (d->fd == fd ) return d;137 if (d->fd == fd && d->valid) return d; 96 138 } 97 139 return NULL; … … 112 154 } 113 155 return -1; 156 } 157 158 static void owl_select_invalidate_io_dispatch(owl_io_dispatch *d) 159 { 160 if (d == NULL || !d->valid) 161 return; 162 d->valid = false; 163 g_source_remove_poll(owl_io_dispatch_source, &d->pollfd); 114 164 } 115 165 … … 125 175 d->needs_gc = 1; 126 176 else { 177 owl_select_invalidate_io_dispatch(d); 127 178 owl_list_remove_element(dl, elt); 128 179 if (d->destroy) … … 134 185 } 135 186 136 void owl_select_io_dispatch_gc(void)187 static void owl_select_io_dispatch_gc(void) 137 188 { 138 189 int i; … … 152 203 } 153 204 154 /* Each FD may have at most one dispatcher.205 /* Each FD may have at most one valid dispatcher. 155 206 * If a new dispatch is added for an FD, the old one is removed. 156 207 * mode determines what types of events are watched for, and may be any combination of: … … 161 212 owl_io_dispatch *d = g_new(owl_io_dispatch, 1); 162 213 owl_list *dl = owl_global_get_io_dispatch_list(&g); 214 owl_io_dispatch *other; 163 215 164 216 d->fd = fd; 217 d->valid = true; 165 218 d->needs_gc = 0; 166 219 d->mode = mode; … … 169 222 d->data = data; 170 223 171 owl_select_remove_io_dispatch(owl_select_find_io_dispatch_by_fd(fd)); 224 /* TODO: Allow changing fd and mode in the middle? Probably don't care... */ 225 d->pollfd.fd = fd; 226 d->pollfd.events = 0; 227 if (d->mode & OWL_IO_READ) 228 d->pollfd.events |= G_IO_IN | G_IO_HUP | G_IO_ERR; 229 if (d->mode & OWL_IO_WRITE) 230 d->pollfd.events |= G_IO_OUT | G_IO_ERR; 231 if (d->mode & OWL_IO_EXCEPT) 232 d->pollfd.events |= G_IO_PRI | G_IO_ERR; 233 g_source_add_poll(owl_io_dispatch_source, &d->pollfd); 234 235 236 other = owl_select_find_valid_io_dispatch_by_fd(fd); 237 if (other) 238 owl_select_invalidate_io_dispatch(other); 172 239 owl_list_append_element(dl, d); 173 240 … … 175 242 } 176 243 177 int owl_select_prepare_io_dispatch_fd_sets(fd_set *rfds, fd_set *wfds, fd_set *efds) { 178 int i, len, max_fd; 179 owl_io_dispatch *d; 180 owl_list *dl = owl_global_get_io_dispatch_list(&g); 181 182 max_fd = 0; 244 static gboolean owl_io_dispatch_prepare(GSource *source, int *timeout) { 245 *timeout = -1; 246 return FALSE; 247 } 248 249 static gboolean owl_io_dispatch_check(GSource *source) { 250 int i, len; 251 const owl_list *dl; 252 253 dl = owl_global_get_io_dispatch_list(&g); 254 len = owl_list_get_size(dl); 255 for(i = 0; i < len; i++) { 256 owl_io_dispatch *d = owl_list_get_element(dl, i); 257 if (!d->valid) continue; 258 if (d->pollfd.revents & G_IO_NVAL) { 259 owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd); 260 owl_select_invalidate_io_dispatch(d); 261 } 262 if (d->pollfd.revents & d->pollfd.events) 263 return TRUE; 264 } 265 return FALSE; 266 } 267 268 static gboolean owl_io_dispatch_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { 269 int i, len; 270 const owl_list *dl; 271 272 dispatch_active = 1; 273 dl = owl_global_get_io_dispatch_list(&g); 183 274 len = owl_list_get_size(dl); 184 275 for (i = 0; i < len; i++) { 185 d = owl_list_get_element(dl, i); 186 if (d->mode & (OWL_IO_READ | OWL_IO_WRITE | OWL_IO_EXCEPT)) { 187 if (max_fd < d->fd) max_fd = d->fd; 188 if (d->mode & OWL_IO_READ) FD_SET(d->fd, rfds); 189 if (d->mode & OWL_IO_WRITE) FD_SET(d->fd, wfds); 190 if (d->mode & OWL_IO_EXCEPT) FD_SET(d->fd, efds); 191 } 192 } 193 return max_fd + 1; 194 } 195 196 void owl_select_io_dispatch(const fd_set *rfds, const fd_set *wfds, const fd_set *efds, const int max_fd) 197 { 198 int i, len; 199 owl_io_dispatch *d; 200 owl_list *dl = owl_global_get_io_dispatch_list(&g); 201 202 dispatch_active = 1; 203 len = owl_list_get_size(dl); 204 for (i = 0; i < len; i++) { 205 d = owl_list_get_element(dl, i); 206 if (d->fd < max_fd && d->callback != NULL && 207 ((d->mode & OWL_IO_READ && FD_ISSET(d->fd, rfds)) || 208 (d->mode & OWL_IO_WRITE && FD_ISSET(d->fd, wfds)) || 209 (d->mode & OWL_IO_EXCEPT && FD_ISSET(d->fd, efds)))) { 276 owl_io_dispatch *d = owl_list_get_element(dl, i); 277 if (!d->valid) continue; 278 if ((d->pollfd.revents & d->pollfd.events) && d->callback != NULL) { 210 279 d->callback(d, d->data); 211 280 } … … 213 282 dispatch_active = 0; 214 283 owl_select_io_dispatch_gc(); 215 } 284 285 return TRUE; 286 } 287 288 static GSourceFuncs owl_io_dispatch_funcs = { 289 owl_io_dispatch_prepare, 290 owl_io_dispatch_check, 291 owl_io_dispatch_dispatch, 292 NULL 293 }; 216 294 217 295 int owl_select_add_perl_io_dispatch(int fd, int mode, SV *cb) 218 296 { 219 const owl_io_dispatch *d = owl_select_find_ io_dispatch_by_fd(fd);297 const owl_io_dispatch *d = owl_select_find_valid_io_dispatch_by_fd(fd); 220 298 if (d != NULL && d->callback != owl_perlconfig_io_dispatch) { 221 299 /* Don't mess with non-perl dispatch functions from here. */ 222 300 return 1; 223 301 } 302 /* Also remove any invalidated perl dispatch functions that may have 303 * stuck around. */ 304 owl_select_remove_perl_io_dispatch(fd); 224 305 owl_select_add_io_dispatch(fd, mode, owl_perlconfig_io_dispatch, owl_perlconfig_io_dispatch_destroy, cb); 225 306 return 0; 226 307 } 227 308 309 static owl_io_dispatch *owl_select_find_perl_io_dispatch(int fd) 310 { 311 int i, len; 312 const owl_list *dl; 313 owl_io_dispatch *d; 314 dl = owl_global_get_io_dispatch_list(&g); 315 len = owl_list_get_size(dl); 316 for(i = 0; i < len; i++) { 317 d = owl_list_get_element(dl, i); 318 if (d->fd == fd && d->callback == owl_perlconfig_io_dispatch) 319 return d; 320 } 321 return NULL; 322 } 323 228 324 int owl_select_remove_perl_io_dispatch(int fd) 229 325 { 230 const owl_io_dispatch *d = owl_select_find_io_dispatch_by_fd(fd);231 if (d != NULL && d->callback == owl_perlconfig_io_dispatch) {326 owl_io_dispatch *d = owl_select_find_perl_io_dispatch(fd); 327 if (d != NULL) { 232 328 /* Only remove perl io dispatchers from here. */ 233 329 owl_select_remove_io_dispatch(d); … … 237 333 } 238 334 239 int owl_select_aim_hack(fd_set *rfds, fd_set *wfds) 240 { 241 aim_conn_t *cur; 242 aim_session_t *sess; 243 int max_fd; 244 245 max_fd = 0; 246 sess = owl_global_get_aimsess(&g); 247 for (cur = sess->connlist; cur; cur = cur->next) { 248 if (cur->fd != -1) { 249 FD_SET(cur->fd, rfds); 250 if (cur->status & AIM_CONN_STATUS_INPROGRESS) { 251 /* Yes, we're checking writable sockets here. Without it, AIM 252 login is really slow. */ 253 FD_SET(cur->fd, wfds); 254 } 255 256 if (cur->fd > max_fd) 257 max_fd = cur->fd; 258 } 259 } 260 return max_fd; 261 } 262 263 void owl_process_input_char(owl_input j) 264 { 265 int ret; 266 267 owl_global_set_lastinputtime(&g, time(NULL)); 268 ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); 269 if (ret!=0 && ret!=1) { 270 owl_function_makemsg("Unable to handle keypress"); 271 } 272 } 273 274 void owl_select_mask_signals(sigset_t *oldmask) { 275 sigset_t set; 276 277 sigemptyset(&set); 278 sigaddset(&set, SIGWINCH); 279 sigaddset(&set, SIGALRM); 280 sigaddset(&set, SIGPIPE); 281 sigaddset(&set, SIGTERM); 282 sigaddset(&set, SIGHUP); 283 sigaddset(&set, SIGINT); 284 sigprocmask(SIG_BLOCK, &set, oldmask); 285 } 286 287 void owl_select_handle_intr(sigset_t *restore) 288 { 289 owl_input in; 290 291 owl_global_unset_interrupted(&g); 292 293 sigprocmask(SIG_SETMASK, restore, NULL); 294 295 in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR]; 296 owl_process_input_char(in); 297 } 298 299 owl_ps_action *owl_select_add_pre_select_action(int (*cb)(owl_ps_action *, void *), void (*destroy)(owl_ps_action *), void *data) 300 { 301 owl_ps_action *a = g_new(owl_ps_action, 1); 302 owl_list *psa_list = owl_global_get_psa_list(&g); 303 a->needs_gc = 0; 304 a->callback = cb; 305 a->destroy = destroy; 306 a->data = data; 307 owl_list_append_element(psa_list, a); 308 return a; 309 } 310 311 void owl_select_psa_gc(void) 312 { 313 int i; 314 owl_list *psa_list; 315 owl_ps_action *a; 316 317 psa_list = owl_global_get_psa_list(&g); 318 for (i = owl_list_get_size(psa_list) - 1; i >= 0; i--) { 319 a = owl_list_get_element(psa_list, i); 320 if (a->needs_gc) { 321 owl_list_remove_element(psa_list, i); 322 if (a->destroy) { 323 a->destroy(a); 324 } 325 g_free(a); 326 } 327 } 328 } 329 330 void owl_select_remove_pre_select_action(owl_ps_action *a) 331 { 332 a->needs_gc = 1; 333 if (!psa_active) 334 owl_select_psa_gc(); 335 } 336 337 int owl_select_do_pre_select_actions(void) 338 { 339 int i, len, ret; 340 owl_list *psa_list; 341 342 psa_active = 1; 343 ret = 0; 344 psa_list = owl_global_get_psa_list(&g); 345 len = owl_list_get_size(psa_list); 346 for (i = 0; i < len; i++) { 347 owl_ps_action *a = owl_list_get_element(psa_list, i); 348 if (a->callback != NULL && a->callback(a, a->data)) { 349 ret = 1; 350 } 351 } 352 psa_active = 0; 353 owl_select_psa_gc(); 354 return ret; 355 } 356 357 void owl_select(void) 358 { 359 int i, max_fd, max_fd2, aim_done, ret; 360 fd_set r; 361 fd_set w; 362 fd_set e; 363 fd_set aim_rfds, aim_wfds; 364 struct timespec timeout; 365 sigset_t mask; 366 367 owl_select_process_timers(&timeout); 368 369 owl_select_mask_signals(&mask); 370 371 if(owl_global_is_interrupted(&g)) { 372 owl_select_handle_intr(&mask); 373 return; 374 } 375 FD_ZERO(&r); 376 FD_ZERO(&w); 377 FD_ZERO(&e); 378 379 max_fd = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e); 380 381 /* AIM HACK: 382 * 383 * The problem - I'm not sure where to hook into the owl/faim 384 * interface to keep track of when the AIM socket(s) open and 385 * close. In particular, the bosconn thing throws me off. So, 386 * rather than register particular dispatchers for AIM, I look up 387 * the relevant FDs and add them to select's watch lists, then 388 * check for them individually before moving on to the other 389 * dispatchers. --asedeno 390 */ 391 aim_done = 1; 392 FD_ZERO(&aim_rfds); 393 FD_ZERO(&aim_wfds); 394 if (owl_global_is_doaimevents(&g)) { 395 aim_done = 0; 396 max_fd2 = owl_select_aim_hack(&aim_rfds, &aim_wfds); 397 if (max_fd < max_fd2) max_fd = max_fd2; 398 for(i = 0; i <= max_fd2; i++) { 399 if (FD_ISSET(i, &aim_rfds)) { 400 FD_SET(i, &r); 401 FD_SET(i, &e); 402 } 403 if (FD_ISSET(i, &aim_wfds)) { 404 FD_SET(i, &w); 405 FD_SET(i, &e); 406 } 407 } 408 } 409 /* END AIM HACK */ 410 411 if (owl_select_do_pre_select_actions()) { 412 timeout.tv_sec = 0; 413 timeout.tv_nsec = 0; 414 } 415 416 ret = pselect(max_fd+1, &r, &w, &e, &timeout, &mask); 417 418 if(ret < 0 && errno == EINTR) { 419 if(owl_global_is_interrupted(&g)) { 420 owl_select_handle_intr(NULL); 421 } 422 sigprocmask(SIG_SETMASK, &mask, NULL); 423 return; 424 } 425 426 sigprocmask(SIG_SETMASK, &mask, NULL); 427 428 if(ret > 0) { 429 /* AIM HACK: process all AIM events at once. */ 430 for(i = 0; !aim_done && i <= max_fd; i++) { 431 if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) { 432 if (FD_ISSET(i, &aim_rfds) || FD_ISSET(i, &aim_wfds)) { 433 owl_process_aim(); 434 aim_done = 1; 435 } 436 } 437 } 438 owl_select_io_dispatch(&r, &w, &e, max_fd); 439 } 335 void owl_select_init(void) 336 { 337 owl_timer_source = g_source_new(&owl_timer_funcs, sizeof(GSource)); 338 g_source_attach(owl_timer_source, NULL); 339 340 owl_io_dispatch_source = g_source_new(&owl_io_dispatch_funcs, sizeof(GSource)); 341 g_source_attach(owl_io_dispatch_source, NULL); 440 342 } 441 343 442 344 void owl_select_run_loop(void) 443 345 { 444 loop_active = 1; 445 while (loop_active) { 446 owl_select(); 447 } 346 main_context = g_main_context_default(); 347 loop = g_main_loop_new(main_context, FALSE); 348 g_main_loop_run(loop); 448 349 } 449 350 450 351 void owl_select_quit_loop(void) 451 352 { 452 loop_active = 0; 453 } 353 if (loop) { 354 g_main_loop_quit(loop); 355 g_main_loop_unref(loop); 356 loop = NULL; 357 } 358 } 359 360 typedef struct _owl_task { /*noproto*/ 361 void (*cb)(void *); 362 void *cbdata; 363 void (*destroy_cbdata)(void *); 364 } owl_task; 365 366 static gboolean _run_task(gpointer data) 367 { 368 owl_task *t = data; 369 if (t->cb) 370 t->cb(t->cbdata); 371 return FALSE; 372 } 373 374 static void _destroy_task(void *data) 375 { 376 owl_task *t = data; 377 if (t->destroy_cbdata) 378 t->destroy_cbdata(t->cbdata); 379 g_free(t); 380 } 381 382 void owl_select_post_task(void (*cb)(void*), void *cbdata, void (*destroy_cbdata)(void*), GMainContext *context) 383 { 384 GSource *source = g_idle_source_new(); 385 owl_task *t = g_new0(owl_task, 1); 386 t->cb = cb; 387 t->cbdata = cbdata; 388 t->destroy_cbdata = destroy_cbdata; 389 g_source_set_priority(source, G_PRIORITY_DEFAULT); 390 g_source_set_callback(source, _run_task, t, _destroy_task); 391 g_source_attach(source, context); 392 g_source_unref(source); 393 } -
sepbar.c
r044f19f r6eb3ed9 16 16 int x, y, i; 17 17 const char *foo, *appendtosepbar; 18 int cur_numlines, cur_totallines; 18 19 19 20 ml=owl_global_get_msglist(&g); … … 50 51 wattron(sepwin, A_REVERSE); 51 52 52 if (owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) {53 getyx(sepwin, y, x);54 wmove(sepwin, y, x+2);55 wattron(sepwin, A_BOLD);56 waddstr(sepwin, " <truncated> ");57 wattroff(sepwin, A_BOLD);58 }59 60 53 i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g)); 61 54 if ((i != -1) && … … 90 83 } 91 84 85 if (owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) { 86 getyx(sepwin, y, x); 87 wmove(sepwin, y, x+2); 88 wattron(sepwin, A_BOLD); 89 cur_numlines = owl_global_get_curmsg_vert_offset(&g) + 1; 90 cur_totallines = owl_message_get_numlines(owl_view_get_element(v, owl_global_get_curmsg(&g))); 91 wprintw(sepwin, " <truncated: %d/%d> ", cur_numlines, cur_totallines); 92 wattroff(sepwin, A_BOLD); 93 } 94 92 95 if (owl_global_get_curmsg_vert_offset(&g)) { 93 96 getyx(sepwin, y, x); -
tester.c
rf25df21 re93dd78 32 32 char *perlerr; 33 33 int status = 0; 34 SCREEN *screen; 34 35 35 36 if (argc <= 1) { … … 41 42 wnull = fopen("/dev/null", "w"); 42 43 rnull = fopen("/dev/null", "r"); 43 newterm("xterm", wnull, rnull);44 screen = newterm("xterm", wnull, rnull); 44 45 /* initialize global structures */ 45 46 owl_global_init(&g); … … 91 92 /* probably not necessary, but tear down the screen */ 92 93 endwin(); 94 delscreen(screen); 93 95 fclose(rnull); 94 96 fclose(wnull); … … 218 220 owl_string_appendf_quoted(g, "%q foo %q%q %s %", "hello", "world is", "can't"); 219 221 FAIL_UNLESS("owl_string_appendf", 220 !strcmp(g _string_free(g, false),221 "hello foo 'world is'\"can't\" %s %"));222 !strcmp(g->str, "hello foo 'world is'\"can't\" %s %")); 223 g_string_free(g, true); 222 224 223 225 /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */ … … 233 235 234 236 printf("# BEGIN testing owl_dict\n"); 235 FAIL_UNLESS("create", 0==owl_dict_create(&d));237 owl_dict_create(&d); 236 238 FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete)); 237 239 FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete)); … … 249 251 FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d)); 250 252 owl_list_create(&l); 251 FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));253 owl_dict_get_keys(&d, &l); 252 254 FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l)); 253 255 -
text.c
r42ee1be r7865479 275 275 g_strfreev(split); 276 276 return out; 277 }278 279 /* replace all instances of character a in buff with the character280 * b. buff must be null terminated.281 */282 void owl_text_tr(char *buff, char a, char b)283 {284 int i;285 286 owl_function_debugmsg("In: %s", buff);287 for (i=0; buff[i]!='\0'; i++) {288 if (buff[i]==a) buff[i]=b;289 }290 owl_function_debugmsg("Out: %s", buff);291 277 } 292 278 -
util.c
re56303f r83a4af3 455 455 g_free(newfile); 456 456 fclose(old); 457 free(actual_filename);457 g_free(actual_filename); 458 458 return -1; 459 459 } … … 466 466 g_free(newfile); 467 467 fclose(old); 468 free(actual_filename);468 g_free(actual_filename); 469 469 return -1; 470 470 } … … 715 715 } 716 716 717 int owl_util_get_colorpairs(void) { 718 #ifndef NCURSES_EXT_COLORS 719 /* Without ext-color support (an ABI change), ncurses only supports 256 720 * different color pairs. However, it gives us a larger number even if your 721 * ncurses is compiled without ext-color. */ 722 return MIN(COLOR_PAIRS, 256); 723 #else 724 return COLOR_PAIRS; 725 #endif 726 } 727 717 728 gulong owl_dirty_window_on_signal(owl_window *w, gpointer sender, const gchar *detailed_signal) 718 729 { -
variable.c
rf203cad r4c7c21f 559 559 int owl_variable_dict_setup(owl_vardict *vd) { 560 560 owl_variable *var, *cur; 561 if (owl_dict_create(vd)) return(-1);561 owl_dict_create(vd); 562 562 for (var = variables_to_init; var->name != NULL; var++) { 563 563 cur = g_new(owl_variable, 1); … … 641 641 642 642 void owl_variable_update(owl_variable *var, const char *summary, const char *desc) { 643 if(var->summary)g_free(var->summary);643 g_free(var->summary); 644 644 var->summary = g_strdup(summary); 645 if(var->description)g_free(var->description);645 g_free(var->description); 646 646 var->description = g_strdup(desc); 647 647 } … … 651 651 if(old) { 652 652 owl_variable_update(old, summ, desc); 653 if(old->pval_default)g_free(old->pval_default);653 g_free(old->pval_default); 654 654 old->pval_default = g_strdup(initval); 655 655 } else { … … 944 944 void owl_variable_delete_default(owl_variable *v) 945 945 { 946 if (v->val)g_free(v->val);946 g_free(v->val); 947 947 } 948 948 … … 1076 1076 if (!v->validate_fn(v, newval)) return(-1); 1077 1077 } 1078 if (v->val)g_free(v->val);1078 g_free(v->val); 1079 1079 v->val = g_strdup(newval); 1080 1080 return(0); -
view.c
rd4927a7 r3b8a563 160 160 { 161 161 owl_list_cleanup(&v->ml.list, NULL); 162 if (v->name)g_free(v->name);162 g_free(v->name); 163 163 } -
window.c
rb31f1c9 rf97c1a6 524 524 owl_window_set_position(w, nlines, ncols, w->begin_y, w->begin_x); 525 525 } 526 527 /** Redrawing main loop hooks **/ 528 529 static bool _owl_window_should_redraw(void) { 530 return g.resizepending || owl_window_get_screen()->dirty_subtree; 531 } 532 533 static gboolean _owl_window_redraw_prepare(GSource *source, int *timeout) { 534 *timeout = -1; 535 return _owl_window_should_redraw(); 536 } 537 538 static gboolean _owl_window_redraw_check(GSource *source) { 539 return _owl_window_should_redraw(); 540 } 541 542 static gboolean _owl_window_redraw_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { 543 owl_colorpair_mgr *cpmgr; 544 545 /* if a resize has been scheduled, deal with it */ 546 owl_global_check_resize(&g); 547 /* update the terminal if we need to */ 548 owl_window_redraw_scheduled(); 549 /* On colorpair shortage, reset and redraw /everything/. NOTE: if we 550 * still overflow, this be useless work. With 8-colors, we get 64 551 * pairs. With 256-colors, we get 32768 pairs with ext-colors 552 * support and 256 otherwise. */ 553 cpmgr = owl_global_get_colorpair_mgr(&g); 554 if (cpmgr->overflow) { 555 owl_function_debugmsg("colorpairs: used all %d pairs; reset pairs and redraw.", 556 owl_util_get_colorpairs()); 557 owl_fmtext_reset_colorpairs(cpmgr); 558 owl_function_full_redisplay(); 559 owl_window_redraw_scheduled(); 560 } 561 return TRUE; 562 } 563 564 static GSourceFuncs redraw_funcs = { 565 _owl_window_redraw_prepare, 566 _owl_window_redraw_check, 567 _owl_window_redraw_dispatch, 568 NULL 569 }; 570 571 GSource *owl_window_redraw_source_new(void) { 572 GSource *source; 573 source = g_source_new(&redraw_funcs, sizeof(GSource)); 574 /* TODO: priority?? */ 575 return source; 576 } -
zcrypt.c
r1dd285b r5b197f7 11 11 #include <unistd.h> 12 12 #include <sys/types.h> 13 #include <zephyr/zephyr.h>14 13 #include <glib.h> 15 14 #include <string.h> … … 476 475 477 476 for(i = 0; i < MAX_SEARCH; i++) { 478 if(varname[i] != NULL) { 479 g_free(varname[i]); 480 } 481 } 482 483 if(filename != NULL) { 484 g_free(filename); 485 } 477 g_free(varname[i]); 478 } 479 480 g_free(filename); 486 481 487 482 return keyfile; … … 773 768 err = call_filter("gpg", argv, in, &out, &status); 774 769 if(err || status) { 775 if(out)g_free(out);770 g_free(out); 776 771 return FALSE; 777 772 } … … 856 851 err = call_filter("gpg", argv, in, &out, &status); 857 852 if(err || status) { 858 if(out)g_free(out);853 g_free(out); 859 854 return FALSE; 860 855 } -
zephyr.c
rf203cad rb848e30 8 8 9 9 #ifdef HAVE_LIBZEPHYR 10 static GSource *owl_zephyr_event_source_new(int fd); 11 12 static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout); 13 static gboolean owl_zephyr_event_check(GSource *source); 14 static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data); 15 10 16 static GList *deferred_subs = NULL; 11 17 … … 16 22 17 23 Code_t ZResetAuthentication(void); 24 25 static GSourceFuncs zephyr_event_funcs = { 26 owl_zephyr_event_prepare, 27 owl_zephyr_event_check, 28 owl_zephyr_event_dispatch, 29 NULL 30 }; 18 31 #endif 19 32 … … 84 97 Code_t code; 85 98 char *perl; 99 GSource *event_source; 86 100 87 101 owl_select_remove_io_dispatch(d); … … 99 113 } 100 114 101 owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_process_events, NULL, NULL); 115 event_source = owl_zephyr_event_source_new(ZGetFD()); 116 g_source_attach(event_source, NULL); 117 g_source_unref(event_source); 102 118 103 119 owl_global_set_havezephyr(&g); … … 127 143 perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()"); 128 144 g_free(perl); 129 130 owl_select_add_pre_select_action(owl_zephyr_pre_select_action, NULL, NULL);131 145 } 132 146 … … 180 194 if((code = ZPending()) < 0) { 181 195 owl_function_debugmsg("Error (%s) in ZPending()\n", 196 error_message(code)); 197 return 0; 198 } 199 return code; 200 } 201 #endif 202 return 0; 203 } 204 205 int owl_zephyr_zqlength(void) 206 { 207 #ifdef HAVE_LIBZEPHYR 208 Code_t code; 209 if(owl_global_is_havezephyr(&g)) { 210 if((code = ZQLength()) < 0) { 211 owl_function_debugmsg("Error (%s) in ZQLength()\n", 182 212 error_message(code)); 183 213 return 0; … … 417 447 return 0; 418 448 } 419 if (buffer) 420 g_free(buffer); 449 g_free(buffer); 421 450 422 451 return owl_zephyr_loadsubs_helper(subs, count); … … 1422 1451 #define OWL_MAX_ZEPHYRGRAMS_TO_PROCESS 20 1423 1452 1453 #ifdef HAVE_LIBZEPHYR 1424 1454 static int _owl_zephyr_process_events(void) 1425 1455 { 1426 1456 int zpendcount=0; 1427 #ifdef HAVE_LIBZEPHYR1428 1457 ZNotice_t notice; 1429 1458 Code_t code; … … 1466 1495 } 1467 1496 } 1468 #endif1469 1497 return zpendcount; 1470 1498 } 1471 1499 1472 void owl_zephyr_process_events(const owl_io_dispatch *d, void *data) 1473 { 1500 typedef struct { /*noproto*/ 1501 GSource source; 1502 GPollFD poll_fd; 1503 } owl_zephyr_event_source; 1504 1505 static GSource *owl_zephyr_event_source_new(int fd) { 1506 GSource *source; 1507 owl_zephyr_event_source *event_source; 1508 1509 source = g_source_new(&zephyr_event_funcs, sizeof(owl_zephyr_event_source)); 1510 event_source = (owl_zephyr_event_source*) source; 1511 event_source->poll_fd.fd = fd; 1512 event_source->poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_PRI | G_IO_ERR; 1513 g_source_add_poll(source, &event_source->poll_fd); 1514 1515 return source; 1516 } 1517 1518 static gboolean owl_zephyr_event_prepare(GSource *source, int *timeout) { 1519 *timeout = -1; 1520 return owl_zephyr_zqlength() > 0; 1521 } 1522 1523 static gboolean owl_zephyr_event_check(GSource *source) { 1524 owl_zephyr_event_source *event_source = (owl_zephyr_event_source*)source; 1525 if (event_source->poll_fd.revents & event_source->poll_fd.events) 1526 return owl_zephyr_zpending() > 0; 1527 return FALSE; 1528 } 1529 1530 static gboolean owl_zephyr_event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { 1474 1531 _owl_zephyr_process_events(); 1475 } 1476 1477 int owl_zephyr_pre_select_action(owl_ps_action *a, void *p) 1478 { 1479 return _owl_zephyr_process_events(); 1480 } 1532 return TRUE; 1533 } 1534 #endif -
zwrite.c
r3f52e14 r3b8a563 185 185 void owl_zwrite_set_message_raw(owl_zwrite *z, const char *msg) 186 186 { 187 if (z->message)g_free(z->message);187 g_free(z->message); 188 188 z->message = owl_validate_utf8(msg); 189 189 } … … 195 195 char *tmp = NULL, *tmp2; 196 196 197 if (z->message)g_free(z->message);197 g_free(z->message); 198 198 199 199 j=owl_list_get_size(&(z->recips)); … … 289 289 void owl_zwrite_set_opcode(owl_zwrite *z, const char *opcode) 290 290 { 291 if (z->opcode)g_free(z->opcode);291 g_free(z->opcode); 292 292 z->opcode=owl_validate_utf8(opcode); 293 293 } … … 306 306 void owl_zwrite_set_zsig(owl_zwrite *z, const char *zsig) 307 307 { 308 if(z->zsig)g_free(z->zsig);308 g_free(z->zsig); 309 309 z->zsig = g_strdup(zsig); 310 310 } … … 353 353 { 354 354 owl_list_cleanup(&(z->recips), &g_free); 355 if (z->cmd)g_free(z->cmd);356 if (z->zwriteline)g_free(z->zwriteline);357 if (z->class)g_free(z->class);358 if (z->inst)g_free(z->inst);359 if (z->opcode)g_free(z->opcode);360 if (z->realm)g_free(z->realm);361 if (z->message)g_free(z->message);362 if (z->zsig)g_free(z->zsig);355 g_free(z->cmd); 356 g_free(z->zwriteline); 357 g_free(z->class); 358 g_free(z->inst); 359 g_free(z->opcode); 360 g_free(z->realm); 361 g_free(z->message); 362 g_free(z->zsig); 363 363 } 364 364
Note: See TracChangeset
for help on using the changeset viewer.