Changeset f4d817d
- Timestamp:
- Feb 11, 2009, 12:37:35 PM (16 years ago)
- Branches:
- debian
- Children:
- 14489be
- Parents:
- 3bc7358 (diff), b4c270c (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:
-
- 13 added
- 2 deleted
- 41 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.in
r8d07892a rf4d817d 5 5 prefix = @prefix@ 6 6 exec_prefix = @exec_prefix@ 7 datarootdir = @datarootdir@ 7 8 datadir = @datadir@/barnowl 8 9 bindir = @bindir@ … … 25 26 regex.c history.c view.c dict.c variable.c filterelement.c pair.c \ 26 27 keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \ 27 aim.c buddy.c buddylist.c timer.cstyle.c errqueue.c \28 zbuddylist.c muxevents.cpopexec.c obarray.c select.c wcwidth.c \28 aim.c buddy.c buddylist.c style.c errqueue.c \ 29 zbuddylist.c popexec.c obarray.c select.c wcwidth.c \ 29 30 glib_compat.c 30 31 OWL_SRC = owl.c … … 53 54 $(ATHSTATIC) $(CC) -o $(EXE) owl.o $(OBJS) $(LDFLAGS) $(LIBS) 54 55 55 tester: $(AUTOGEN) $(OBJS) tester.o 56 tester: $(AUTOGEN) $(OBJS) tester.o libfaim 56 57 $(ATHSTATIC) $(CC) -o tester tester.o $(OBJS) $(LDFLAGS) $(LIBS) 57 58 -
aim.c
rdb0ac7e rc675b39 130 130 } 131 131 132 void owl_aim_send_nop(owl_timer *t, void *data) { 133 if(owl_global_is_doaimevents(&g)) { 134 aim_session_t *sess = owl_global_get_aimsess(&g); 135 aim_flap_nop(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS)); 136 } 137 } 138 132 139 133 140 int owl_aim_login(char *screenname, char *password) … … 194 201 owl_function_debugmsg("owl_aim_login: connecting"); 195 202 203 g.aim_nop_timer = owl_select_add_timer(30, 30, owl_aim_send_nop, NULL, NULL); 204 196 205 return(0); 206 } 207 208 void owl_aim_unset_ignorelogin(owl_timer *t, void *data) { /* noproto */ 209 owl_global_unset_ignore_aimlogin(&g); 197 210 } 198 211 … … 212 225 213 226 /* start the ingorelogin timer */ 214 owl_ timer_reset_newstart(owl_global_get_aim_login_timer(&g),215 owl_global_get_aim_ignorelogin_timer(&g)); 216 217 227 owl_global_set_ignore_aimlogin(&g); 228 owl_select_add_timer(owl_global_get_aim_ignorelogin_timer(&g), 229 0, owl_aim_unset_ignorelogin, NULL, NULL); 230 218 231 /* aim_ssi_setpresence(owl_global_get_aimsess(&g), 0x00000400); */ 219 232 /* aim_bos_setidle(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), 5000); */ … … 228 241 owl_global_set_aimnologgedin(&g); 229 242 owl_global_set_no_doaimevents(&g); 243 owl_select_remove_timer(g.aim_nop_timer); 230 244 } 231 245 … … 239 253 { 240 254 if (message) { 241 owl_function_error( message);255 owl_function_error("%s", message); 242 256 } else { 243 257 owl_function_error("Authentication error on login"); … … 246 260 owl_global_set_aimnologgedin(&g); 247 261 owl_global_set_no_doaimevents(&g); 262 owl_select_remove_timer(g.aim_nop_timer); 248 263 } 249 264 … … 252 267 int ret; 253 268 254 ret=aim_im_sendch1(owl_global_get_aimsess(&g), to, NULL, msg);269 ret=aim_im_sendch1(owl_global_get_aimsess(&g), to, 0, msg); 255 270 256 271 /* I don't know how to check for an error yet */ … … 422 437 tv.tv_usec = 0; 423 438 waitingconn = aim_select(aimsess, &tv, &selstat); 424 425 if (owl_global_is_aimnop_time(&g)) {426 aim_flap_nop(aimsess, aim_getconn_type(aimsess, AIM_CONN_TYPE_BOS));427 owl_global_aimnop_sent(&g);428 }429 439 430 440 if (selstat == -1) { … … 1698 1708 1699 1709 /* printf("snac threw error (reason 0x%04x: %s)\n", reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */ 1700 if (reason<msgerrreasonslen) owl_function_error( msgerrreasons[reason]);1710 if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]); 1701 1711 1702 1712 return 1; … … 1715 1725 1716 1726 /* printf("message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */ 1717 if (reason<msgerrreasonslen) owl_function_error( msgerrreasons[reason]);1727 if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]); 1718 1728 1719 1729 if (reason==4) { … … 1736 1746 1737 1747 /* printf("user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */ 1738 if (reason<msgerrreasonslen) owl_function_error( msgerrreasons[reason]);1748 if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]); 1739 1749 1740 1750 return 1; … … 2309 2319 aim_sendcookie(sess, tstconn, redir->cookielen, redir->cookie); 2310 2320 return; 2321 } 2322 2323 void owl_process_aim() 2324 { 2325 if (owl_global_is_doaimevents(&g)) { 2326 owl_aim_process_events(); 2327 } 2311 2328 } 2312 2329 -
buddylist.c
r257a22f rb7bb454 51 51 52 52 /* are we ingoring login messages for a while? */ 53 if ( !owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;53 if (owl_global_is_ignore_aimlogin(&g)) return; 54 54 55 55 /* if not, create the login message */ -
commands.c
r451db9e rf34dd65 453 453 OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN, 454 454 "pops up a message in a window", "", ""), 455 456 OWLCMD_VOID("openurl", owl_command_openurl, OWL_CTX_INTERACTIVE,457 "opens up a URL from the current message",458 "",459 "Uses the 'webbrowser' variable to determine\n"460 "which browser to use. Currently, 'netscape'\n"461 "and 'galeon' are supported.\n"),462 455 463 456 OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE, … … 641 634 "show keymap <keymap>\n" 642 635 "show license\n" 636 "show quickstart\n" 643 637 "show startup\n" 644 638 "show status\n" … … 1046 1040 void owl_command_version() 1047 1041 { 1048 char buff[1024]; 1049 1050 sprintf(buff, "Owl version %s", OWL_VERSION_STRING); 1051 owl_function_makemsg(buff); 1042 owl_function_makemsg("BarnOwl version %s", OWL_VERSION_STRING); 1052 1043 } 1053 1044 … … 1461 1452 owl_function_aaway_on(); 1462 1453 owl_function_zaway_on(); 1463 owl_function_makemsg("Away messages set." , owl_global_get_aaway_msg_default(&g));1454 owl_function_makemsg("Away messages set."); 1464 1455 return NULL; 1465 1456 } … … 1691 1682 } 1692 1683 1693 owl_function_debugmsg( argv[1]);1684 owl_function_debugmsg("%s", argv[1]); 1694 1685 return(NULL); 1695 1686 } … … 1735 1726 return(NULL); 1736 1727 } 1737 1738 1739 void owl_command_zlog_out(void)1740 {1741 owl_zephyr_zlog_out();1742 }1743 1744 1728 1745 1729 char *owl_command_subscribe(int argc, char **argv, char *buff) … … 2207 2191 } else if (!strcmp(argv[1], "license")) { 2208 2192 owl_function_show_license(); 2193 } else if (!strcmp(argv[1], "quickstart")) { 2194 owl_function_show_quickstart(); 2209 2195 } else if (!strcmp(argv[1], "startup")) { 2210 2196 char *filename; … … 2251 2237 { 2252 2238 owl_function_curmsg_to_popwin(); 2253 }2254 2255 void owl_command_openurl(void)2256 {2257 owl_function_openurl();2258 2239 } 2259 2240 … … 2580 2561 { 2581 2562 buff = skiptokens(buff, 1); 2582 owl_function_error( buff);2563 owl_function_error("%s", buff); 2583 2564 return NULL; 2584 2565 } … … 2587 2568 { 2588 2569 buff = skiptokens(buff, 1); 2589 owl_function_makemsg( buff);2570 owl_function_makemsg("%s", buff); 2590 2571 return NULL; 2591 2572 } -
configure.ac
rd9337637 rd54035d 46 46 fi 47 47 48 AC_CHECK_LIB(ncursesw, initscr,, AC_MSG_ERROR(No curses libraryfound.))48 AC_CHECK_LIB(ncursesw, initscr,, AC_MSG_ERROR(No libncursesw found.)) 49 49 AC_CHECK_LIB(com_err, com_err) 50 50 AC_CHECK_LIB(nsl, gethostbyname) -
editwin.c
re9bb404 r50e671c 1042 1042 if (e->buff[i] == '\n' && e->buff[i+1] == '\n') break; 1043 1043 1044 /* bail if we hit a trailing dot on the buffer */ 1045 if (e->buff[i] == '\n' && e->buff[i+1] == '.' 1046 && ((i+2) >= e->bufflen || e->buff[i+2] == '\0')) 1047 break; 1048 1044 1049 /* if we've travelled too far, linewrap */ 1045 1050 if ((e->buffx) >= e->fillcol) { -
examples/owlconf.erik
r5d9c664 r4f15e8e 147 147 owl::command("set -q rxping on"); 148 148 owl::command("set -q typewinsize 5"); 149 if ($ENV{"DISPLAY"} eq ":0.0") {150 owl::command("set -q webbrowser galeon");151 }152 149 owl::command("filter me recipient %me% or ( sender %me% and class message and instance personal ) or class mail or type aim"); 153 150 owl::command("filter owl instance ^owl.*"); -
examples/owlconf.simple
r2b14303 r4f15e8e 93 93 # owl::command('set -q view_home all'); 94 94 95 96 ## Which webbrowser to use to launch URLs with the 'w' key.97 # owl::command('set -q webbrowser netscape');98 # owl::command('set -q webbrowser galeon');99 # owl::command('set -q webbrowser none');100 95 101 96 ## Default message to send when zaway is on (toggle with 'A') -
filter.c
rcdc6ff1 rf34dd65 3 3 4 4 static const char fileIdent[] = "$Id$"; 5 6 #define OWL_FILTER_MAXRECURSE 207 5 8 6 int owl_filter_init_fromstring(owl_filter *f, char *name, char *string) … … 20 18 { 21 19 f->name=owl_strdup(name); 22 f->polarity=0;23 20 f->fgcolor=OWL_COLOR_DEFAULT; 24 21 f->bgcolor=OWL_COLOR_DEFAULT; … … 50 47 /* Now check for recursion. */ 51 48 if (owl_filter_is_toodeep(f)) { 52 owl_function_error("Filter loop or exceeds recursion depth");49 owl_function_error("Filter loop!"); 53 50 owl_filter_free(f); 54 51 return(-1); … … 159 156 } 160 157 161 void owl_filter_set_polarity_match(owl_filter *f)162 {163 f->polarity=0;164 }165 166 void owl_filter_set_polarity_unmatch(owl_filter *f)167 {168 f->polarity=1;169 }170 171 158 void owl_filter_set_fgcolor(owl_filter *f, int color) 172 159 { … … 207 194 if(!f->root) return 0; 208 195 ret = owl_filterelement_match(f->root, m); 209 if(f->polarity) ret = !ret;210 196 return ret; 211 197 } … … 313 299 int numfailed=0; 314 300 owl_message m; 315 owl_filter f1, f2, f3, f4 ;301 owl_filter f1, f2, f3, f4, f5; 316 302 317 303 owl_list_create(&(g.filterlist)); … … 365 351 FAIL_UNLESS("mutual recursion", owl_filter_init_fromstring(&f4, "f4", "filter f3")); 366 352 353 /* support referencing a filter several times */ 354 FAIL_UNLESS("DAG", !owl_filter_init_fromstring(&f5, "dag", "filter f1 or filter f1")); 355 367 356 return 0; 368 357 } -
filterelement.c
r0504f63 rf446454 279 279 } 280 280 281 static int fe_visiting = 0; 282 static int fe_visited = 1; 283 281 284 int owl_filterelement_is_toodeep(owl_filter *f, owl_filterelement *fe) 282 285 { 283 int one = 1; 284 owl_list nodes; 286 int rv; 285 287 owl_dict filters; 286 owl_list_create(&nodes);287 288 owl_dict_create(&filters); 288 289 owl_list_append_element(&nodes, fe); 290 owl_dict_insert_element(&filters, f->name, &one, NULL); 291 while(owl_list_get_size(&nodes)) { 292 fe = owl_list_get_element(&nodes, 0); 293 owl_list_remove_element(&nodes, 0); 294 if(fe->left) owl_list_append_element(&nodes, fe->left); 295 if(fe->right) owl_list_append_element(&nodes, fe->right); 296 if(fe->match_message == owl_filterelement_match_filter) { 297 if(owl_dict_find_element(&filters, fe->field)) return 1; 298 owl_dict_insert_element(&filters, fe->field, &one, NULL); 289 290 owl_dict_insert_element(&filters, f->name, &fe_visiting, owl_dict_noop_free); 291 292 rv = _owl_filterelement_is_toodeep(fe, &filters); 293 294 owl_dict_free_simple(&filters); 295 return rv; 296 } 297 298 int _owl_filterelement_is_toodeep(owl_filterelement *fe, owl_dict *seen) 299 { 300 int rv = 0; 301 owl_filter *f; 302 303 if(fe->match_message == owl_filterelement_match_filter) { 304 int *nval = owl_dict_find_element(seen, fe->field); 305 if(nval == &fe_visiting) { 306 return 1; 307 } else if (nval == NULL) { 299 308 f = owl_global_get_filter(&g, fe->field); 300 if(f) owl_list_append_element(&nodes, f->root); 309 owl_dict_insert_element(seen, fe->field, &fe_visiting, owl_dict_noop_free); 310 if(f) rv = _owl_filterelement_is_toodeep(f->root, seen); 311 owl_dict_insert_element(seen, fe->field, &fe_visited, owl_dict_noop_free); 301 312 } 302 } 303 304 owl_list_free_simple(&nodes); 305 owl_dict_free_simple(&filters); 306 return 0; 313 } else { 314 if(fe->left) 315 rv = rv || _owl_filterelement_is_toodeep(fe->left, seen); 316 if(fe->right) 317 rv = rv || _owl_filterelement_is_toodeep(fe->right, seen); 318 } 319 return rv; 307 320 } 308 321 -
fmtext.c
r6f6330b r1490327 90 90 } 91 91 92 /* Append normal, uncolored text specified by format string to 'f' */ 93 void owl_fmtext_appendf_normal(owl_fmtext *f, char *fmt, ...) 94 { 95 va_list ap; 96 char *buff; 97 98 va_start(ap, fmt); 99 buff = g_strdup_vprintf(fmt, ap); 100 va_end(ap); 101 if (!buff) 102 return; 103 owl_fmtext_append_attr(f, buff, OWL_FMTEXT_ATTR_NONE, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT); 104 } 105 92 106 /* Append normal text 'text' to 'f' with color 'color' */ 93 107 void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int fgcolor, int bgcolor) … … 169 183 170 184 /* Internal function. Append text from 'in' between index 'start' and 171 * 'stop' to the end of 'f' 185 * 'stop', inclusive, to the end of 'f'. This function works with 186 * bytes. 172 187 */ 173 188 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/ … … 474 489 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 475 490 } 491 else if (chwidth > 1) { 492 /* Last char is wide, truncate. */ 493 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); 494 owl_fmtext_append_normal(out, "\n"); 495 } 476 496 else { 477 if (chwidth > 1) { 478 /* Last char is wide, truncate. */ 479 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); 480 owl_fmtext_append_normal(out, "\n"); 481 } 482 else { 483 /* Last char fits perfectly, leave alone.*/ 484 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 485 } 497 /* Last char fits perfectly, We skip to the next char and back 498 * up a byte to make sure we get it all. 499 */ 500 ptr_c = g_utf8_next_char(ptr_c); 501 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff - 1); 486 502 } 487 503 } … … 763 779 * If format_fn is specified, passes it the list element value 764 780 * and it will return a string which this needs to free. */ 765 void owl_fmtext_append_list(owl_fmtext *f, owl_list *l, char *join_with, char *(format_fn)( void*))781 void owl_fmtext_append_list(owl_fmtext *f, owl_list *l, char *join_with, char *(format_fn)(char *)) 766 782 { 767 783 int i, size; 768 void*elem;784 char *elem; 769 785 char *text; 770 786 -
functions.c
r3f3ee61 rb4c270c 15 15 static const char fileIdent[] = "$Id$"; 16 16 17 void owl_function_noop(void)18 {19 return;20 }21 22 17 char *owl_function_command(char *cmdbuff) 23 18 { … … 99 94 } 100 95 101 char *owl_function_style_describe( void*name) {96 char *owl_function_style_describe(char *name) { 102 97 char *desc, *s; 103 98 owl_style *style; … … 114 109 } 115 110 116 char *owl_function_cmd_describe( void*name)111 char *owl_function_cmd_describe(char *name) 117 112 { 118 113 owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name); … … 172 167 } 173 168 169 void owl_function_show_quickstart() 170 { 171 char *message = 172 "Move between messages with the arrow keys, and press 'r' to reply.\n" 173 "For more info, press 'h' or visit http://barnowl.mit.edu/\n\n" 174 #ifdef HAVE_LIBZEPHYR 175 "@b(Zephyr:)\n" 176 "To send a message to a user, type ':zwrite @b(username)'. You can also\n" 177 "press 'z' and then type the username. To subscribe to a class, type\n" 178 "':sub @b(class)', and then type ':zwrite -c @b(class)' to send.\n\n" 179 #endif 180 "@b(AIM:)\n" 181 "Log in to AIM with ':aimlogin @b(screenname)'. Use ':aimwrite @b(screenname)',\n" 182 "or 'a' and then the screen name, to send someone a message.\n\n" 183 ; 184 185 if (owl_perlconfig_is_function("BarnOwl::Hooks::_get_quickstart")) { 186 char *perlquickstart = owl_perlconfig_execute("BarnOwl::Hooks::_get_quickstart()"); 187 if (perlquickstart) { 188 char *result = owl_sprintf("%s%s", message, perlquickstart); 189 owl_function_adminmsg("BarnOwl Quickstart", result); 190 owl_free(result); 191 owl_free(perlquickstart); 192 return; 193 } 194 } 195 owl_function_adminmsg("BarnOwl Quickstart", message); 196 } 197 198 174 199 /* Create an admin message, append it to the global list of messages 175 200 * and redisplay if necessary. … … 602 627 603 628 if (!found) { 604 owl_function_makemsg("already at last%s message%s%s ",629 owl_function_makemsg("already at last%s message%s%s%s", 605 630 skip_deleted?" non-deleted":"", 606 filter?" in ":"", filter?filter:""); 631 filter?" in ":"", filter?filter:"", 632 owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g)) ? 633 ", press Enter to scroll" : ""); 607 634 /* if (!skip_deleted) owl_function_beep(); */ 608 635 } … … 684 711 owl_function_prevmsg_full(NULL, 1, 1); 685 712 } 686 687 void owl_function_nextmsg_personal()688 {689 owl_function_nextmsg_full("personal", 0, 0);690 }691 692 void owl_function_prevmsg_personal()693 {694 owl_function_prevmsg_full("personal", 0, 0);695 }696 697 713 698 714 /* if move_after is 1, moves after the delete */ … … 1019 1035 owl_function_debugmsg("Quitting Owl"); 1020 1036 exit(0); 1021 }1022 1023 void owl_function_openurl()1024 {1025 /* visit the first url in the current message */1026 owl_message *m;1027 owl_view *v;1028 char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE];1029 int webbrowser;1030 1031 webbrowser = owl_global_get_webbrowser(&g);1032 1033 if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) {1034 owl_function_error("No browser selected");1035 return;1036 }1037 1038 v=owl_global_get_current_view(&g);1039 1040 m=owl_view_get_element(v, owl_global_get_curmsg(&g));1041 1042 if (!m || owl_view_get_size(v)==0) {1043 owl_function_error("No current message selected");1044 return;1045 }1046 1047 text=owl_message_get_text(m);1048 1049 /* First look for a good URL */1050 if ((ptr1=strstr(text, "http://"))!=NULL) {1051 ptr2=strpbrk(ptr1, " \n\t");1052 if (ptr2) {1053 strncpy(url, ptr1, ptr2-ptr1+1);1054 url[ptr2-ptr1+1]='\0';1055 } else {1056 strcpy(url, ptr1);1057 }1058 1059 /* if we had <http strip a trailing > */1060 if (ptr1>text && ptr1[-1]=='<') {1061 if (url[strlen(url)-1]=='>') {1062 url[strlen(url)-1]='\0';1063 }1064 }1065 } else if ((ptr1=strstr(text, "https://"))!=NULL) {1066 /* Look for an https URL */1067 ptr2=strpbrk(ptr1, " \n\t");1068 if (ptr2) {1069 strncpy(url, ptr1, ptr2-ptr1+1);1070 url[ptr2-ptr1+1]='\0';1071 } else {1072 strcpy(url, ptr1);1073 }1074 1075 /* if we had <http strip a trailing > */1076 if (ptr1>text && ptr1[-1]=='<') {1077 if (url[strlen(url)-1]=='>') {1078 url[strlen(url)-1]='\0';1079 }1080 }1081 } else if ((ptr1=strstr(text, "www."))!=NULL) {1082 /* if we can't find a real url look for www.something */1083 ptr2=strpbrk(ptr1, " \n\t");1084 if (ptr2) {1085 strncpy(url, ptr1, ptr2-ptr1+1);1086 url[ptr2-ptr1+1]='\0';1087 } else {1088 strcpy(url, ptr1);1089 }1090 } else {1091 owl_function_beep();1092 owl_function_error("Could not find URL to open.");1093 return;1094 }1095 1096 /* Make sure there aren't any quotes or \'s in the url */1097 for (ptr1 = url; *ptr1; ptr1++) {1098 if (*ptr1 == '"' || *ptr1 == '\\') {1099 owl_function_beep();1100 owl_function_error("URL contains invalid characters.");1101 return;1102 }1103 }1104 1105 /* NOTE: There are potentially serious security issues here... */1106 1107 /* open the page */1108 owl_function_makemsg("Opening %s", url);1109 if (webbrowser == OWL_WEBBROWSER_NETSCAPE) {1110 snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url);1111 system(tmpbuff);1112 } else if (webbrowser == OWL_WEBBROWSER_GALEON) {1113 snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url);1114 system(tmpbuff);1115 } else if (webbrowser == OWL_WEBBROWSER_OPERA) {1116 snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url);1117 system(tmpbuff);1118 }1119 1037 } 1120 1038 … … 1344 1262 } 1345 1263 1346 void owl_function_refresh()1347 {1348 owl_function_resize();1349 }1350 1351 1264 void owl_function_beep() 1352 1265 { … … 1471 1384 void owl_function_about() 1472 1385 { 1473 char buff[5000]; 1474 1475 sprintf(buff, "This is barnowl version %s\n\n", OWL_VERSION_STRING); 1476 strcat(buff, "barnowl is a fork of the Owl zephyr client, written and\n"); 1477 strcat(buff, "maintained by Alejandro Sedeno and Nelson Elhage at the\n"); 1478 strcat(buff, "Massachusetts Institute of Technology. \n"); 1479 strcat(buff, "\n"); 1480 strcat(buff, "Owl was written by James Kretchmar. The first version, 0.5, was\n"); 1481 strcat(buff, "released in March 2002.\n"); 1482 strcat(buff, "\n"); 1483 strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n"); 1484 strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n"); 1485 strcat(buff, "between Witches and Wizards. The name 'barnowl' was chosen\n"); 1486 strcat(buff, "because we feel our owls should live closer to our ponies.\n"); 1487 strcat(buff, "\n"); 1488 strcat(buff, "Copyright (c) 2006-2008 The BarnOwl Developers. All rights reserved.\n"); 1489 strcat(buff, "Copyright (c) 2004 James Kretchmar. All rights reserved.\n"); 1490 strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n"); 1491 strcat(buff, "\n"); 1492 strcat(buff, "This program is free software. You can redistribute it and/or\n"); 1493 strcat(buff, "modify under the terms of the Sleepycat License. Use the \n"); 1494 strcat(buff, "':show license' command to display the full license\n"); 1495 owl_function_popless_text(buff); 1386 owl_function_popless_text( 1387 "This is barnowl version " OWL_VERSION_STRING ".\n\n" 1388 "barnowl is a fork of the Owl zephyr client, written and\n" 1389 "maintained by Alejandro Sedeno and Nelson Elhage at the\n" 1390 "Massachusetts Institute of Technology. \n" 1391 "\n" 1392 "Owl was written by James Kretchmar. The first version, 0.5, was\n" 1393 "released in March 2002.\n" 1394 "\n" 1395 "The name 'owl' was chosen in reference to the owls in the\n" 1396 "Harry Potter novels, who are tasked with carrying messages\n" 1397 "between Witches and Wizards. The name 'barnowl' was chosen\n" 1398 "because we feel our owls should live closer to our ponies.\n" 1399 "\n" 1400 "Copyright (c) 2006-2008 The BarnOwl Developers. All rights reserved.\n" 1401 "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" 1402 "Copyright 2002 Massachusetts Institute of Technology\n" 1403 "\n" 1404 "This program is free software. You can redistribute it and/or\n" 1405 "modify under the terms of the Sleepycat License. Use the \n" 1406 "':show license' command to display the full license\n" 1407 ); 1496 1408 } 1497 1409 … … 1500 1412 owl_message *m; 1501 1413 owl_fmtext fm, attrfm; 1502 char buff[10000];1503 1414 owl_view *v; 1504 1415 #ifdef HAVE_LIBZEPHYR … … 1516 1427 1517 1428 owl_fmtext_append_bold(&fm, "General Information:\n"); 1518 owl_fmtext_append_normal(&fm, " Msg Id : "); 1519 sprintf(buff, "%i", owl_message_get_id(m)); 1520 owl_fmtext_append_normal(&fm, buff); 1521 owl_fmtext_append_normal(&fm, "\n"); 1429 owl_fmtext_appendf_normal(&fm, " Msg Id : %i\n", owl_message_get_id(m)); 1522 1430 1523 1431 owl_fmtext_append_normal(&fm, " Type : "); … … 1535 1443 } 1536 1444 1537 owl_fmtext_append_normal(&fm, " Time : "); 1538 owl_fmtext_append_normal(&fm, owl_message_get_timestr(m)); 1539 owl_fmtext_append_normal(&fm, "\n"); 1445 owl_fmtext_appendf_normal(&fm, " Time : %s\n", owl_message_get_timestr(m)); 1540 1446 1541 1447 if (!owl_message_is_type_admin(m)) { 1542 owl_fmtext_append_normal(&fm, " Sender : "); 1543 owl_fmtext_append_normal(&fm, owl_message_get_sender(m)); 1544 owl_fmtext_append_normal(&fm, "\n"); 1545 1546 owl_fmtext_append_normal(&fm, " Recipient : "); 1547 owl_fmtext_append_normal(&fm, owl_message_get_recipient(m)); 1548 owl_fmtext_append_normal(&fm, "\n"); 1549 } 1550 1448 owl_fmtext_appendf_normal(&fm, " Sender : %s\n", owl_message_get_sender(m)); 1449 owl_fmtext_appendf_normal(&fm, " Recipient : %s\n", owl_message_get_recipient(m)); 1450 } 1451 1551 1452 if (owl_message_is_type_zephyr(m)) { 1552 1453 owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n"); 1553 1454 1554 owl_fmtext_append_normal(&fm, " Class : "); 1555 owl_fmtext_append_normal(&fm, owl_message_get_class(m)); 1556 owl_fmtext_append_normal(&fm, "\n"); 1557 owl_fmtext_append_normal(&fm, " Instance : "); 1558 owl_fmtext_append_normal(&fm, owl_message_get_instance(m)); 1559 owl_fmtext_append_normal(&fm, "\n"); 1560 owl_fmtext_append_normal(&fm, " Opcode : "); 1561 owl_fmtext_append_normal(&fm, owl_message_get_opcode(m)); 1562 owl_fmtext_append_normal(&fm, "\n"); 1563 1564 owl_fmtext_append_normal(&fm, " Time : "); 1565 owl_fmtext_append_normal(&fm, owl_message_get_timestr(m)); 1566 owl_fmtext_append_normal(&fm, "\n"); 1455 owl_fmtext_appendf_normal(&fm, " Class : %s\n", owl_message_get_class(m)); 1456 owl_fmtext_appendf_normal(&fm, " Instance : %s\n", owl_message_get_instance(m)); 1457 owl_fmtext_appendf_normal(&fm, " Opcode : %s\n", owl_message_get_opcode(m)); 1567 1458 #ifdef HAVE_LIBZEPHYR 1568 1459 if (owl_message_is_direction_in(m)) { … … 1596 1487 } 1597 1488 } 1598 owl_fmtext_append_normal(&fm, " Host : "); 1599 owl_fmtext_append_normal(&fm, owl_message_get_hostname(m)); 1489 owl_fmtext_appendf_normal(&fm, " Host : %s\n", owl_message_get_hostname(m)); 1600 1490 1601 1491 if (!owl_message_is_pseudo(m)) { 1602 1492 owl_fmtext_append_normal(&fm, "\n"); 1603 sprintf(buff, " Port : %i\n", ntohs(n->z_port)); 1604 owl_fmtext_append_normal(&fm, buff); 1605 1606 owl_fmtext_append_normal(&fm, " Auth : "); 1607 owl_fmtext_append_normal(&fm, owl_zephyr_get_authstr(n)); 1608 owl_fmtext_append_normal(&fm, "\n"); 1609 1610 /* fix this */ 1611 sprintf(buff, " Checkd Ath: %i\n", n->z_checked_auth); 1612 sprintf(buff, "%s Multi notc: %s\n", buff, n->z_multinotice); 1613 sprintf(buff, "%s Num other : %i\n", buff, n->z_num_other_fields); 1614 sprintf(buff, "%s Msg Len : %i\n", buff, n->z_message_len); 1615 owl_fmtext_append_normal(&fm, buff); 1616 1617 sprintf(buff, " Fields : %i\n", owl_zephyr_get_num_fields(n)); 1618 owl_fmtext_append_normal(&fm, buff); 1619 1493 owl_fmtext_appendf_normal(&fm, " Port : %i\n", ntohs(n->z_port)); 1494 owl_fmtext_appendf_normal(&fm, " Auth : %s\n", owl_zephyr_get_authstr(n)); 1495 1496 /* FIXME make these more descriptive */ 1497 owl_fmtext_appendf_normal(&fm, " Checkd Ath: %i\n", n->z_checked_auth); 1498 owl_fmtext_appendf_normal(&fm, " Multi notc: %s\n", n->z_multinotice); 1499 owl_fmtext_appendf_normal(&fm, " Num other : %i\n", n->z_num_other_fields); 1500 owl_fmtext_appendf_normal(&fm, " Msg Len : %i\n", n->z_message_len); 1501 1620 1502 fields=owl_zephyr_get_num_fields(n); 1503 owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); 1504 1621 1505 for (i=0; i<fields; i++) { 1622 sprintf(buff, " Field %i : ", i+1);1623 1624 1506 ptr=owl_zephyr_get_field_as_utf8(n, i+1); 1625 1507 len=strlen(ptr); … … 1633 1515 } 1634 1516 owl_free(ptr); 1635 1517 1636 1518 for (j=0; j<strlen(tmpbuff); j++) { 1637 1519 if (tmpbuff[j]=='\n') tmpbuff[j]='~'; 1638 1520 if (tmpbuff[j]=='\r') tmpbuff[j]='!'; 1639 1521 } 1640 1641 strcat(buff, tmpbuff); 1642 strcat(buff, "\n"); 1643 owl_fmtext_append_normal(&fm, buff); 1522 1523 owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i+1, tmpbuff); 1644 1524 } 1645 owl_fmtext_append_normal(&fm, " Default Fm:"); 1646 owl_fmtext_append_normal(&fm, n->z_default_format); 1525 owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", n->z_default_format); 1647 1526 } 1648 1649 } 1650 #endif 1527 1528 } 1529 #endif 1651 1530 } 1652 1531 … … 1749 1628 } 1750 1629 1751 void owl_function_typwin_grow()1752 {1753 int i;1754 1755 i=owl_global_get_typwin_lines(&g);1756 owl_function_resize_typwin(i+1);1757 }1758 1759 void owl_function_typwin_shrink()1760 {1761 int i;1762 1763 i=owl_global_get_typwin_lines(&g);1764 if (i>2) {1765 owl_function_resize_typwin(i-1);1766 }1767 }1768 1769 1630 void owl_function_mainwin_pagedown() 1770 1631 { … … 1803 1664 } 1804 1665 1805 #define PABUFLEN 50001806 1666 void owl_function_printallvars() 1807 1667 { 1808 char buff[PABUFLEN], *pos, *name; 1668 char *name; 1669 char var[LINE]; 1809 1670 owl_list varnames; 1810 int i, numvarnames , rem;1811 1812 pos = buff; 1813 pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");1814 pos += sprintf(pos, "%-20s %s\n", "--------", "-----");1671 int i, numvarnames; 1672 GString *str = g_string_new(""); 1673 1674 g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); 1675 g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); 1815 1676 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 1816 rem = (buff+PABUFLEN)-pos-1;1817 1677 numvarnames = owl_list_get_size(&varnames); 1818 1678 for (i=0; i<numvarnames; i++) { 1819 1679 name = owl_list_get_element(&varnames, i); 1820 1680 if (name && name[0]!='_') { 1821 rem = (buff+PABUFLEN)-pos-1; 1822 pos += snprintf(pos, rem, "\n%-20s = ", name); 1823 rem = (buff+PABUFLEN)-pos-1; 1824 owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem); 1825 pos = buff+strlen(buff); 1826 } 1827 } 1828 rem = (buff+PABUFLEN)-pos-1; 1829 snprintf(pos, rem, "\n"); 1681 g_string_append_printf(str, "\n%-20s = ", name); 1682 owl_variable_get_tostring(owl_global_get_vardict(&g), name, var, LINE); 1683 g_string_append(str, var); 1684 } 1685 } 1686 g_string_append(str, "\n"); 1830 1687 owl_variable_dict_namelist_free(&varnames); 1831 1832 owl_function_popless_text(buff); 1688 1689 owl_function_popless_text(str->str); 1690 g_string_free(str, TRUE); 1833 1691 } 1834 1692 … … 1922 1780 void owl_function_status() 1923 1781 { 1924 char buff[ 5000];1782 char buff[MAXPATHLEN+1]; 1925 1783 time_t start; 1926 1784 int up, days, hours, minutes; … … 1942 1800 1943 1801 owl_fmtext_append_normal(&fm, " Current Directory: "); 1944 (void) getcwd(buff, MAXPATHLEN); 1945 owl_fmtext_append_normal(&fm, buff); 1802 if(getcwd(buff, MAXPATHLEN) == NULL) { 1803 owl_fmtext_append_normal(&fm, "<Error in getcwd>"); 1804 } else { 1805 owl_fmtext_append_normal(&fm, buff); 1806 } 1946 1807 owl_fmtext_append_normal(&fm, "\n"); 1947 1808 1948 sprintf(buff, " Startup Time: %s", ctime(&start)); 1949 owl_fmtext_append_normal(&fm, buff); 1809 owl_fmtext_appendf_normal(&fm, " Startup Time: %s", ctime(&start)); 1950 1810 1951 1811 up=owl_global_get_runtime(&g); … … 1956 1816 minutes=up/60; 1957 1817 up-=minutes*60; 1958 sprintf(buff, " Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up); 1959 owl_fmtext_append_normal(&fm, buff); 1818 owl_fmtext_appendf_normal(&fm, " Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up); 1960 1819 1961 1820 owl_fmtext_append_normal(&fm, "\nProtocol Options:\n"); … … 2002 1861 { 2003 1862 owl_fmtext fm; 2004 char buff[LINE];2005 1863 2006 1864 owl_fmtext_init_null(&fm); 2007 sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n",1865 owl_fmtext_appendf_normal(&fm, "Terminal Lines: %i\nTerminal Columns: %i\n", 2008 1866 owl_global_get_lines(&g), 2009 1867 owl_global_get_cols(&g)); 2010 owl_fmtext_append_normal(&fm, buff);2011 1868 2012 1869 if (owl_global_get_hascolors(&g)) { 2013 1870 owl_fmtext_append_normal(&fm, "Color: Yes\n"); 2014 sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g)); 2015 owl_fmtext_append_normal(&fm, buff); 2016 sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); 2017 owl_fmtext_append_normal(&fm, buff); 1871 owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g)); 1872 owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); 2018 1873 } else { 2019 1874 owl_fmtext_append_normal(&fm, "Color: No\n"); … … 2052 1907 return; 2053 1908 } 1909 } 1910 1911 /* then check if it's a question and just bring up the command prompt */ 1912 if (owl_message_is_question(m)) { 1913 owl_function_start_command(""); 1914 return; 2054 1915 } 2055 1916 … … 2495 2356 char *tmpclass, *tmpinstance = NULL; 2496 2357 char *class, *instance = NULL; 2497 int len;2498 2358 2499 2359 class = owl_util_baseclass(c); … … 2505 2365 2506 2366 /* name for the filter */ 2507 len=strlen(class)+30;2508 if (instance) len+=strlen(instance);2509 filtname=owl_malloc(len);2510 2367 if (!instance) { 2511 sprintf(filtname,"class-%s", class);2512 } else { 2513 sprintf(filtname,"class-%s-instance-%s", class, instance);2368 filtname = owl_sprintf("class-%s", class); 2369 } else { 2370 filtname = owl_sprintf("class-%s-instance-%s", class, instance); 2514 2371 } 2515 2372 /* downcase it */ … … 2542 2399 owl_text_tr(tmpinstance, '"', '.'); 2543 2400 } 2544 len = strlen(tmpclass); 2545 if(tmpinstance) len += strlen(tmpinstance); 2546 len += 60; 2547 argbuff = owl_malloc(len); 2548 sprintf(argbuff, "class ^(un)*%s(\\.d)*$", tmpclass); 2401 2402 argbuff = owl_sprintf("class ^(un)*%s(\\.d)*$", tmpclass); 2549 2403 if (tmpinstance) { 2550 sprintf(argbuff, "%s and ( instance ^(un)*%s(\\.d)*$ )", argbuff, tmpinstance); 2404 char *tmp = argbuff; 2405 argbuff = owl_sprintf("%s and ( instance ^(un)*%s(\\.d)*$ )", tmp, tmpinstance); 2406 owl_free(tmp); 2551 2407 } 2552 2408 owl_free(tmpclass); … … 2577 2433 { 2578 2434 owl_filter *f; 2579 char *argbuff, *longuser, * shortuser, *filtname;2435 char *argbuff, *longuser, *esclonguser, *shortuser, *filtname; 2580 2436 2581 2437 /* stick the local realm on if it's not there */ … … 2584 2440 2585 2441 /* name for the filter */ 2586 filtname=owl_malloc(strlen(shortuser)+20); 2587 sprintf(filtname, "user-%s", shortuser); 2442 filtname=owl_sprintf("user-%s", shortuser); 2588 2443 2589 2444 /* if it already exists then go with it. This lets users override */ … … 2595 2450 f=owl_malloc(sizeof(owl_filter)); 2596 2451 2597 argbuff=owl_malloc(strlen(longuser)+1000); 2598 sprintf(argbuff, "( type ^zephyr$ and filter personal and "); 2599 sprintf(argbuff, "%s ( ( direction ^in$ and sender ^%s$ ) or ( direction ^out$ and recipient ^%s$ ) ) )", argbuff, longuser, longuser); 2600 sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) )", argbuff, longuser); 2452 esclonguser = owl_text_quote(longuser, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2453 2454 argbuff=owl_sprintf("( type ^zephyr$ and filter personal and " 2455 "( ( direction ^in$ and sender ^%1$s$ ) or ( direction ^out$ and " 2456 "recipient ^%1$s$ ) ) ) or ( ( class ^login$ ) and ( sender ^%1$s$ ) )", 2457 esclonguser); 2601 2458 2602 2459 owl_filter_init_fromstring(f, filtname, argbuff); … … 2608 2465 owl_free(argbuff); 2609 2466 owl_free(longuser); 2467 owl_free(esclonguser); 2610 2468 owl_free(shortuser); 2611 2469 … … 2626 2484 2627 2485 /* name for the filter */ 2628 filtname=owl_malloc(strlen(user)+40); 2629 sprintf(filtname, "aimuser-%s", user); 2486 filtname=owl_sprintf("aimuser-%s", user); 2630 2487 2631 2488 /* if it already exists then go with it. This lets users override */ … … 2639 2496 escuser = owl_text_quote(user, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2640 2497 2641 argbuff=owl_malloc(1000); 2642 sprintf(argbuff, 2643 "( type ^aim$ and ( ( sender ^%s$ and recipient ^%s$ ) or ( sender ^%s$ and recipient ^%s$ ) ) )", 2644 escuser, owl_global_get_aim_screenname_for_filters(&g), 2645 owl_global_get_aim_screenname_for_filters(&g), escuser); 2498 argbuff = owl_sprintf( 2499 "( type ^aim$ and ( ( sender ^%1$s$ and recipient ^%2$s$ ) or " 2500 "( sender ^%2$s$ and recipient ^%1$s$ ) ) )", 2501 escuser, owl_global_get_aim_screenname_for_filters(&g)); 2646 2502 2647 2503 owl_filter_init_fromstring(f, filtname, argbuff); … … 2660 2516 { 2661 2517 owl_filter *f; 2662 char *argbuff, *filtname ;2518 char *argbuff, *filtname, *esctype; 2663 2519 2664 2520 /* name for the filter */ … … 2673 2529 f=owl_malloc(sizeof(owl_filter)); 2674 2530 2675 argbuff = owl_sprintf("type ^%s$", type); 2531 esctype = owl_text_quote(type, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2532 2533 argbuff = owl_sprintf("type ^%s$", esctype); 2676 2534 2677 2535 owl_filter_init_fromstring(f, filtname, argbuff); … … 2682 2540 /* free stuff */ 2683 2541 owl_free(argbuff); 2542 owl_free(esctype); 2684 2543 2685 2544 return filtname; … … 2943 2802 void owl_function_zpunt(char *class, char *inst, char *recip, int direction) 2944 2803 { 2945 char * buff;2804 char *puntexpr, *classexpr, *instexpr, *recipexpr; 2946 2805 char *quoted; 2947 2806 2948 buff=owl_malloc(strlen(class)+strlen(inst)+strlen(recip)+100);2949 strcpy(buff, "class");2950 2807 if (!strcmp(class, "*")) { 2951 strcat(buff, ".*");2808 classexpr = owl_sprintf("class .*"); 2952 2809 } else { 2953 2810 quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); … … 2955 2812 owl_text_tr(quoted, '\'', '.'); 2956 2813 owl_text_tr(quoted, '"', '.'); 2957 sprintf(buff, "%s ^(un)*%s(\\.d)*$", buff, quoted);2814 classexpr = owl_sprintf("class ^(un)*%s(\\.d)*$", quoted); 2958 2815 owl_free(quoted); 2959 2816 } 2960 2817 if (!strcmp(inst, "*")) { 2961 strcat(buff," and instance .*");2818 instexpr = owl_sprintf(" and instance .*"); 2962 2819 } else { 2963 2820 quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); … … 2965 2822 owl_text_tr(quoted, '\'', '.'); 2966 2823 owl_text_tr(quoted, '"', '.'); 2967 sprintf(buff, "%s and instance ^(un)*%s(\\.d)*$", buff, quoted);2824 instexpr = owl_sprintf(" and instance ^(un)*%s(\\.d)*$", quoted); 2968 2825 owl_free(quoted); 2969 2826 } 2970 if (strcmp(recip, "*")) { 2827 if (!strcmp(recip, "*")) { 2828 recipexpr = owl_sprintf(""); 2829 } else { 2971 2830 quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2972 2831 owl_text_tr(quoted, ' ', '.'); 2973 2832 owl_text_tr(quoted, '\'', '.'); 2974 2833 owl_text_tr(quoted, '"', '.'); 2975 sprintf(buff, "%s and recipient ^%s$", buff, quoted);2834 recipexpr = owl_sprintf(" and recipient ^%s$", quoted); 2976 2835 owl_free(quoted); 2977 2836 } 2978 2837 2979 owl_function_punt(buff, direction); 2980 owl_free(buff); 2838 puntexpr = owl_sprintf("%s %s %s", classexpr, instexpr, recipexpr); 2839 owl_function_punt(puntexpr, direction); 2840 owl_free(puntexpr); 2841 owl_free(classexpr); 2842 owl_free(instexpr); 2843 owl_free(recipexpr); 2981 2844 } 2982 2845 … … 3065 2928 } 3066 2929 3067 char *owl_function_keymap_summary( void*name)2930 char *owl_function_keymap_summary(char *name) 3068 2931 { 3069 2932 owl_keymap *km … … 3195 3058 owl_buddy *b; 3196 3059 owl_list anyone; 3197 char * foo, *timestr;3060 char *timestr; 3198 3061 #ifdef HAVE_LIBZEPHYR 3199 char *tmp, *user , *line;3062 char *tmp, *user; 3200 3063 ZLocations_t location[200]; 3201 3064 int numlocs, ret; … … 3219 3082 timestr=owl_strdup(""); 3220 3083 } 3221 foo=owl_sprintf(" %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr); 3222 owl_fmtext_append_normal(&fm, foo); 3084 owl_fmtext_appendf_normal(&fm, " %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr); 3223 3085 owl_free(timestr); 3224 owl_free(foo);3225 3086 } 3226 3087 } … … 3250 3111 if (ret==0) { 3251 3112 for (x=0; x<numlocs; x++) { 3252 line=owl_malloc(strlen(location[x].host)+strlen(location[x].time)+strlen(location[x].tty)+100);3253 3113 tmp=short_zuser(user); 3254 sprintf(line, " %-10.10s %-24.24s %-12.12s %20.20s\n", 3255 tmp, 3256 location[x].host, 3257 location[x].tty, 3258 location[x].time); 3259 owl_fmtext_append_normal(&fm, line); 3114 owl_fmtext_appendf_normal(&fm, " %-10.10s %-24.24s %-12.12s %20.20s\n", 3115 tmp, 3116 location[x].host, 3117 location[x].tty, 3118 location[x].time); 3260 3119 owl_free(tmp); 3261 owl_free(line);3262 3120 } 3263 3121 if (numlocs>=200) { … … 3491 3349 { 3492 3350 va_list ap; 3493 char buff[2048], buff2[2048]; 3351 char *buff, *buff2; 3352 char *nl; 3494 3353 char *date; 3495 3354 time_t now; … … 3501 3360 va_start(ap, fmt); 3502 3361 3503 vsnprintf(buff, 2048,fmt, ap);3504 sprintf(buff2,"%s %s", date, buff);3362 buff = g_strdup_vprintf(fmt, ap); 3363 buff2 = owl_sprintf("%s %s", date, buff); 3505 3364 owl_function_debugmsg("ERROR: %s", buff); 3506 if (owl_global_get_curs_msgwin(&g)) { 3507 werase(owl_global_get_curs_msgwin(&g)); 3508 waddstr(owl_global_get_curs_msgwin(&g), buff); 3509 wnoutrefresh(owl_global_get_curs_msgwin(&g)); 3510 owl_global_set_needrefresh(&g); 3365 nl = strchr(buff, '\n'); 3366 if(nl && *(nl + 1)) { 3367 /* Multiline error */ 3368 owl_function_adminmsg("ERROR", buff); 3369 } else { 3370 owl_function_makemsg("[Error] %s", buff); 3511 3371 } 3512 3372 owl_errqueue_append_err(owl_global_get_errqueue(&g), buff2); 3513 3373 va_end(ap); 3514 3374 owl_free(date); 3375 owl_free(buff); 3376 owl_free(buff2); 3515 3377 } 3516 3378 -
global.c
rda466e0 rf34dd65 51 51 owl_keys_setup_keymaps(&g->kh); 52 52 53 owl_list_create(&(g->muxevents));54 53 owl_list_create(&(g->filterlist)); 55 54 owl_list_create(&(g->puntlist)); … … 100 99 g->aim_screenname_for_filters=NULL; 101 100 g->aim_loggedin=0; 102 owl_timer_create_countdown(&(g->aim_noop_timer), 30);103 owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);104 owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);105 101 owl_buddylist_init(&(g->buddylist)); 106 102 107 103 g->havezephyr=0; 108 104 g->haveaim=0; 105 g->ignoreaimlogin=0; 109 106 owl_global_set_no_doaimevents(g); 110 107 … … 113 110 114 111 owl_zbuddylist_create(&(g->zbuddies)); 115 owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);116 112 117 113 owl_obarray_init(&(g->obarray)); … … 119 115 owl_message_init_fmtext_cache(); 120 116 owl_list_create(&(g->dispatchlist)); 117 g->timerlist = NULL; 121 118 } 122 119 … … 139 136 g->recwin=newwin(g->recwinlines, cols, 0, 0); 140 137 if (g->recwin==NULL) { 141 owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n" , g->recwinlines, cols);138 owl_function_debugmsg("_owl_global_setup_windows: newwin returned NULL\n"); 142 139 endwin(); 143 140 exit(50); … … 570 567 strcpy(g->startupargs, ""); 571 568 for (i=0; i<argc; i++) { 572 sprintf(g->startupargs , "%s%s ", g->startupargs, argv[i]);569 sprintf(g->startupargs + strlen(g->startupargs), "%s ", argv[i]); 573 570 } 574 571 g->startupargs[strlen(g->startupargs)-1]='\0'; … … 588 585 owl_history *owl_global_get_cmd_history(owl_global *g) { 589 586 return(&(g->cmdhist)); 590 }591 592 /* muxevents */593 594 owl_muxevents *owl_global_get_muxevents(owl_global *g) {595 return(&(g->muxevents));596 587 } 597 588 … … 719 710 int owl_global_get_newmsgproc_pid(owl_global *g) { 720 711 return(g->newmsgproc_pid); 721 }722 723 void owl_global_add_to_malloced(owl_global *g, int i) {724 g->malloced+=i;725 }726 727 void owl_global_add_to_freed(owl_global *g, int i) {728 g->freed+=1;729 }730 731 int owl_global_get_malloced(owl_global *g) {732 return(g->malloced);733 }734 735 int owl_global_get_freed(owl_global *g) {736 return(g->freed);737 }738 739 int owl_global_get_meminuse(owl_global *g) {740 return(g->malloced-g->freed);741 712 } 742 713 … … 812 783 { 813 784 g->bosconn=*conn; 814 }815 816 int owl_global_is_aimnop_time(owl_global *g)817 {818 if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);819 return(0);820 }821 822 void owl_global_aimnop_sent(owl_global *g)823 {824 owl_timer_reset(&(g->aim_noop_timer));825 }826 827 owl_timer *owl_global_get_aim_login_timer(owl_global *g)828 {829 return(&(g->aim_ignorelogin_timer));830 785 } 831 786 … … 902 857 } 903 858 859 void owl_global_set_ignore_aimlogin(owl_global *g) 860 { 861 g->ignoreaimlogin = 1; 862 } 863 864 void owl_global_unset_ignore_aimlogin(owl_global *g) 865 { 866 g->ignoreaimlogin = 0; 867 } 868 869 int owl_global_is_ignore_aimlogin(owl_global *g) 870 { 871 return g->ignoreaimlogin; 872 } 873 904 874 void owl_global_set_havezephyr(owl_global *g) 905 875 { … … 911 881 if (g->havezephyr) return(1); 912 882 return(0); 913 }914 915 owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)916 {917 return(&(g->aim_buddyinfo_timer));918 883 } 919 884 … … 944 909 } 945 910 946 owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)947 {948 return(&(g->zephyr_buddycheck_timer));949 }950 911 951 912 owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g) … … 968 929 return &(g->dispatchlist); 969 930 } 931 932 GList **owl_global_get_timerlist(owl_global *g) 933 { 934 return &(g->timerlist); 935 } -
help.c
r0398d55 r799b60e 18 18 owl_fmtext_append_normal 19 19 (&fm, 20 " If you're new to BarnOwl, the first thing you should type is\n\n" 21 " :show quickstart\n\n" 20 22 " For help on a specific command use 'help <command>'\n" 21 23 " For information on advanced keys, use 'show keymaps'.\n" -
keys.c
rdb0ac7e rce56149 50 50 51 51 BIND_CMD("LEFT", "edit:move-left", ""); 52 BIND_CMD("M-[ D", "edit:move-left", ""); 52 53 BIND_CMD("C-b", "edit:move-left", ""); 53 54 BIND_CMD("RIGHT", "edit:move-right", ""); 55 BIND_CMD("M-[ C", "edit:move-right", ""); 54 56 BIND_CMD("C-f", "edit:move-right", ""); 55 57 … … 65 67 BIND_CMD("M-DELETE", "edit:delete-prev-word", ""); 66 68 BIND_CMD("M-d", "edit:delete-next-word", ""); 69 BIND_CMD("M-DC", "edit:delete-next-word", ""); 67 70 BIND_CMD("M-[ 3 ; 3 ~", "edit:delete-next-word", ""); 68 71 69 72 BIND_CMD("C-h", "edit:delete-prev-char", ""); 70 73 BIND_CMD("BACKSPACE", "edit:delete-prev-char", ""); 71 BIND_CMD("DC", "edit:delete-prev-char", "");72 74 BIND_CMD("DELETE", "edit:delete-prev-char", ""); 75 BIND_CMD("C-d", "edit:delete-next-char", ""); 76 BIND_CMD("DC", "edit:delete-next-char", ""); 73 77 74 78 BIND_CMD("C-k", "edit:delete-to-line-end", ""); … … 79 83 80 84 BIND_CMD("C-l", "( edit:recenter ; redisplay )", ""); 81 82 BIND_CMD("C-d", "edit:delete-next-char", "");83 85 84 86 … … 93 95 94 96 BIND_CMD("UP", "editmulti:move-up-line", ""); 97 BIND_CMD("M-[ A", "editmulti:move-up-line", ""); 95 98 BIND_CMD("C-p", "editmulti:move-up-line", ""); 96 99 BIND_CMD("DOWN", "editmulti:move-down-line", ""); 100 BIND_CMD("M-[ B", "editmulti:move-down-line", ""); 97 101 BIND_CMD("C-n", "editmulti:move-down-line", ""); 98 102 … … 120 124 121 125 BIND_CMD("UP", "edit:history-prev", ""); 126 BIND_CMD("M-[ A", "edit:history-prev", ""); 122 127 BIND_CMD("C-p", "edit:history-prev", ""); 123 128 BIND_CMD("M-p", "edit:history-prev", ""); 124 129 125 130 BIND_CMD("DOWN", "edit:history-next", ""); 131 BIND_CMD("M-[ B", "edit:history-next", ""); 126 132 BIND_CMD("C-n", "edit:history-next", ""); 127 133 BIND_CMD("M-n", "edit:history-next", ""); … … 166 172 BIND_CMD("LF", "popless:scroll-down-line", ""); 167 173 BIND_CMD("DOWN", "popless:scroll-down-line", ""); 174 BIND_CMD("M-[ B", "popless:scroll-down-line", ""); 168 175 BIND_CMD("C-n", "popless:scroll-down-line", ""); 169 176 170 177 BIND_CMD("UP", "popless:scroll-up-line", ""); 178 BIND_CMD("M-[ A", "popless:scroll-up-line", ""); 171 179 BIND_CMD("C-h", "popless:scroll-up-line", ""); 172 180 BIND_CMD("C-p", "popless:scroll-up-line", ""); … … 176 184 177 185 BIND_CMD("RIGHT", "popless:scroll-right 10", "scrolls right"); 186 BIND_CMD("M-[ C", "popless:scroll-right 10", "scrolls right"); 178 187 BIND_CMD("LEFT", "popless:scroll-left 10", "scrolls left"); 188 BIND_CMD("M-[ D", "popless:scroll-left 10", "scrolls left"); 179 189 180 190 BIND_CMD("HOME", "popless:scroll-to-top", ""); … … 232 242 BIND_CMD("M-[ D", "recv:shiftleft", ""); 233 243 BIND_CMD("RIGHT", "recv:shiftright",""); 234 BIND_CMD("M-[ C", "recv:shift left","");244 BIND_CMD("M-[ C", "recv:shiftright",""); 235 245 BIND_CMD("DOWN", "recv:next", ""); 236 246 BIND_CMD("C-n", "recv:next", ""); … … 282 292 BIND_CMD("M-r", "reply -e", "reply to the current message, but allow editing of recipient"); 283 293 BIND_CMD("M-R", "reply -e sender", "reply to sender of the current message, but allow editing of recipient"); 284 285 BIND_CMD("w", "openurl", "open a URL using a webbrowser");286 294 287 295 BIND_CMD("W", "start-command webzephyr ", "start a webzephyr command"); -
list.c
r50622a5 rf34dd65 78 78 } 79 79 80 /* todo: might leak memory */81 int owl_list_replace_element(owl_list *l, int n, void *element)82 {83 if (n>l->size-1) return(-1);84 85 l->list[n]=element;86 return(0);87 }88 89 80 void owl_list_free_all(owl_list *l, void (*elefree)(void *)) 90 81 { -
message.c
r147d880 rf34dd65 338 338 } 339 339 340 /* caller must free the return */341 char *owl_message_get_shorttimestr(owl_message *m)342 {343 struct tm *tmstruct;344 char *out;345 346 tmstruct=localtime(&(m->time));347 out=owl_sprintf("%2.2i:%2.2i", tmstruct->tm_hour, tmstruct->tm_min);348 if (out) return(out);349 return("??:??");350 }351 352 340 void owl_message_set_type_admin(owl_message *m) 353 341 { … … 384 372 { 385 373 return owl_message_is_type(m, "admin"); 386 }387 388 int owl_message_is_type_generic(owl_message *m)389 {390 char * t = owl_message_get_attribute_value(m, "type");391 return (t == NULL);392 374 } 393 375 … … 573 555 } 574 556 575 int owl_message_is_from_me(owl_message *m)576 {577 if (owl_message_is_type_zephyr(m)) {578 if (!strcasecmp(owl_message_get_sender(m), owl_zephyr_get_sender())) {579 return(1);580 } else {581 return(0);582 }583 } else if (owl_message_is_type_aim(m)) {584 if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {585 return(1);586 } else {587 return(0);588 }589 } else if (owl_message_is_type_admin(m)) {590 return(0);591 }592 return(0);593 }594 595 557 int owl_message_is_mail(owl_message *m) 596 558 { 597 559 if (owl_message_is_type_zephyr(m)) { 598 560 if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) { 599 return(1);600 } else {601 return(0);602 }603 }604 return(0);605 }606 607 int owl_message_is_ping(owl_message *m)608 {609 if (owl_message_is_type_zephyr(m)) {610 if (!strcasecmp(owl_message_get_opcode(m), "ping")) {611 561 return(1); 612 562 } else { … … 964 914 owl_message_set_instance(m, owl_zwrite_get_instance(&z)); 965 915 if (owl_zwrite_get_numrecips(&z)>0) { 916 char *longzuser = long_zuser(owl_zwrite_get_recip_n(&z, 0)); 966 917 owl_message_set_recipient(m, 967 long_zuser(owl_zwrite_get_recip_n(&z, 0))); /* only gets the first user, must fix */ 918 longzuser); /* only gets the first user, must fix */ 919 owl_free(longzuser); 968 920 } 969 921 owl_message_set_opcode(m, owl_zwrite_get_opcode(&z)); … … 990 942 } 991 943 992 void owl_message_pretty_zsig(owl_message *m, char *buff)993 {994 /* stick a one line version of the zsig in buff */995 char *ptr;996 997 strcpy(buff, owl_message_get_zsig(m));998 ptr=strchr(buff, '\n');999 if (ptr) ptr[0]='\0';1000 }1001 1002 944 void owl_message_free(owl_message *m) 1003 945 { -
owl.c
rc1d2e6c r28fa23c 46 46 int newmsgs, nexttimediff; 47 47 struct sigaction sigact; 48 char *configfile, *tty, *perlout, *perlerr, **argvsave , buff[LINE], startupmsg[LINE];48 char *configfile, *tty, *perlout, *perlerr, **argvsave; 49 49 char *confdir; 50 50 owl_filter *f; … … 55 55 struct termios tio; 56 56 owl_message *m; 57 #if OWL_STDERR_REDIR 58 int newstderr; 59 #endif 60 57 61 58 if (!GLIB_CHECK_VERSION (2, 12, 0)) 62 59 g_error ("GLib version 2.12.0 or above is needed."); … … 191 188 d->fd = STDIN; 192 189 d->cfunc = &owl_process_input; 193 d-> pfunc= NULL;190 d->destroy = NULL; 194 191 owl_select_add_dispatch(d); 195 192 } … … 202 199 d->fd = ZGetFD(); 203 200 d->cfunc = &owl_zephyr_process_events; 204 d-> pfunc= NULL;201 d->destroy = NULL; 205 202 owl_select_add_dispatch(d); 206 203 owl_global_set_havezephyr(&g); … … 211 208 #if OWL_STDERR_REDIR 212 209 /* Do this only after we've started curses up... */ 213 owl_function_debugmsg("startup: doing stderr redirection"); 214 newstderr = stderr_replace(); 215 owl_muxevents_add(owl_global_get_muxevents(&g), newstderr, OWL_MUX_READ, 216 stderr_redirect_handler, NULL); 217 #endif 210 { 211 owl_dispatch *d = owl_malloc(sizeof(owl_dispatch)); 212 owl_function_debugmsg("startup: doing stderr redirection"); 213 d->fd = stderr_replace(); 214 d->cfunc = stderr_redirect_handler; 215 d->destroy = NULL; 216 owl_select_add_dispatch(d); 217 } 218 #endif 218 219 219 220 /* create the owl directory, in case it does not exist */ … … 320 321 /* welcome message */ 321 322 owl_function_debugmsg("startup: creating splash message"); 322 strcpy(startupmsg, "-----------------------------------------------------------------------\n");323 sprintf(buff, "Welcome to barnowl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING);324 strcat(startupmsg, buff);325 strcat(startupmsg, " \n");326 strcat(startupmsg, "BarnOwl is free software. Type ':show license' for more \n");327 strcat(startupmsg, "information. \n");328 strcat(startupmsg, " ^ ^ \n");329 strcat(startupmsg, " OvO \n");330 strcat(startupmsg, "Please report any bugs or suggestions to bug-barnowl@mit.edu ( ) \n");331 strcat(startupmsg, "-----------------------------------------------------------------m-m---\n");332 owl_function_adminmsg("", startupmsg);323 owl_function_adminmsg("", 324 "-----------------------------------------------------------------------\n" 325 "Welcome to barnowl version " OWL_VERSION_STRING ". Press 'h' for on-line help.\n" 326 "To see a quick introduction, type ':show quickstart'. \n" 327 " \n" 328 "BarnOwl is free software. Type ':show license' for more \n" 329 "information. ^ ^ \n" 330 " OvO \n" 331 "Please report any bugs or suggestions to bug-barnowl@mit.edu ( ) \n" 332 "-----------------------------------------------------------------m-m---\n" 333 ); 333 334 sepbar(NULL); 334 335 … … 395 396 nexttime=time(NULL); 396 397 397 #ifdef HAVE_LIBZEPHYR 398 /* Check for any zephyrs that have come in while we've done init. */ 399 owl_zephyr_process_events(); 400 #endif 401 398 399 owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL, NULL); 400 401 /* If we ever deprecate the mainloop hook, remove this. */ 402 owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL, NULL); 403 404 402 405 owl_function_debugmsg("startup: entering main loop"); 403 406 /* main loop */ … … 414 417 415 418 followlast=owl_global_should_followlast(&g); 416 417 owl_perlconfig_mainloop();418 419 419 420 /* little hack */ … … 442 443 } 443 444 444 /* is it time to check zbuddies? */445 if (owl_global_is_pseudologins(&g)) {446 if (owl_timer_is_expired(owl_global_get_zephyr_buddycheck_timer(&g))) {447 owl_function_debugmsg("Doing zephyr buddy check");448 owl_function_zephyr_buddy_check(1);449 owl_timer_reset(owl_global_get_zephyr_buddycheck_timer(&g));450 }451 }452 453 /* dispatch any muxevents */454 owl_muxevents_dispatch(owl_global_get_muxevents(&g), 0);455 456 445 /* follow the last message if we're supposed to */ 457 446 if (newmsgs && followlast) { … … 511 500 int signum; 512 501 if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) { 513 owl_function_error("Got unexpected signal: %d %s (code: %d band: % d errno: %d)",502 owl_function_error("Got unexpected signal: %d %s (code: %d band: %ld errno: %d)", 514 503 signum, signum==SIGPIPE?"SIGPIPE":"SIG????", 515 504 si.si_code, si.si_band, si.si_errno); … … 614 603 } 615 604 616 void owl_process_aim() 617 { 618 if (owl_global_is_doaimevents(&g)) { 619 owl_aim_process_events(); 620 621 if (owl_global_is_aimloggedin(&g)) { 622 if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) { 623 /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */ 624 owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g)); 625 } 626 } 627 } 628 } 629 630 void owl_process_input() 605 void owl_process_input(owl_dispatch *d) 631 606 { 632 607 int ret; … … 773 748 774 749 /* Sends stderr (read from rfd) messages to the error console */ 775 void stderr_redirect_handler( int handle, int rfd, int eventmask, void *data)750 void stderr_redirect_handler(owl_dispatch *d) 776 751 { 777 752 int navail, bread; 778 char *buf;779 /*owl_function_debugmsg("stderr_redirect: called with rfd=%d\n", rfd);*/753 char buf[4096]; 754 int rfd = d->fd; 780 755 if (rfd<0) return; 781 756 if (-1 == ioctl(rfd, FIONREAD, (void*)&navail)) { … … 783 758 } 784 759 /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/ 785 if (navail<=0) return; 786 if (navail>256) { navail = 256; } 787 buf = owl_malloc(navail+1); 760 if (navail <= 0) return; 761 if (navail > sizeof(buf)-1) { 762 navail = sizeof(buf)-1; 763 } 788 764 bread = read(rfd, buf, navail); 789 765 if (buf[navail-1] != '\0') { 790 766 buf[navail] = '\0'; 791 767 } 792 owl_function_error("Err: %s", buf); 793 owl_free(buf); 768 owl_function_error("[stderr]\n%s", buf); 794 769 } 795 770 796 771 #endif /* OWL_STDERR_REDIR */ 772 773 void owl_zephyr_buddycheck_timer(owl_timer *t, void *data) 774 { 775 if (owl_global_is_pseudologins(&g)) { 776 owl_function_debugmsg("Doing zephyr buddy check"); 777 owl_function_zephyr_buddy_check(1); 778 } 779 } -
owl.h
r43a306c rf34dd65 320 320 321 321 typedef struct _owl_pair { 322 void*key;323 void*value;322 char *key; 323 char *value; 324 324 } owl_pair; 325 325 … … 377 377 int active; 378 378 int needsfirstrefresh; 379 void (*handler) (int ch);380 379 } owl_popwin; 381 382 typedef struct _owl_popexec {383 int refcount;384 owl_viewwin *vwin;385 int winactive;386 int pid; /* or 0 if it has terminated */387 int rfd;388 } owl_popexec;389 380 390 381 typedef struct _owl_messagelist { … … 412 403 typedef struct _owl_filter { 413 404 char *name; 414 int polarity;415 405 owl_filterelement * root; 416 406 int fgcolor; … … 453 443 } owl_editwin; 454 444 455 typedef struct _owl_mux {456 int handle; /* for referencing this */457 int active; /* has this been deleted? */458 int fd;459 int eventmask; /* bitmask of OWL_MUX_* */460 void (*handler_fn)(int handle, int fd, int eventmask, void *data);461 void *data; /* data reference to pass to callback */462 } owl_mux;463 typedef owl_list owl_muxevents;464 465 445 typedef struct _owl_keybinding { 466 446 int *j; /* keypress stack (0-terminated) */ … … 505 485 506 486 typedef struct _owl_timer { 507 int direction; 508 time_t starttime; 509 int start; 487 time_t time; 488 int interval; 489 void (*callback)(struct _owl_timer *, void *); 490 void (*destroy)(struct _owl_timer *); 491 void *data; 510 492 } owl_timer; 511 493 … … 524 506 525 507 typedef struct _owl_dispatch { 526 int fd; /* FD to watch for dispatch. */ 527 void (*cfunc)(); /* C function to dispatch to. */ 528 SV *pfunc; /* Perl function to dispatch to. */ 508 int fd; /* FD to watch for dispatch. */ 509 int needs_gc; 510 void (*cfunc)(struct _owl_dispatch*); /* C function to dispatch to. */ 511 void (*destroy)(struct _owl_dispatch*); /* Destructor */ 512 void *data; 529 513 } owl_dispatch; 514 515 typedef struct _owl_popexec { 516 int refcount; 517 owl_viewwin *vwin; 518 int winactive; 519 int pid; /* or 0 if it has terminated */ 520 owl_dispatch dispatch; 521 } owl_popexec; 530 522 531 523 typedef struct _owl_global { … … 537 529 owl_list filterlist; 538 530 owl_list puntlist; 539 owl_muxevents muxevents; /* fds to dispatch on */540 531 owl_vardict vars; 541 532 owl_cmddict cmds; … … 583 574 owl_timer aim_noop_timer; 584 575 owl_timer aim_ignorelogin_timer; 585 owl_timer aim_buddyinfo_timer;586 576 int aim_loggedin; /* true if currently logged into AIM */ 587 577 int aim_doprocessing; /* true if we should process AIM events (like pending login) */ … … 594 584 int havezephyr; 595 585 int haveaim; 586 int ignoreaimlogin; 596 587 int got_err_signal; /* 1 if we got an unexpected signal */ 597 588 siginfo_t err_signal_info; … … 601 592 owl_obarray obarray; 602 593 owl_list dispatchlist; 594 GList *timerlist; 595 owl_timer *aim_nop_timer; 603 596 } owl_global; 604 597 -
pair.c
r160ea47 rde1c8a5 1 1 #include "owl.h" 2 2 3 void owl_pair_create(owl_pair *p, void *key, void*value) {3 void owl_pair_create(owl_pair *p, char *key, char *value) { 4 4 p->key=key; 5 5 p->value=value; 6 6 } 7 7 8 void owl_pair_set_key(owl_pair *p, void*key) {8 void owl_pair_set_key(owl_pair *p, char *key) { 9 9 p->key=key; 10 10 } 11 11 12 void owl_pair_set_value(owl_pair *p, void*value) {12 void owl_pair_set_value(owl_pair *p, char *value) { 13 13 p->value=value; 14 14 } 15 15 16 void*owl_pair_get_key(owl_pair *p) {16 char *owl_pair_get_key(owl_pair *p) { 17 17 return(p->key); 18 18 } 19 19 20 void*owl_pair_get_value(owl_pair *p) {20 char *owl_pair_get_value(owl_pair *p) { 21 21 return(p->value); 22 22 } -
perl/modules/IRC/lib/BarnOwl/Message/IRC.pm
r38a7f22 rf79d6a2 33 33 @filter = 34 34 (qw{( type ^irc$ and filter personal and }, 35 qw{( ( direction ^in$ and sender}, "^ $who\$",36 qw{ ) or ( direction ^out$ and recipient}, "^ $who\$",35 qw{( ( direction ^in$ and sender}, "^\Q$who\E\$", 36 qw{ ) or ( direction ^out$ and recipient}, "^\Q$who\E\$", 37 37 qw{) ) ) }); 38 38 BarnOwl::command("filter", "$filter", @filter); … … 47 47 $filter = "irc-$network-channel-$channel-$sender-$1"; 48 48 @filter = 49 (qw{type ^irc$ and network}, "^ $network\$",50 qw{and channel}, "^ $channel\$",51 qw{and ( sender}, "^ $sender\$",52 qw{or sender}, "^ $1\$",qq{)});49 (qw{type ^irc$ and network}, "^\Q$network\E\$", 50 qw{and channel}, "^\Q$channel\E\$", 51 qw{and ( sender}, "^\Q$sender\E\$", 52 qw{or sender}, "^\Q$1\E\$",qq{)}); 53 53 } else { 54 54 $filter = "irc-$network-channel-$channel"; 55 @filter = (qw{type ^irc$ and network}, "^ $network\$",56 qw{and channel}, "^ $channel\$");55 @filter = (qw{type ^irc$ and network}, "^\Q$network\E\$", 56 qw{and channel}, "^\Q$channel\E\$"); 57 57 } 58 58 BarnOwl::command("filter", "$filter", @filter); -
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r167044b r56d0189 214 214 if ($body =~ /^\/me (.*)/) { 215 215 $conn->conn->me($to, $1); 216 $body = BarnOwl::Style::boldify($conn->nick.' '.$1);216 $body = '* '.$conn->nick.' '.$1; 217 217 } else { 218 218 $conn->conn->privmsg($to, $body); -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r4789b17 r3048f1f 107 107 my $nick = $self->nick; 108 108 BarnOwl::beep() if $body =~ /\b\Q$nick\E\b/; 109 $body = BarnOwl::Style::boldify($evt->nick.' '.$body)if $evt->type eq 'caction';109 $body = '* '.$evt->nick.' '.$body if $evt->type eq 'caction'; 110 110 my $msg = $self->new_message($evt, 111 111 direction => 'in', -
perl/modules/Jabber/lib/BarnOwl/Message/Jabber.pm
r96134cb r9375f8c 70 70 $filter = "jabber-room-$room"; 71 71 BarnOwl::command(qw[filter], $filter, 72 qw[type ^jabber$ and room], "^ $room\$");72 qw[type ^jabber$ and room], "^\Q$room\E\$"); 73 73 return $filter; 74 74 } elsif ($self->login ne 'none') { … … 84 84 my $filter = "jabber-user-$user"; 85 85 BarnOwl::command(qw[filter], $filter, qw[type ^jabber$], 86 qw[and ( ( direction ^in$ and from], "^ $user",87 qw[) or ( direction ^out$ and to ], "^ $user",86 qw[and ( ( direction ^in$ and from], "^\Q$user\E(/.*)?\$", 87 qw[) or ( direction ^out$ and to ], "^\Q$user\E(/.*)?\$", 88 88 qw[ ) ) ]); 89 89 return $filter; -
perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
re979da9 rb73ce70 70 70 $BarnOwl::Hooks::mainLoop->add("BarnOwl::Module::Jabber::onMainLoop"); 71 71 $BarnOwl::Hooks::getBuddyList->add("BarnOwl::Module::Jabber::onGetBuddyList"); 72 $BarnOwl::Hooks::getQuickstart->add("BarnOwl::Module::Jabber::onGetQuickstart"); 72 73 $vars{show} = ''; 73 74 BarnOwl::new_variable_bool("jabber:show_offline_buddies", … … 222 223 } 223 224 225 sub onGetQuickstart { 226 return <<'EOF' 227 @b(Jabber:) 228 Type ':jabberlogin @b(username@mit.edu)' to log in to Jabber. The command 229 ':jroster sub @b(somebody@gmail.com)' will request that they let you message 230 them. Once you get a message saying you are subscribed, you can message 231 them by typing ':jwrite @b(somebody@gmail.com)' or just 'j @b(somebody)'. 232 EOF 233 } 234 224 235 ################################################################################ 225 236 ### Owl Commands … … 435 446 436 447 sub cmd_logout { 448 return "You are not logged into jabber." unless ($conn->connected() > 0); 437 449 # Logged into multiple accounts 438 450 if ( $conn->connected() > 1 ) { … … 1112 1124 sub process_presence_subscribed { 1113 1125 my ( $sid, $p ) = @_; 1114 queue_admin_msg("ignoring:".$p->GetXML()) ;1126 queue_admin_msg("ignoring:".$p->GetXML()) if BarnOwl::getvar('jabber:spew') eq 'on'; 1115 1127 # RFC 3921 says we should respond to this with a "subscribe" 1116 1128 # but this causes a flood of sub/sub'd presence packets with … … 1122 1134 sub process_presence_unsubscribed { 1123 1135 my ( $sid, $p ) = @_; 1124 queue_admin_msg("ignoring:".$p->GetXML()) ;1136 queue_admin_msg("ignoring:".$p->GetXML()) if BarnOwl::getvar('jabber:spew') eq 'on'; 1125 1137 # RFC 3921 says we should respond to this with a "subscribe" 1126 1138 # but this causes a flood of unsub/unsub'd presence packets with -
perlconfig.c
rc1d2e6c re8c6d8f 44 44 h = newHV(); 45 45 46 #define MSG2H(h,field) hv_store(h, #field, strlen(#field),\47 46 #define MSG2H(h,field) (void)hv_store(h, #field, strlen(#field), \ 47 newSVpv(owl_message_get_##field(m),0), 0) 48 48 49 49 if (owl_message_is_type_zephyr(m) … … 59 59 owl_free(ptr); 60 60 } 61 hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0);62 63 hv_store(h, "auth", strlen("auth"),64 61 (void)hv_store(h, "fields", strlen("fields"), newRV_noinc((SV*)av_zfields), 0); 62 63 (void)hv_store(h, "auth", strlen("auth"), 64 newSVpv(owl_zephyr_get_authstr(owl_message_get_notice(m)),0),0); 65 65 } 66 66 … … 68 68 for(i=0; i<j; i++) { 69 69 pair=owl_list_get_element(&(m->attributes), i); 70 hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)),71 70 (void)hv_store(h, owl_pair_get_key(pair), strlen(owl_pair_get_key(pair)), 71 newSVpv(owl_pair_get_value(pair),0),0); 72 72 } 73 73 … … 88 88 MSG2H(h, header); 89 89 } 90 hv_store(h, "time", strlen("time"), newSVpv(owl_message_get_timestr(m),0),0);91 hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0);92 hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0);93 hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0);94 hv_store(h, "should_wordwrap",95 96 90 (void)hv_store(h, "time", strlen("time"), newSVpv(owl_message_get_timestr(m),0),0); 91 (void)hv_store(h, "id", strlen("id"), newSViv(owl_message_get_id(m)),0); 92 (void)hv_store(h, "deleted", strlen("deleted"), newSViv(owl_message_is_delete(m)),0); 93 (void)hv_store(h, "private", strlen("private"), newSViv(owl_message_is_private(m)),0); 94 (void)hv_store(h, "should_wordwrap", 95 strlen("should_wordwrap"), newSViv( 96 owl_filter_message_match(wrap, m)),0); 97 97 98 98 type = owl_message_get_type(m); … … 102 102 blessas = owl_sprintf("BarnOwl::Message::%s", type); 103 103 104 hr = sv_2mortal(newRV_noinc((SV*)h));104 hr = newRV_noinc((SV*)h); 105 105 stash = gv_stashpv(blessas,0); 106 106 if(!stash) { … … 182 182 dSP ; 183 183 int count; 184 unsigned int len;185 184 SV *msgref, *srv; 186 char *out , *preout;185 char *out; 187 186 188 187 ENTER ; … … 191 190 PUSHMARK(SP) ; 192 191 msgref = owl_perlconfig_message2hashref(m); 193 XPUSHs( msgref);192 XPUSHs(sv_2mortal(msgref)); 194 193 PUTBACK ; 195 194 … … 199 198 200 199 if (SvTRUE(ERRSV)) { 201 STRLEN n_a; 202 owl_function_error("Perl Error: '%s'", SvPV(ERRSV, n_a)); 200 owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV)); 203 201 /* and clear the error */ 204 202 sv_setsv (ERRSV, &PL_sv_undef); … … 213 211 214 212 if (srv) { 215 preout=SvPV(srv, len); 216 out = owl_malloc(strlen(preout)+1); 217 strncpy(out, preout, len); 218 out[len] = '\0'; 213 out = owl_strdup(SvPV_nolen(srv)); 219 214 } else { 220 215 out = NULL; … … 235 230 { 236 231 dSP; 237 unsigned int count, len,i;232 unsigned int count, i; 238 233 SV *msgref, *srv; 239 char *out , *preout;234 char *out; 240 235 241 236 msgref = owl_perlconfig_message2hashref(m); … … 245 240 246 241 PUSHMARK(SP); 247 XPUSHs( msgref);242 XPUSHs(sv_2mortal(msgref)); 248 243 for(i=0;i<argc;i++) { 249 244 XPUSHs(sv_2mortal(newSVpv(argv[i], 0))); … … 261 256 262 257 if (SvTRUE(ERRSV)) { 263 STRLEN n_a; 264 owl_function_error("Error: '%s'", SvPV(ERRSV, n_a)); 258 owl_function_error("Error: '%s'", SvPV_nolen(ERRSV)); 265 259 /* and clear the error */ 266 260 sv_setsv (ERRSV, &PL_sv_undef); … … 270 264 271 265 if (srv) { 272 preout=SvPV(srv, len); 273 out = owl_malloc(strlen(preout)+1); 274 strncpy(out, preout, len); 275 out[len] = '\0'; 266 out = owl_strdup(SvPV_nolen(srv)); 276 267 } else { 277 268 out = NULL; … … 301 292 owl_global_set_no_have_config(&g); 302 293 303 304 294 ret=perl_parse(p, owl_perl_xs_init, 2, args, NULL); 305 295 if (ret || SvTRUE(ERRSV)) { 306 STRLEN n_a; 307 err=owl_strdup(SvPV(ERRSV, n_a)); 296 err=owl_strdup(SvPV_nolen(ERRSV)); 308 297 sv_setsv(ERRSV, &PL_sv_undef); /* and clear the error */ 309 298 return(err); … … 312 301 ret=perl_run(p); 313 302 if (ret || SvTRUE(ERRSV)) { 314 STRLEN n_a; 315 err=owl_strdup(SvPV(ERRSV, n_a)); 303 err=owl_strdup(SvPV_nolen(ERRSV)); 316 304 sv_setsv(ERRSV, &PL_sv_undef); /* and clear the error */ 317 305 return(err); … … 321 309 322 310 /* create legacy variables */ 323 perl_get_sv("BarnOwl::id", TRUE);324 perl_get_sv("BarnOwl::class", TRUE);325 perl_get_sv("BarnOwl::instance", TRUE);326 perl_get_sv("BarnOwl::recipient", TRUE);327 perl_get_sv("BarnOwl::sender", TRUE);328 perl_get_sv("BarnOwl::realm", TRUE);329 perl_get_sv("BarnOwl::opcode", TRUE);330 perl_get_sv("BarnOwl::zsig", TRUE);331 perl_get_sv("BarnOwl::msg", TRUE);332 perl_get_sv("BarnOwl::time", TRUE);333 perl_get_sv("BarnOwl::host", TRUE);334 perl_get_av("BarnOwl::fields", TRUE);311 get_sv("BarnOwl::id", TRUE); 312 get_sv("BarnOwl::class", TRUE); 313 get_sv("BarnOwl::instance", TRUE); 314 get_sv("BarnOwl::recipient", TRUE); 315 get_sv("BarnOwl::sender", TRUE); 316 get_sv("BarnOwl::realm", TRUE); 317 get_sv("BarnOwl::opcode", TRUE); 318 get_sv("BarnOwl::zsig", TRUE); 319 get_sv("BarnOwl::msg", TRUE); 320 get_sv("BarnOwl::time", TRUE); 321 get_sv("BarnOwl::host", TRUE); 322 get_av("BarnOwl::fields", TRUE); 335 323 336 324 if(file) { … … 339 327 } 340 328 341 perl_eval_pv(owl_perlwrap_codebuff, FALSE);329 eval_pv(owl_perlwrap_codebuff, FALSE); 342 330 343 331 if (SvTRUE(ERRSV)) { 344 STRLEN n_a; 345 err=owl_strdup(SvPV(ERRSV, n_a)); 332 err=owl_strdup(SvPV_nolen(ERRSV)); 346 333 sv_setsv (ERRSV, &PL_sv_undef); /* and clear the error */ 347 334 return(err); … … 358 345 /* returns whether or not a function exists */ 359 346 int owl_perlconfig_is_function(char *fn) { 360 if ( perl_get_cv(fn, FALSE)) return(1);347 if (get_cv(fn, FALSE)) return(1); 361 348 else return(0); 362 }363 364 /* returns 0 on success */365 int owl_perlconfig_get_hashkeys(char *hashname, owl_list *l)366 {367 HV *hv;368 HE *he;369 char *key;370 I32 i;371 372 if (owl_list_create(l)) return(-1);373 hv = get_hv(hashname, FALSE);374 if (!hv) return(-1);375 i = hv_iterinit(hv);376 while ((he = hv_iternext(hv))) {377 key = hv_iterkey(he, &i);378 if (key) {379 owl_list_append_element(l, owl_strdup(key));380 }381 }382 return(0);383 349 } 384 350 … … 392 358 if (!owl_global_have_config(&g)) return NULL; 393 359 360 ENTER; 361 SAVETMPS; 394 362 /* execute the subroutine */ 395 response = perl_eval_pv(line, FALSE);363 response = eval_pv(line, FALSE); 396 364 397 365 if (SvTRUE(ERRSV)) { 398 STRLEN n_a; 399 owl_function_error("Perl Error: '%s'", SvPV(ERRSV, n_a)); 366 owl_function_error("Perl Error: '%s'", SvPV_nolen(ERRSV)); 400 367 sv_setsv (ERRSV, &PL_sv_undef); /* and clear the error */ 401 368 } 402 369 403 370 preout=SvPV(response, len); 404 /* leave enough space in case we have to add a newline */ 405 out = owl_malloc(strlen(preout)+2); 406 strncpy(out, preout, len); 407 out[len] = '\0'; 408 if (!strlen(out) || out[strlen(out)-1]!='\n') { 409 strcat(out, "\n"); 410 } 371 if (len == 0 || preout[len - 1] != '\n') 372 out = owl_sprintf("%s\n", preout); 373 else 374 out = owl_strdup(preout); 375 FREETMPS; 376 LEAVE; 411 377 412 378 return(out); … … 439 405 char * ret = NULL; 440 406 SV *rv; 441 STRLEN n_a;442 407 dSP; 443 408 … … 458 423 459 424 if(SvTRUE(ERRSV)) { 460 owl_function_error("%s", SvPV (ERRSV, n_a));425 owl_function_error("%s", SvPV_nolen(ERRSV)); 461 426 (void)POPs; 462 427 } else { … … 465 430 rv = POPs; 466 431 if(SvTRUE(rv)) { 467 ret = owl_strdup(SvPV (rv, n_a));432 ret = owl_strdup(SvPV_nolen(rv)); 468 433 } 469 434 } … … 482 447 void owl_perlconfig_dispatch_free(owl_dispatch *d) 483 448 { 484 SvREFCNT_dec(d->pfunc); 449 SvREFCNT_dec(d->data); 450 owl_free(d); 485 451 } 486 452 … … 489 455 SV *cb = (SV*)(e->cbdata); 490 456 SV *text; 491 unsigned int n_a;492 457 dSP; 493 458 … … 508 473 509 474 if(SvTRUE(ERRSV)) { 510 owl_function_error("%s", SvPV (ERRSV, n_a));475 owl_function_error("%s", SvPV_nolen(ERRSV)); 511 476 } 512 477 … … 526 491 call_pv("BarnOwl::Hooks::_mainloop_hook", G_DISCARD|G_EVAL); 527 492 if(SvTRUE(ERRSV)) { 528 STRLEN n_a; 529 owl_function_error("%s", SvPV(ERRSV, n_a)); 493 owl_function_error("%s", SvPV_nolen(ERRSV)); 530 494 } 531 495 return; 532 496 } 533 497 534 void owl_perlconfig_do_dispatch(owl_dispatch *d) 535 { 536 SV *cb = d->pfunc; 537 unsigned int n_a; 498 void owl_perlconfig_dispatch(owl_dispatch *d) 499 { 500 SV *cb = d->data; 538 501 dSP; 539 502 if(cb == NULL) { 540 503 owl_function_error("Perl callback is NULL!"); 504 return; 541 505 } 542 506 … … 550 514 551 515 if(SvTRUE(ERRSV)) { 552 owl_function_error("%s", SvPV (ERRSV, n_a));516 owl_function_error("%s", SvPV_nolen(ERRSV)); 553 517 } 554 518 … … 556 520 LEAVE; 557 521 } 522 523 void owl_perlconfig_perl_timer(owl_timer *t, void *data) 524 { 525 SV *obj = data; 526 527 if(!SvROK(obj)) { 528 return; 529 } 530 531 dSP; 532 ENTER; 533 SAVETMPS; 534 535 PUSHMARK(SP); 536 XPUSHs(obj); 537 PUTBACK; 538 539 call_method("do_callback", G_DISCARD|G_KEEPERR|G_EVAL); 540 541 SPAGAIN; 542 543 if (SvTRUE(ERRSV)) { 544 owl_function_error("Error in calback: '%s'", SvPV_nolen(ERRSV)); 545 sv_setsv (ERRSV, &PL_sv_undef); 546 } 547 548 PUTBACK; 549 FREETMPS; 550 LEAVE; 551 } 552 553 void owl_perlconfig_perl_timer_destroy(owl_timer *t) 554 { 555 if(SvOK((SV*)t->data)) { 556 SvREFCNT_dec((SV*)t->data); 557 } 558 } -
perlglue.xs
r740d5f7 r1631825 24 24 * complex argument processing or something, we define a 25 25 * simple version here that takes arguments in as flat a 26 * manner as possible, to simplify the XS code, with a name27 * with a trailing `_internal', and write a perl wrapper in28 * perlwrap.pm that munges the arguments as appropriate and29 * calls theinternal version.26 * manner as possible, to simplify the XS code, put it in 27 * BarnOwl::Intenal::, and write a perl wrapper in perlwrap.pm 28 * that munges the arguments as appropriate and calls the 29 * internal version. 30 30 */ 31 31 … … 62 62 getcurmsg() 63 63 CODE: 64 ST(0) = owl_perlconfig_curmessage2hashref(); 64 RETVAL = owl_perlconfig_curmessage2hashref(); 65 OUTPUT: 66 RETVAL 65 67 66 68 int … … 141 143 if (rv) owl_free(rv); 142 144 143 void 144 new_command_internal(name, func, summary, usage, description) 145 void queue_message(msg) 146 SV *msg 147 PREINIT: 148 owl_message *m; 149 CODE: 150 { 151 if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { 152 croak("Usage: BarnOwl::queue_message($message)"); 153 } 154 155 m = owl_perlconfig_hashref2message(msg); 156 157 owl_global_messagequeue_addmsg(&g, m); 158 } 159 160 void admin_message(header, body) 161 char *header 162 char *body 163 CODE: 164 { 165 owl_function_adminmsg(header, body); 166 } 167 168 void start_question(line, callback) 169 char *line 170 SV *callback 171 PREINIT: 172 CODE: 173 { 174 if(!SV_IS_CODEREF(callback)) 175 croak("Callback must be a subref"); 176 177 owl_function_start_question(line); 178 179 SvREFCNT_inc(callback); 180 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); 181 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); 182 } 183 184 void start_password(line, callback) 185 char *line 186 SV *callback 187 PREINIT: 188 CODE: 189 { 190 if(!SV_IS_CODEREF(callback)) 191 croak("Callback must be a subref"); 192 193 owl_function_start_password(line); 194 195 SvREFCNT_inc(callback); 196 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); 197 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); 198 } 199 200 void start_edit_win(line, callback) 201 char *line 202 SV *callback 203 PREINIT: 204 owl_editwin * e; 205 char buff[1024]; 206 CODE: 207 { 208 if(!SV_IS_CODEREF(callback)) 209 croak("Callback must be a subref"); 210 211 e = owl_global_get_typwin(&g); 212 owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, 213 owl_global_get_msg_history(&g)); 214 owl_editwin_clear(e); 215 owl_editwin_set_dotsend(e); 216 snprintf(buff, 1023, "----> %s\n", line); 217 owl_editwin_set_locktext(e, buff); 218 219 owl_global_set_typwin_active(&g); 220 221 SvREFCNT_inc(callback); 222 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); 223 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); 224 } 225 226 227 char * 228 get_data_dir () 229 CODE: 230 RETVAL = (char *) owl_get_datadir(); 231 OUTPUT: 232 RETVAL 233 234 char * 235 get_config_dir () 236 CODE: 237 RETVAL = (char *) owl_global_get_confdir(&g); 238 OUTPUT: 239 RETVAL 240 241 void 242 popless_text(text) 243 char *text 244 CODE: 245 { 246 owl_function_popless_text(text); 247 } 248 249 void 250 popless_ztext(text) 251 char *text 252 CODE: 253 { 254 owl_fmtext fm; 255 owl_fmtext_init_null(&fm); 256 owl_fmtext_append_ztext(&fm, text); 257 owl_function_popless_fmtext(&fm); 258 owl_fmtext_free(&fm); 259 } 260 261 void 262 error(text) 263 char *text 264 CODE: 265 { 266 owl_function_error("%s", text); 267 } 268 269 void 270 create_style(name, object) 271 char *name 272 SV *object 273 PREINIT: 274 owl_style *s; 275 CODE: 276 { 277 s = owl_malloc(sizeof(owl_style)); 278 owl_style_create_perl(s, name, object); 279 owl_global_add_style(&g, s); 280 } 281 282 int 283 getnumcolors() 284 CODE: 285 RETVAL = owl_function_get_color_count(); 286 OUTPUT: 287 RETVAL 288 289 void 290 _remove_filter(filterName) 291 char *filterName 292 CODE: 293 { 294 /* Don't delete the current view, or the 'all' filter */ 295 if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) 296 && strcmp(filterName, "all")) { 297 owl_global_remove_filter(&g,filterName); 298 } 299 } 300 301 char * 302 wordwrap(in, cols) 303 char *in 304 int cols 305 PREINIT: 306 char *rv = NULL; 307 CODE: 308 rv = owl_text_wordwrap(in, cols); 309 RETVAL = rv; 310 OUTPUT: 311 RETVAL 312 CLEANUP: 313 if (rv) owl_free(rv); 314 315 void 316 add_dispatch(fd, cb) 317 int fd 318 SV * cb 319 CODE: 320 SvREFCNT_inc(cb); 321 owl_select_add_perl_dispatch(fd, cb); 322 323 void 324 remove_dispatch(fd) 325 int fd 326 CODE: 327 owl_select_remove_perl_dispatch(fd); 328 329 MODULE = BarnOwl PACKAGE = BarnOwl::Internal 330 331 332 void 333 new_command(name, func, summary, usage, description) 145 334 char *name 146 335 SV *func … … 172 361 } 173 362 174 void queue_message(msg) 175 SV *msg 176 PREINIT: 177 owl_message *m; 178 CODE: 179 { 180 if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { 181 croak("Usage: BarnOwl::queue_message($message)"); 182 } 183 184 m = owl_perlconfig_hashref2message(msg); 185 186 owl_global_messagequeue_addmsg(&g, m); 187 } 188 189 void admin_message(header, body) 190 char *header 191 char *body 192 CODE: 193 { 194 owl_function_adminmsg(header, body); 195 } 196 197 void start_question(line, callback) 198 char *line 199 SV *callback 200 PREINIT: 201 CODE: 202 { 203 if(!SV_IS_CODEREF(callback)) 204 croak("Callback must be a subref"); 205 206 owl_function_start_question(line); 207 208 SvREFCNT_inc(callback); 209 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); 210 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); 211 } 212 213 void start_password(line, callback) 214 char *line 215 SV *callback 216 PREINIT: 217 CODE: 218 { 219 if(!SV_IS_CODEREF(callback)) 220 croak("Callback must be a subref"); 221 222 owl_function_start_password(line); 223 224 SvREFCNT_inc(callback); 225 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); 226 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); 227 } 228 229 void start_edit_win(line, callback) 230 char *line 231 SV *callback 232 PREINIT: 233 owl_editwin * e; 234 char buff[1024]; 235 CODE: 236 { 237 if(!SV_IS_CODEREF(callback)) 238 croak("Callback must be a subref"); 239 240 e = owl_global_get_typwin(&g); 241 owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, 242 owl_global_get_msg_history(&g)); 243 owl_editwin_clear(e); 244 owl_editwin_set_dotsend(e); 245 snprintf(buff, 1023, "----> %s\n", line); 246 owl_editwin_set_locktext(e, buff); 247 248 owl_global_set_typwin_active(&g); 249 250 SvREFCNT_inc(callback); 251 owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); 252 owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); 253 } 254 255 256 char * 257 get_data_dir () 258 CODE: 259 RETVAL = (char *) owl_get_datadir(); 260 OUTPUT: 261 RETVAL 262 263 char * 264 get_config_dir () 265 CODE: 266 RETVAL = (char *) owl_global_get_confdir(&g); 267 OUTPUT: 268 RETVAL 269 270 void 271 popless_text(text) 272 char *text 273 CODE: 274 { 275 owl_function_popless_text(text); 276 } 277 278 void 279 popless_ztext(text) 280 char *text 281 CODE: 282 { 283 owl_fmtext fm; 284 owl_fmtext_init_null(&fm); 285 owl_fmtext_append_ztext(&fm, text); 286 owl_function_popless_fmtext(&fm); 287 owl_fmtext_free(&fm); 288 } 289 290 void 291 error(text) 292 char *text 293 CODE: 294 { 295 owl_function_error("%s", text); 296 } 297 298 void 299 create_style(name, object) 300 char *name 301 SV *object 302 PREINIT: 303 owl_style *s; 304 CODE: 305 { 306 s = owl_malloc(sizeof(owl_style)); 307 owl_style_create_perl(s, name, object); 308 owl_global_add_style(&g, s); 309 } 310 311 int 312 getnumcolors() 313 CODE: 314 RETVAL = owl_function_get_color_count(); 315 OUTPUT: 316 RETVAL 317 318 void 319 _remove_filter(filterName) 320 char *filterName 321 CODE: 322 { 323 /* Don't delete the current view, or the 'all' filter */ 324 if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) 325 && strcmp(filterName, "all")) { 326 owl_global_remove_filter(&g,filterName); 327 } 328 } 329 330 char * 331 wordwrap(in, cols) 332 char *in 333 int cols 334 PREINIT: 335 char *rv = NULL; 336 CODE: 337 rv = owl_text_wordwrap(in, cols); 338 RETVAL = rv; 339 OUTPUT: 340 RETVAL 341 CLEANUP: 342 if (rv) owl_free(rv); 343 344 void 345 new_variable_string_internal(name, ival, summ, desc) 363 void 364 new_variable_string(name, ival, summ, desc) 346 365 char * name 347 366 char * ival … … 356 375 357 376 void 358 new_variable_int _internal(name, ival, summ, desc)377 new_variable_int(name, ival, summ, desc) 359 378 char * name 360 379 int ival … … 369 388 370 389 void 371 new_variable_bool _internal(name, ival, summ, desc)390 new_variable_bool(name, ival, summ, desc) 372 391 char * name 373 392 int ival … … 381 400 ival); 382 401 383 void 384 add_dispatch(fd, cb) 385 int fd 386 SV * cb 387 CODE: 388 SvREFCNT_inc(cb); 389 owl_select_add_perl_dispatch(fd, cb); 390 391 void 392 remove_dispatch(fd) 393 int fd 394 CODE: 395 owl_select_remove_perl_dispatch(fd); 402 IV 403 add_timer(after, interval, cb) 404 int after 405 int interval 406 SV *cb 407 PREINIT: 408 SV *ref; 409 owl_timer *t; 410 CODE: 411 ref = sv_rvweaken(newSVsv(cb)); 412 t = owl_select_add_timer(after, 413 interval, 414 owl_perlconfig_perl_timer, 415 owl_perlconfig_perl_timer_destroy, 416 ref); 417 owl_function_debugmsg("Created timer %p", t); 418 RETVAL = (IV)t; 419 OUTPUT: 420 RETVAL 421 422 void 423 remove_timer(timer) 424 IV timer 425 PREINIT: 426 owl_timer *t; 427 CODE: 428 t = (owl_timer*)timer; 429 owl_function_debugmsg("Freeing timer %p", t); 430 owl_select_remove_timer(t); -
perlwrap.pm
r740d5f7 re9708d2 242 242 ); 243 243 244 BarnOwl:: new_command_internal($name, $func, $args{summary}, $args{usage}, $args{description});244 BarnOwl::Internal::new_command($name, $func, $args{summary}, $args{usage}, $args{description}); 245 245 } 246 246 … … 275 275 276 276 sub new_variable_int { 277 unshift @_, \&BarnOwl:: new_variable_int_internal, 0;277 unshift @_, \&BarnOwl::Internal::new_variable_int, 0; 278 278 goto \&_new_variable; 279 279 } 280 280 281 281 sub new_variable_bool { 282 unshift @_, \&BarnOwl:: new_variable_bool_internal, 0;282 unshift @_, \&BarnOwl::Internal::new_variable_bool, 0; 283 283 goto \&_new_variable; 284 284 } 285 285 286 286 sub new_variable_string { 287 unshift @_, \&BarnOwl:: new_variable_string_internal, "";287 unshift @_, \&BarnOwl::Internal::new_variable_string, ""; 288 288 goto \&_new_variable; 289 289 } … … 795 795 =item $receiveMessage 796 796 797 Called with a C<BarnOwl::Message> object every time BarnOwl appends a 798 new message to its message list 797 Called with a C<BarnOwl::Message> object every time BarnOwl receives a 798 new incoming message. 799 800 =item $newMessage 801 802 Called with a C<BarnOwl::Message> object every time BarnOwl appends 803 I<any> new message to the message list. 799 804 800 805 =item $mainLoop … … 810 815 displayed in a popup window, with zephyr formatting parsed. 811 816 817 =item $getQuickstart 818 819 Called by :show quickstart to display 2-5 lines of help on how to 820 start using the protocol. The result from every function registered 821 with this hook will be appended and displayed in an admin message, 822 with zephyr formatting parsed. The format should be 823 "@b(Protocol:)\nSome text.\nMore text.\n" 824 812 825 =back 813 826 … … 818 831 our @EXPORT_OK = qw($startup $shutdown 819 832 $receiveMessage $newMessage 820 $mainLoop $getBuddyList); 833 $mainLoop $getBuddyList 834 $getQuickstart); 821 835 822 836 our %EXPORT_TAGS = (all => [@EXPORT_OK]); … … 828 842 our $mainLoop = BarnOwl::Hook->new; 829 843 our $getBuddyList = BarnOwl::Hook->new; 844 our $getQuickstart = BarnOwl::Hook->new; 830 845 831 846 # Internal startup/shutdown routines called by the C code … … 921 936 } 922 937 938 sub _get_quickstart { 939 return join("\n", $getQuickstart->run); 940 } 941 923 942 ################################################################################ 924 943 # Built-in perl styles … … 1214 1233 } 1215 1234 1235 package BarnOwl::Timer; 1236 1237 sub new { 1238 my $class = shift; 1239 my $args = shift; 1240 1241 my $cb = $args->{cb}; 1242 die("Invalid callback pased to BarnOwl::Timer\n") unless ref($cb) eq 'CODE'; 1243 1244 my $self = {cb => $cb}; 1245 1246 bless($self, $class); 1247 1248 $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0, 1249 $args->{interval} || 0, 1250 $self); 1251 return $self; 1252 } 1253 1254 sub do_callback { 1255 my $self = shift; 1256 $self->{cb}->($self); 1257 } 1258 1259 sub DESTROY { 1260 my $self = shift; 1261 if(defined($self->{timer})) { 1262 BarnOwl::Internal::remove_timer($self->{timer}); 1263 } 1264 } 1265 1216 1266 1217 1267 # switch to package main when we're done -
popexec.c
r1971b59 r40c6657 51 51 return NULL; 52 52 } else if (pid != 0) { 53 close(child_write_fd); 53 54 /* still in owl */ 54 int muxhandle;55 55 pe->pid=pid; 56 56 pe->winactive=1; 57 pe-> rfd = parent_read_fd;58 close(child_write_fd);59 muxhandle = owl_muxevents_add(owl_global_get_muxevents(&g),60 parent_read_fd, OWL_MUX_READ|OWL_MUX_EXCEPT,61 owl_popexec_inputhandler, (void*)pe);57 pe->dispatch.fd = parent_read_fd; 58 pe->dispatch.cfunc = owl_popexec_inputhandler; 59 pe->dispatch.destroy = owl_popexec_free_dispatch; 60 pe->dispatch.data = pe; 61 owl_select_add_dispatch(&pe->dispatch); 62 62 pe->refcount++; 63 63 } else { … … 73 73 dup2(child_write_fd, 2 /*stderr*/); 74 74 close(child_write_fd); 75 76 while(0) {77 write(child_write_fd, "meep\n", 5);78 sleep(1);79 }80 75 81 76 argv[0] = "sh"; … … 90 85 } 91 86 92 void owl_popexec_inputhandler( int handle, int fd, int eventmask, void *data)87 void owl_popexec_inputhandler(owl_dispatch *d) 93 88 { 94 owl_popexec *pe = (owl_popexec*)data;89 owl_popexec *pe = d->data; 95 90 int navail, bread, rv_navail; 96 91 char *buf; … … 101 96 /* If pe->winactive is 0 then the vwin has closed. 102 97 * If pe->pid is 0 then the child has already been reaped. 103 * if pe->rfd is -1 then the fd has been closed out.98 * if d->fd is -1 then the fd has been closed out. 104 99 * Under these cases we want to get to a state where: 105 100 * - data read until end if child running … … 110 105 111 106 /* the viewwin has closed */ 112 if (pe->rfd<0 && !pe->pid && !pe->winactive) { 113 owl_muxevents_remove(owl_global_get_muxevents(&g), handle); 114 owl_function_debugmsg("unref of %p from input handler at A", pe); 115 owl_popexec_unref(pe); 107 if (!pe->pid && !pe->winactive) { 108 owl_select_remove_dispatch(d->fd); 116 109 return; 117 110 } 118 111 119 if (0 != (rv_navail = ioctl( fd, FIONREAD, (void*)&navail))) {112 if (0 != (rv_navail = ioctl(d->fd, FIONREAD, (void*)&navail))) { 120 113 owl_function_debugmsg("ioctl error"); 121 114 } … … 130 123 owl_viewwin_redisplay(pe->vwin, 1); 131 124 } 132 if (pe->rfd>0) { 133 close(pe->rfd); 134 pe->rfd = -1; 135 } 136 owl_muxevents_remove(owl_global_get_muxevents(&g), handle); 137 owl_function_debugmsg("unref of %p from input handler at B", pe); 138 owl_popexec_unref(pe); 125 owl_select_remove_dispatch(d->fd); 139 126 return; 140 127 } 141 128 142 if ( pe->rfd<0 || !pe->pid || !pe->winactive || rv_navail) {129 if (d->fd<0 || !pe->pid || !pe->winactive || rv_navail) { 143 130 owl_function_error("popexec should not have reached this point"); 144 131 return; … … 148 135 if (navail>1024) { navail = 1024; } 149 136 buf = owl_malloc(navail+1); 150 owl_function_debugmsg("about to read %d \n", navail);151 bread = read( fd, buf, navail);137 owl_function_debugmsg("about to read %d", navail); 138 bread = read(d->fd, buf, navail); 152 139 if (bread<0) { 153 140 perror("read"); … … 157 144 buf[navail] = '\0'; 158 145 } 159 owl_function_debugmsg("got data: <%s> \n", buf);146 owl_function_debugmsg("got data: <%s>", buf); 160 147 if (pe->winactive) { 161 148 owl_viewwin_append_text(pe->vwin, buf); … … 166 153 } 167 154 155 void owl_popexec_free_dispatch(owl_dispatch *d) 156 { 157 owl_popexec *pe = d->data; 158 close(d->fd); 159 owl_popexec_unref(pe); 160 } 161 168 162 void owl_popexec_viewwin_onclose(owl_viewwin *vwin, void *data) 169 163 { … … 172 166 173 167 pe->winactive = 0; 174 if (pe->rfd>0) { 175 close(pe->rfd); 176 pe->rfd = -1; 168 if (pe->dispatch.fd>0) { 169 owl_select_remove_dispatch(pe->dispatch.fd); 177 170 } 178 171 if (pe->pid) { -
popwin.c
r818a073 rf34dd65 57 57 } 58 58 59 int owl_popwin_display_text(owl_popwin *pw, char *text)60 {61 waddstr(pw->popwin, text);62 wnoutrefresh(pw->popwin);63 touchwin(pw->borderwin);64 wnoutrefresh(pw->borderwin);65 owl_global_set_needrefresh(&g);66 return(0);67 }68 69 59 int owl_popwin_close(owl_popwin *pw) 70 60 { … … 96 86 } 97 87 98 void owl_popwin_set_handler(owl_popwin *pw, void (*func)(int ch))99 {100 pw->handler=func;101 }102 103 void owl_popwin_unset_handler(owl_popwin *pw)104 {105 pw->handler=NULL;106 }107 108 88 WINDOW *owl_popwin_get_curswin(owl_popwin *pw) 109 89 { -
regex.c
r8b7466b r554a2b8 13 13 { 14 14 int ret; 15 char buff1[LINE] , buff2[LINE];15 char buff1[LINE]; 16 16 char *ptr; 17 17 … … 29 29 if (ret) { 30 30 regerror(ret, NULL, buff1, LINE); 31 sprintf(buff2, "Error in regular expression: %s", buff1); 32 owl_function_makemsg(buff2); 31 owl_function_makemsg("Error in regular expression: %s", buff1); 33 32 owl_free(re->string); 34 33 re->string=NULL; -
select.c
r2f69081 r1895c29 2 2 3 3 static const char fileIdent[] = "$Id: select.c 894 2008-01-17 07:13:44Z asedeno $"; 4 5 static int dispatch_active = 0; 6 7 int _owl_select_timer_cmp(owl_timer *t1, owl_timer *t2) { 8 return t1->time - t2->time; 9 } 10 11 int _owl_select_timer_eq(owl_timer *t1, owl_timer *t2) { 12 return t1 == t2; 13 } 14 15 owl_timer *owl_select_add_timer(int after, int interval, void (*cb)(owl_timer *, void *), void (*destroy)(owl_timer*), void *data) 16 { 17 owl_timer *t = owl_malloc(sizeof(owl_timer)); 18 GList **timers = owl_global_get_timerlist(&g); 19 20 t->time = time(NULL) + after; 21 t->interval = interval; 22 t->callback = cb; 23 t->destroy = destroy; 24 t->data = data; 25 26 *timers = g_list_insert_sorted(*timers, t, 27 (GCompareFunc)_owl_select_timer_cmp); 28 return t; 29 } 30 31 void owl_select_remove_timer(owl_timer *t) 32 { 33 GList **timers = owl_global_get_timerlist(&g); 34 if (t && g_list_find(*timers, t)) { 35 *timers = g_list_remove(*timers, t); 36 if(t->destroy) { 37 t->destroy(t); 38 } 39 owl_free(t); 40 } 41 } 42 43 void owl_select_process_timers(struct timeval *timeout) 44 { 45 time_t now = time(NULL); 46 GList **timers = owl_global_get_timerlist(&g); 47 48 while(*timers) { 49 owl_timer *t = (*timers)->data; 50 int remove = 0; 51 52 if(t->time > now) 53 break; 54 55 /* Reschedule if appropriate */ 56 if(t->interval > 0) { 57 t->time = now + t->interval; 58 *timers = g_list_remove(*timers, t); 59 *timers = g_list_insert_sorted(*timers, t, 60 (GCompareFunc)_owl_select_timer_cmp); 61 } else { 62 remove = 1; 63 } 64 65 /* Do the callback */ 66 t->callback(t, t->data); 67 if(remove) { 68 owl_select_remove_timer(t); 69 } 70 } 71 72 if(*timers) { 73 owl_timer *t = (*timers)->data; 74 timeout->tv_sec = t->time - now; 75 if (timeout->tv_sec > 60) 76 timeout->tv_sec = 60; 77 } else { 78 timeout->tv_sec = 60; 79 } 80 81 timeout->tv_usec = 0; 82 } 4 83 5 84 /* Returns the index of the dispatch for the file descriptor. */ … … 19 98 } 20 99 100 void owl_select_remove_dispatch_at(int elt) /* noproto */ 101 { 102 owl_list *dl; 103 owl_dispatch *d; 104 105 dl = owl_global_get_dispatchlist(&g); 106 d = (owl_dispatch*)owl_list_get_element(dl, elt); 107 owl_list_remove_element(dl, elt); 108 if (d->destroy) { 109 d->destroy(d); 110 } 111 } 112 21 113 /* Adds a new owl_dispatch to the list, replacing existing ones if needed. */ 22 114 void owl_select_add_dispatch(owl_dispatch *d) … … 24 116 int elt; 25 117 owl_list *dl; 118 119 d->needs_gc = 0; 26 120 27 121 elt = owl_select_find_dispatch(d->fd); … … 34 128 replace the old dispatch. */ 35 129 if (d_old != d) { 36 owl_list_replace_element(dl, elt, d); 37 owl_free(d_old); 38 } 39 } 40 else { 41 owl_list_append_element(dl, d); 42 } 130 owl_select_remove_dispatch_at(elt); 131 } 132 } 133 owl_list_append_element(dl, d); 43 134 } 44 135 … … 48 139 int elt; 49 140 owl_list *dl; 141 owl_dispatch *d; 50 142 51 143 elt = owl_select_find_dispatch(fd); 52 dl = owl_global_get_dispatchlist(&g); 53 54 if (elt != -1) { 55 owl_dispatch *d; 144 if(elt == -1) { 145 return; 146 } else if(dispatch_active) { 147 /* Defer the removal until dispatch is done walking the list */ 148 dl = owl_global_get_dispatchlist(&g); 56 149 d = (owl_dispatch*)owl_list_get_element(dl, elt); 57 owl_list_remove_element(dl, elt); 58 if (d->pfunc) { 59 owl_perlconfig_dispatch_free(d); 60 } 61 owl_free(d); 150 d->needs_gc = 1; 151 } else { 152 owl_select_remove_dispatch_at(elt); 62 153 } 63 154 } … … 75 166 if (elt != -1) { 76 167 d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt); 77 if (d-> pfunc == NULL) {168 if (d->cfunc != owl_perlconfig_dispatch) { 78 169 /* don't mess with non-perl dispatch functions from here. */ 79 170 return 1; … … 83 174 d = malloc(sizeof(owl_dispatch)); 84 175 d->fd = fd; 85 d->cfunc = NULL; 86 d->pfunc = cb; 176 d->cfunc = owl_perlconfig_dispatch; 177 d->destroy = owl_perlconfig_dispatch_free; 178 d->data = cb; 87 179 owl_select_add_dispatch(d); 88 180 return 0; … … 97 189 if (elt != -1) { 98 190 d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt); 99 if (d-> pfunc != NULL) {100 owl_select_remove_dispatch (fd);191 if (d->cfunc == owl_perlconfig_dispatch) { 192 owl_select_remove_dispatch_at(elt); 101 193 return 0; 102 194 } … … 125 217 } 126 218 219 void owl_select_gc() 220 { 221 int i; 222 owl_list *dl; 223 224 dl = owl_global_get_dispatchlist(&g); 225 /* 226 * Count down so we aren't set off by removing items from the list 227 * during the iteration. 228 */ 229 for(i = owl_list_get_size(dl) - 1; i >= 0; i--) { 230 owl_dispatch *d = owl_list_get_element(dl, i); 231 if(d->needs_gc) { 232 owl_select_remove_dispatch_at(i); 233 } 234 } 235 } 236 127 237 void owl_select_dispatch(fd_set *fds, int max_fd) 128 238 { … … 133 243 dl = owl_global_get_dispatchlist(&g); 134 244 len = owl_select_dispatch_count(); 245 246 dispatch_active = 1; 247 135 248 for(i = 0; i < len; i++) { 136 249 d = (owl_dispatch*)owl_list_get_element(dl, i); 137 250 /* While d shouldn't normally be null, the list may be altered by 138 251 * functions we dispatch to. */ 139 if (d != NULL && FD_ISSET(d->fd, fds)) {252 if (d != NULL && !d->needs_gc && FD_ISSET(d->fd, fds)) { 140 253 if (d->cfunc != NULL) { 141 (d->cfunc)();254 d->cfunc(d); 142 255 } 143 else if (d->pfunc != NULL) {144 owl_perlconfig_do_dispatch(d);145 } 146 }147 }256 } 257 } 258 259 dispatch_active = 0; 260 owl_select_gc(); 148 261 } 149 262 … … 182 295 struct timeval timeout; 183 296 184 timeout.tv_sec = 1; 185 timeout.tv_usec = 0; 297 owl_select_process_timers(&timeout); 186 298 187 299 max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e); -
tester.c
r1cf3f8d3 r3381399 6 6 7 7 owl_global g; 8 9 void screeninit()10 {11 char buff[1024];12 13 sprintf(buff, "TERMINFO=%s", TERMINFO);14 putenv(buff);15 16 initscr();17 start_color();18 /* cbreak(); */19 raw();20 noecho();21 intrflush(stdscr,FALSE);22 keypad(stdscr,TRUE);23 nodelay(stdscr,1);24 clear();25 refresh();26 meta(stdscr, TRUE);27 }28 29 void test1()30 {31 int j;32 owl_editwin e;33 34 screeninit();35 36 owl_editwin_init(&e, stdscr, LINES, COLS, OWL_EDITWIN_STYLE_MULTILINE, NULL);37 /* owl_editwin_set_locktext(&e, "Here is some locktext:\n");*/38 doupdate();39 while (1) {40 usleep(50);41 42 j=getch();43 44 if (j==ERR) continue;45 46 if (j==3) break;47 48 if (j==27) {49 j=getch();50 if (j==ERR) continue;51 owl_editwin_process_char(&e, j);52 doupdate();53 } else {54 owl_editwin_process_char(&e, j);55 doupdate();56 }57 }58 endwin();59 printf("Had:\n%s", owl_editwin_get_text(&e));60 }61 62 void test2(char *in)63 {64 owl_fmtext t;65 66 screeninit();67 68 owl_fmtext_init_null(&t);69 owl_fmtext_append_ztext(&t, in);70 owl_fmtext_curs_waddstr(&t, stdscr);71 wrefresh(stdscr);72 sleep(5000);73 endwin();74 }75 76 void test3()77 {78 ZNotice_t *n;79 80 printf("%i\n", sizeof(n->z_uid.zuid_addr));81 /* gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET); */82 }83 84 void colorinfo()85 {86 char buff[1024];87 88 screeninit();89 sprintf(buff, "Have %i COLOR_PAIRS\n", COLOR_PAIRS);90 addstr(buff);91 refresh();92 sleep(10);93 endwin();94 }95 96 void test4()97 {98 int j;99 char buff[1024];100 101 screeninit();102 103 while (1) {104 usleep(100);105 106 j=getch();107 108 if (j==ERR) continue;109 110 if (j==3) break;111 sprintf(buff, "%o\n", j);112 addstr(buff);113 }114 endwin();115 }116 117 void test_keypress()118 {119 int j, rev;120 char buff[1024], buff2[64];121 122 screeninit();123 124 while (1) {125 usleep(100);126 127 j=wgetch(stdscr);128 129 if (j==ERR) continue;130 131 if (j==3) break;132 if (0 == owl_keypress_tostring(j, 0, buff2, 1000)) {133 rev = owl_keypress_fromstring(buff2);134 sprintf(buff, "%s : 0x%x 0%o %d %d %s\n", buff2, j, j, j, rev,135 (j==rev?"matches":"*** WARNING: Does Not Reverse"));136 } else {137 sprintf(buff, "UNKNOWN : 0x%x 0%o %d\n", j, j, j);138 }139 addstr(buff);140 }141 endwin();142 }143 144 8 145 9 #define OWL_DICT_NTESTS 20 … … 155 19 156 20 int numfailures=0; 157 if (argc==1 || (argc==2 && 0==strcmp(argv[1],"reg"))) { 158 printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS 159 +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS); 160 numfailures += owl_util_regtest(); 161 numfailures += owl_dict_regtest(); 162 numfailures += owl_variable_regtest(); 163 numfailures += owl_filter_regtest(); 164 numfailures += owl_obarray_regtest(); 165 if (numfailures) { 21 printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS 22 +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS); 23 numfailures += owl_util_regtest(); 24 numfailures += owl_dict_regtest(); 25 numfailures += owl_variable_regtest(); 26 numfailures += owl_filter_regtest(); 27 numfailures += owl_obarray_regtest(); 28 if (numfailures) { 166 29 fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures); 167 }168 return(numfailures);169 } else if (argc==2 && 0==strcmp(argv[1],"test1")) {170 test1();171 } else if (argc==2 && 0==strcmp(argv[1],"colorinfo")) {172 colorinfo();173 } else if (argc==2 && 0==strcmp(argv[1],"test4")) {174 test4();175 } else if (argc==2 && 0==strcmp(argv[1],"keypress")) {176 test_keypress();177 } else {178 fprintf(stderr, "No test specified. Current options are: reg test1\n");179 30 } 180 return( 0);31 return(numfailures); 181 32 } -
text.c
rf8d9df1 rf34dd65 6 6 7 7 static const char fileIdent[] = "$Id$"; 8 9 /* start with line aline (where the first line is 1) and print 'lines'10 * lines11 */12 int owl_text_truncate_lines(char *out, char *in, int aline, int lines)13 {14 char *ptr1, *ptr2;15 int i;16 17 strcpy(out, "");18 19 if (aline==0) aline=1; /* really illegal use */20 21 /* find the starting line */22 ptr1=in;23 if (aline!=1) {24 for (i=0; i<aline-1; i++) {25 ptr1=strchr(ptr1, '\n');26 if (!ptr1) return(-1);27 ptr1++;28 }29 }30 /* ptr1 now holds the starting point */31 32 /* copy in the next 'lines' lines */33 if (lines<1) return(-1);34 35 for (i=0; i<lines; i++) {36 ptr2=strchr(ptr1, '\n');37 if (!ptr2) {38 strcat(out, ptr1);39 return(-1);40 }41 strncat(out, ptr1, ptr2-ptr1+1);42 ptr1=ptr2+1;43 }44 return(0);45 }46 47 48 /* the first column is column 0. The message is expected to end in a49 * new line for now */50 void owl_text_truncate_cols(char *out, char *in, int acol, int bcol)51 {52 char *ptr_s, *ptr_e, *ptr_c, *tmpbuff, *last;53 int col, cnt, padding;54 55 tmpbuff=owl_malloc(strlen(in)+20);56 57 strcpy(tmpbuff, "");58 last=in+strlen(in)-1;59 ptr_s=in;60 while (ptr_s<last) {61 ptr_e=strchr(ptr_s, '\n');62 if (!ptr_e) {63 /* but this shouldn't happen if we end in a \n */64 break;65 }66 67 if (ptr_e==ptr_s) {68 strcat(tmpbuff, "\n");69 ptr_s++;70 continue;71 }72 73 col = 0;74 cnt = 0;75 padding = 0;76 ptr_c = ptr_s;77 while(col < bcol && ptr_c < ptr_e) {78 gunichar c = g_utf8_get_char(ptr_c);79 if (col + mk_wcwidth(c) > bcol) break;80 col += mk_wcwidth(c);81 ptr_c = g_utf8_next_char(ptr_c);82 if (col >= acol) {83 if (cnt == 0) {84 ptr_s = ptr_c;85 padding = col - acol;86 }87 ++cnt;88 }89 }90 if (cnt) {91 while(padding-- > 0) {92 strcat(tmpbuff, " ");93 }94 strncat(tmpbuff, ptr_s, ptr_c - ptr_s - 1);95 }96 strcat(tmpbuff, "\n");97 ptr_s = ptr_e + 1;98 #if 099 /* we need to check that we won't run over here */100 if ( (ptr_e-ptr_s) < (bcol-acol) ) {101 len=ptr_e-(ptr_s+acol);102 } else {103 len=bcol-acol;104 }105 if ((ptr_s+len)>=last) {106 len-=last-(ptr_s+len);107 }108 109 strncat(tmpbuff, ptr_s+acol, len);110 strcat(tmpbuff, "\n");111 112 ptr_s=ptr_e+1;113 #endif114 }115 strcpy(out, tmpbuff);116 owl_free(tmpbuff);117 }118 119 8 120 9 void owl_text_indent(char *out, char *in, int n) -
util.c
r601733d rf34dd65 125 125 wattroff(sepwin, A_REVERSE); 126 126 wnoutrefresh(sepwin); 127 }128 129 130 void pophandler_quit(int ch)131 {132 if (ch=='q') {133 owl_popwin_close(owl_global_get_popwin(&g));134 }135 127 } 136 128 … … 373 365 374 366 if (days>0) { 375 out=owl_sprintf("%i d %2.2i:%2.2 i", days, hours, run);367 out=owl_sprintf("%i d %2.2i:%2.2li", days, hours, run); 376 368 } else { 377 out=owl_sprintf(" %2.2i:%2.2 i", hours, run);369 out=owl_sprintf(" %2.2i:%2.2li", hours, run); 378 370 } 379 371 return(out); 380 }381 382 /* return the index of the last char before a change from the first one */383 int owl_util_find_trans(char *in, int len)384 {385 int i;386 for (i=1; i<len; i++) {387 if (in[i] != in[0]) return(i-1);388 }389 return(i);390 }391 392 int owl_util_find_trans_short(short *in, int len)393 {394 int i;395 for (i=1; i<len; i++) {396 if (in[i] != in[0]) return(i-1);397 }398 return(i);399 }400 401 /* Caller must free response.402 * Takes in strings which are space-separated lists of tokens403 * and returns a single string containing no token more than once.404 * If prohibit is non-null, no token may start with a character405 * in prohibit.406 */407 char *owl_util_uniq(char *A, char *B, char *prohibit)408 {409 410 char *cat, **tok;411 int toklen, i, j, first=1;412 cat = owl_malloc(strlen(A)+strlen(B)+3);413 strcpy(cat, A);414 strcat(cat, " ");415 strcat(cat, B);416 tok = atokenize(cat, " ", &toklen);417 strcpy(cat, "");418 for (i=0; i<toklen; i++) {419 int dup=0;420 for (j=0; j<i; j++) {421 if (!strcmp(tok[i], tok[j])) dup=1;422 }423 if (!dup && (!prohibit || !strchr(prohibit, tok[i][0]))) {424 if (!first) {425 strcat(cat, " ");426 }427 first=0;428 strcat(cat, tok[i]);429 }430 }431 atokenize_free(tok, toklen);432 return(cat);433 372 } 434 373 … … 641 580 owl_function_error("Error opening file %s for writing", backupfilename); 642 581 owl_free(backupfilename); 582 fclose(file); 643 583 return; 644 584 } 645 owl_free(backupfilename);646 585 } 647 586 … … 682 621 owl_function_error("WARNING: Error opening %s for writing. Use %s to restore.", filename, backupfilename); 683 622 owl_function_beep(); 684 owl_free(line); 685 return; 686 } 687 688 fputs(text, file); 689 fclose(file); 690 } 691 692 /* add the string 'str' to the list 'list' of strings, only if it 693 * is not already present 694 */ 695 void owl_util_list_add_unique_string(owl_list *list, char *str) 696 { 697 int i, j; 698 699 j=owl_list_get_size(list); 700 for (i=0; i<j; i++) { 701 if (!strcmp(str, owl_list_get_element(list, i))) return; 702 } 703 owl_list_append_element(list, owl_strdup(str)); 704 } 705 706 int owl_util_common_strings_in_lists(owl_list *a, owl_list *b) 707 { 708 int i, j, x, y; 709 710 j=owl_list_get_size(a); 711 for (i=0; i<j; i++) { 712 y=owl_list_get_size(b); 713 for (x=0; x<y; x++) { 714 if (!strcmp(owl_list_get_element(a, i), owl_list_get_element(b, x))) return(1); 715 } 716 } 717 return(0); 623 } else { 624 fputs(text, file); 625 fclose(file); 626 } 627 628 if (backup) 629 owl_free(backupfilename); 630 owl_free(text); 718 631 } 719 632 … … 881 794 !strcmp("meep", skiptokens("foo 'bar quux' meep", 2))); 882 795 883 FAIL_UNLESS("owl_util_uniq 1",884 !strcmp("foo bar x", owl_util_uniq("foo", "bar x", "-")));885 FAIL_UNLESS("owl_util_uniq 2",886 !strcmp("foo bar x", owl_util_uniq("foo", "bar -y x", "-")));887 FAIL_UNLESS("owl_util_uniq 3",888 !strcmp("meep foo bar", owl_util_uniq("meep foo", "bar foo meep", "-")));889 890 796 /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */ 891 797 printf("# END testing owl_util (%d failures)\n", numfailed); -
variable.c
r451db9e r4f15e8e 351 351 " the cursor will be near the center.\n", 352 352 "normal,top,neartop,center,paged,pagedcenter" ), 353 354 OWLVAR_ENUM( "webbrowser" /* %OwlVarStub */, OWL_WEBBROWSER_NETSCAPE,355 "web browser to use to launch URLs",356 "When the 'w' key is pressed, this browser is used\n"357 "to display the requested URL.\n",358 "none,netscape,galeon,opera" ),359 353 360 354 … … 1056 1050 FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize")); 1057 1051 1058 FAIL_UNLESS("get enum", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));1059 FAIL_UNLESS("get enum as string 1", 0==owl_variable_get_tostring(&vd,"webbrowser", buf, 1024));1060 FAIL_UNLESS("get enum as string 2", 0==strcmp(buf,"netscape"));1061 FAIL_UNLESS("set enum 1", 0==owl_variable_set_int(&vd,"webbrowser",OWL_WEBBROWSER_GALEON));1062 FAIL_UNLESS("get enum 2", OWL_WEBBROWSER_GALEON==owl_variable_get_int(&vd,"webbrowser"));1063 FAIL_UNLESS("set enum 1b", -1==owl_variable_set_int(&vd,"webbrowser",-3));1064 FAIL_UNLESS("set enum 1b", -1==owl_variable_set_int(&vd,"webbrowser",209));1065 FAIL_UNLESS("get enum 2b", OWL_WEBBROWSER_GALEON==owl_variable_get_int(&vd,"webbrowser"));1066 FAIL_UNLESS("set enum 3", 0==owl_variable_set_fromstring(&vd,"webbrowser","none",0,0));1067 FAIL_UNLESS("get enum 4", OWL_WEBBROWSER_NONE==owl_variable_get_int(&vd,"webbrowser"));1068 FAIL_UNLESS("set enum 5", 0==owl_variable_set_fromstring(&vd,"webbrowser","netscape",0,0));1069 FAIL_UNLESS("get enum 6", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));1070 FAIL_UNLESS("set enum 7", -1==owl_variable_set_fromstring(&vd,"webbrowser","xxx",0,0));1071 FAIL_UNLESS("set enum 8", -1==owl_variable_set_fromstring(&vd,"webbrowser","",0,0));1072 FAIL_UNLESS("set enum 9", -1==owl_variable_set_fromstring(&vd,"webbrowser","netscapey",0,0));1073 FAIL_UNLESS("get enum 10", OWL_WEBBROWSER_NETSCAPE==owl_variable_get_int(&vd,"webbrowser"));1074 1075 1052 owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval"); 1076 1053 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING))); -
wcwidth.c
r47519e1b r49a8434 62 62 #include <wchar.h> 63 63 64 st atic struct interval {64 struct interval { /* noproto */ 65 65 int first; 66 66 int last; -
zcrypt.c
r34509d5 rf34dd65 66 66 #define M_RANDOMIZE 4 67 67 #define M_SETKEY 5 68 69 int zcrypt(int argc, char *argv[]) {70 char *fname = NULL;71 int error = FALSE;72 int zephyr = FALSE;73 char *class = NULL, *instance = NULL;74 int mode = M_NONE;75 76 extern int optind, opterr;77 extern char *optarg;78 char c;79 80 int messageflag = FALSE;81 ZWRITEOPTIONS zoptions;82 zoptions.flags = 0;83 84 while ((c = getopt(argc, argv, "ZDERSF:c:i:advqtluons:f:m")) != (char)EOF) {85 switch(c) {86 case 'Z':87 /* Zephyr encrypt */88 mode = M_ZEPHYR_ENCRYPT;89 break;90 case 'D':91 /* Decrypt */92 mode = M_DECRYPT;93 break;94 case 'E':95 /* Encrypt */96 mode = M_ENCRYPT;97 break;98 case 'R':99 /* Randomize the keyfile */100 mode = M_RANDOMIZE;101 break;102 case 'S':103 /* Set a new key value from stdin */104 mode = M_SETKEY;105 break;106 case 'F':107 /* Specify the keyfile explicitly */108 if (fname != NULL) error = TRUE;109 fname = optarg;110 break;111 case 'c':112 /* Zwrite/zcrypt: class name */113 if (class != NULL) error = TRUE;114 class = optarg;115 break;116 case 'i':117 /* Zwrite/zcrypt: instance name */118 if (instance != NULL) error = TRUE;119 instance = optarg;120 break;121 case 'a':122 /* Zwrite: authenticate (default) */123 zoptions.flags &= ~ZWRITE_OPT_NOAUTH;124 break;125 case 'd':126 /* Zwrite: do not authenticate */127 zoptions.flags |= ZWRITE_OPT_NOAUTH;128 break;129 case 'v':130 /* Zwrite: verbose */131 zoptions.flags |= ZWRITE_OPT_VERBOSE;132 break;133 case 'q':134 /* Zwrite: quiet */135 zoptions.flags |= ZWRITE_OPT_QUIET;136 break;137 case 't':138 /* Zwrite: no expand tabs (ignored) */139 break;140 case 'l':141 /* Zwrite: ignore '.' on a line by itself (ignored) */142 zoptions.flags |= ZCRYPT_OPT_IGNOREDOT;143 break;144 case 'u':145 /* Zwrite: urgent message */146 instance = "URGENT";147 break;148 case 'o':149 /* Zwrite: ignore zephyr variables zwrite-class, zwrite-inst, */150 /* zwrite-opcode */151 zoptions.flags |= ZWRITE_OPT_IGNOREVARS;152 break;153 case 'n':154 /* Zwrite: prevent PING message (always used) */155 break;156 case 's':157 /* Zwrite: signature */158 zoptions.flags |= ZWRITE_OPT_SIGNATURE;159 zoptions.signature = optarg;160 break;161 case 'f':162 /* Zwrite: file system specification (ignored) */163 break;164 case 'm':165 /* Message on rest of line */166 messageflag = TRUE;167 break;168 case '?':169 error = TRUE;170 break;171 }172 if (error || messageflag) break;173 }174 175 if (class != NULL || instance != NULL) {176 zephyr = TRUE;177 }178 179 if (messageflag) {180 zoptions.flags |= ZCRYPT_OPT_MESSAGE;181 zoptions.message = BuildArgString(argv, optind, argc);182 if (!zoptions.message)183 {184 printf("Memory allocation error.\n");185 error = TRUE;186 }187 } else if (optind < argc) {188 error = TRUE;189 }190 191 if (mode == M_NONE) mode = (zephyr?M_ZEPHYR_ENCRYPT:M_ENCRYPT);192 193 if (mode == M_ZEPHYR_ENCRYPT && !zephyr) error = TRUE;194 195 if (!error && fname == NULL && (class != NULL || instance != NULL)) {196 fname = GetZephyrVarKeyFile(argv[0], class, instance);197 }198 199 200 if (error || fname == NULL) {201 printf("Usage: %s [-Z|-D|-E|-R|-S] [-F Keyfile] [-c class] [-i instance]\n", argv[0]);202 printf(" [-advqtluon] [-s signature] [-f arg] [-m message]\n");203 printf(" One or more of class, instance, and keyfile must be specified.\n");204 } else {205 if (mode == M_RANDOMIZE) {206 /* Choose a new, random key */207 /*208 FILE *fkey = fopen(fname, "w");209 if (!fkey)210 printf("Could not open key file for writing: %s\n", fname);211 else212 {213 char string[100];214 fputs(fkey, string);215 fclose(fkey);216 }217 */218 printf("Feature not yet implemented.\n");219 } else if (mode == M_SETKEY) {220 /* Set a new, user-entered key */221 char newkey[MAX_KEY];222 FILE *fkey;223 224 if (isatty(0)) {225 printf("Enter new key: ");226 /* Really should read without echo!!! */227 fgets(newkey, MAX_KEY - 1, stdin);228 } else {229 fgets(newkey, MAX_KEY - 1, stdin);230 }231 232 fkey = fopen(fname, "w");233 if (!fkey) {234 printf("Could not open key file for writing: %s\n", fname);235 } else {236 if (fputs(newkey, fkey) != strlen(newkey) || putc('\n', fkey) != '\n') {237 printf("Error writing to key file.\n");238 fclose(fkey);239 } else {240 fclose(fkey);241 printf("Key update complete.\n");242 }243 }244 } else {245 /* Encrypt/decrypt */246 FILE *fkey = fopen(fname, "r");247 if (!fkey) {248 printf("Could not open key file: %s\n", fname);249 } else {250 char keystring[MAX_KEY];251 fgets(keystring, MAX_KEY-1, fkey);252 if (mode == M_ZEPHYR_ENCRYPT || mode == M_ENCRYPT) {253 do_encrypt(keystring, (mode == M_ZEPHYR_ENCRYPT), class, instance,254 &zoptions, fname);255 } else {256 do_decrypt(keystring);257 }258 fclose(fkey);259 }260 }261 }262 263 /* Always print the **END** message if -D is specified. */264 if (mode == M_DECRYPT) printf("**END**\n");265 266 exit(0);267 }268 68 269 69 /* The 'owl_zcrypt_decrypt' function was written by kretch for Owl. … … 375 175 376 176 for (i = 0; i < 8; i++) { 377 sprintf(out , "%s%c", out, ((output[i] & 0xf0) >> 4) + BASE_CODE);378 sprintf(out , "%s%c", out, (output[i] & 0x0f) + BASE_CODE);177 sprintf(out + strlen(out), "%c", ((output[i] & 0xf0) >> 4) + BASE_CODE); 178 sprintf(out + strlen(out), "%c", (output[i] & 0x0f) + BASE_CODE); 379 179 } 380 180 … … 384 184 } 385 185 386 /* Build a space-separated string from argv from elements between start *387 * and end - 1. owl_malloc()'s the returned string. */388 char *BuildArgString(char **argv, int start, int end) {389 int len = 1;390 int i;391 char *result;392 393 /* Compute the length of the string. (Plus 1 or 2) */394 for (i = start; i < end; i++) {395 len += strlen(argv[i]) + 1;396 }397 398 /* Allocate memory */399 result = (char *)owl_malloc(len);400 if (result) {401 /* Build the string */402 char *ptr = result;403 /* Start with an empty string, in case nothing is copied. */404 *ptr = '\0';405 /* Copy the arguments */406 for (i = start; i < end; i++) {407 char *temp = argv[i];408 /* Add a space, if not the first argument */409 if (i != start) *ptr++ = ' ';410 /* Copy argv[i], leaving ptr pointing to the '\0' copied from temp */411 while ((*ptr = *temp++)!=0) {412 ptr++;413 }414 }415 }416 417 return(result);418 }419 186 420 187 #define MAX_BUFF 258 … … 423 190 char *GetZephyrVarKeyFile(char *whoami, char *class, char *instance) { 424 191 char *keyfile = NULL; 425 char varname[MAX_SEARCH][128];192 char *varname[MAX_SEARCH]; 426 193 int length[MAX_SEARCH], i; 427 194 char buffer[MAX_BUFF]; 428 char filename[MAX_BUFF];195 char *filename; 429 196 char result[MAX_SEARCH][MAX_BUFF]; 430 197 int numsearch = 0; 431 198 FILE *fsearch; 432 199 200 memset(varname, 0, sizeof(varname)); 201 433 202 /* Determine names to look for in .crypt-table */ 434 203 if (instance) { 435 sprintf(varname[numsearch++],"crypt-%s-%s:", (class?class:"message"), instance);204 varname[numsearch++] = owl_sprintf("crypt-%s-%s:", (class?class:"message"), instance); 436 205 } 437 206 if (class) { 438 sprintf(varname[numsearch++],"crypt-%s:", class);439 } 440 sprintf(varname[numsearch++],"crypt-default:");207 varname[numsearch++] = owl_sprintf("crypt-%s:", class); 208 } 209 varname[numsearch++] = owl_strdup("crypt-default:"); 441 210 442 211 /* Setup the result array, and determine string lengths */ … … 447 216 448 217 /* Open~/.crypt-table */ 449 sprintf(filename,"%s/.crypt-table", getenv("HOME"));218 filename = owl_sprintf("%s/.crypt-table", getenv("HOME")); 450 219 fsearch = fopen(filename, "r"); 451 220 if (fsearch) { … … 495 264 } 496 265 266 for(i = 0; i < MAX_SEARCH; i++) { 267 owl_free(varname[i]); 268 } 269 270 owl_free(filename); 271 497 272 return(keyfile); 498 273 } … … 500 275 static pid_t zephyrpipe_pid = 0; 501 276 502 /* Open a pipe to zwrite */ 503 static FILE *GetZephyrPipe(char *class, char *instance, ZWRITEOPTIONS *zoptions) { 504 int fildes[2]; 505 pid_t pid; 506 FILE *result; 507 char *argv[20]; 508 int argc = 0; 509 510 if (pipe(fildes) < 0) return(NULL); 511 pid = fork(); 512 513 if (pid < 0) { 514 /* Error: clean up */ 515 close(fildes[0]); 516 close(fildes[1]); 517 result = NULL; 518 } else if (pid == 0) { 519 /* Setup child process */ 520 argv[argc++] = "zwrite"; 521 argv[argc++] = "-n"; /* Always send without ping */ 522 if (class) { 523 argv[argc++] = "-c"; 524 argv[argc++] = class; 525 } 526 if (instance) { 527 argv[argc++] = "-i"; 528 argv[argc++] = instance; 529 } 530 if (zoptions->flags & ZWRITE_OPT_NOAUTH) argv[argc++] = "-d"; 531 if (zoptions->flags & ZWRITE_OPT_QUIET) argv[argc++] = "-q"; 532 if (zoptions->flags & ZWRITE_OPT_VERBOSE) argv[argc++] = "-v"; 533 if (zoptions->flags & ZWRITE_OPT_SIGNATURE) { 534 argv[argc++] = "-s"; 535 argv[argc++] = zoptions->signature; 536 } 537 argv[argc++] = "-O"; 538 argv[argc++] = "crypt"; 539 argv[argc] = NULL; 540 close(fildes[1]); 541 if (fildes[0] != STDIN_FILENO) { 542 if (dup2(fildes[0], STDIN_FILENO) != STDIN_FILENO) exit(0); 543 close(fildes[0]); 544 } 545 close(fildes[0]); 546 execvp(argv[0], argv); 547 printf("Exec error: could not run zwrite\n"); 548 exit(0); 549 } else { 550 close(fildes[0]); 551 /* Create a FILE * for the zwrite pipe */ 552 result = (FILE *)fdopen(fildes[1], "w"); 553 zephyrpipe_pid = pid; 554 } 555 556 return(result); 557 } 558 559 /* Close the pipe to zwrite */ 560 void CloseZephyrPipe(FILE *pipe) { 561 fclose(pipe); 562 waitpid(zephyrpipe_pid, NULL, 0); 563 zephyrpipe_pid = 0; 564 } 565 566 #define MAX_RESULT 2048 567 568 569 void block_to_ascii(char *output, FILE *outfile) { 570 int i; 571 for (i = 0; i < 8; i++) { 572 putc(((output[i] & 0xf0) >> 4) + BASE_CODE, outfile); 573 putc( (output[i] & 0x0f) + BASE_CODE, outfile); 574 } 575 } 576 577 #define MAX_LINE 128 578 579 /* Encrypt stdin, with prompt if isatty, and send to stdout, or to zwrite 580 if zephyr is set. */ 581 static int do_encrypt(char *keystring, int zephyr, char *class, char *instance, ZWRITEOPTIONS *zoptions, char* keyfile) { 582 des_cblock key; 583 des_key_schedule schedule; 584 char input[8], output[8]; 585 int size; 586 FILE *outfile = stdout; 587 int error = FALSE; 588 char *inbuff = NULL, *inptr; 589 int freein = FALSE; 590 int use_buffer = FALSE; 591 int num_blocks=0, last_block_size=0; 592 593 des_string_to_key(keystring, key); 594 des_key_sched(key, schedule); 595 596 if (zephyr) { 597 if (zoptions->flags & ZCRYPT_OPT_MESSAGE) { 598 /* Use the -m message */ 599 int length; 600 inbuff = zoptions->message; 601 length = strlen(inbuff); 602 num_blocks = (length + 7) / 8; 603 last_block_size = ((length + 7) % 8) + 1; 604 use_buffer = TRUE; 605 } else if (isatty(0)) { 606 /* tty input, so show the "Type your message now..." message */ 607 if (zoptions->flags & ZCRYPT_OPT_IGNOREDOT) { 608 printf("Type your message now. End with the end-of-file character.\n"); 609 } else { 610 printf("Type your message now. End with control-D or a dot on a line by itself.\n"); 611 } 612 use_buffer = TRUE; 613 if ((inptr = inbuff = (char *)owl_malloc(MAX_RESULT)) == NULL) { 614 printf("Memory allocation error\n"); 615 return FALSE; 616 } 617 while (inptr - inbuff < MAX_RESULT - MAX_LINE - 20) { 618 fgets(inptr, MAX_LINE, stdin); 619 if (inptr[0]) { 620 if (inptr[0] == '.' && inptr[1] == '\n' && 621 !(zoptions->flags & ZCRYPT_OPT_IGNOREDOT)) { 622 inptr[0] = '\0'; 623 break; 624 } else { 625 inptr += strlen(inptr); 626 } 627 } else { 628 break; 629 } 630 } 631 num_blocks = (inptr - inbuff + 7) / 8; 632 last_block_size = ((inptr - inbuff + 7) % 8) + 1; 633 freein = TRUE; 634 } 635 636 /* if (zephyr) */ 637 outfile = GetZephyrPipe(class, instance, zoptions); 638 if (!outfile) { 639 printf("Could not run zwrite\n"); 640 if (freein && inbuff) { 641 owl_free(inbuff); 642 } 643 return(FALSE); 644 } 645 } 646 647 inptr = inbuff; 648 649 /* Encrypt the input (inbuff or stdin) and send it to outfile */ 650 while (TRUE) { 651 if (use_buffer) { 652 /* Get 8 bytes from buffer */ 653 if (num_blocks > 1) { 654 size = 8; 655 memcpy(input, inptr, size); 656 inptr += 8; 657 num_blocks--; 658 } else if (num_blocks == 1) { 659 size = last_block_size; 660 memcpy(input, inptr, size); 661 num_blocks--; 662 } else { 663 size = 0; 664 } 665 } else { 666 /* Get 8 bytes from stdin */ 667 size = fread(input, 1, 8, stdin); 668 } 669 670 /* Check for EOF and pad the string to 8 chars, if needed */ 671 if (size == 0) break; /* END OF INPUT: BREAK FROM while LOOP! */ 672 673 if (size < 8) memset(input + size, 0, 8 - size); 674 675 /* Encrypt and output the block */ 676 des_ecb_encrypt(input, output, schedule, TRUE); 677 block_to_ascii(output, outfile); 678 679 if (size < 8) break; 680 } 681 682 /* Close out the output */ 683 if (!error) putc('\n', outfile); 684 if (zephyr) CloseZephyrPipe(outfile); 685 686 /* Free the input buffer, if necessary */ 687 if (freein && inbuff) owl_free(inbuff); 688 689 return(!error); 690 } 691 692 /* Read a half-byte from stdin, skipping invalid characters. Returns -1 693 if at EOF or file error */ 694 int read_ascii_nybble() { 695 char c; 696 697 while (TRUE) { 698 if (fread(&c, 1, 1, stdin) == 0) { 699 return(-1); 700 } else if (c >= BASE_CODE && c <= LAST_CODE) { 701 return(c - BASE_CODE); 702 } 703 } 704 } 705 706 /* Read both halves of the byte and return the single byte. Returns -1 707 if at EOF or file error. */ 708 int read_ascii_byte() { 709 int c1, c2; 710 c1 = read_ascii_nybble(); 711 if (c1 >= 0) { 712 c2 = read_ascii_nybble(); 713 if (c2 >= 0) { 714 return c1 * 0x10 + c2; 715 } 716 } 717 return(-1); 718 } 719 720 /* Read an 8-byte DES block from stdin */ 721 int read_ascii_block(char *input) { 722 int c, i; 723 724 for (i = 0; i < 8; i++) { 725 c = read_ascii_byte(); 726 if (c < 0) return(FALSE); 727 input[i] = c; 728 } 729 730 return(TRUE); 731 } 732 733 /* Decrypt stdin */ 734 int do_decrypt(char *keystring) { 735 des_cblock key; 736 des_key_schedule schedule; 737 char input[8], output[9]; 738 739 output[0] = '\0'; /* In case no message at all */ 740 output[8] = '\0'; /* NULL at end will limit string length to 8 */ 741 742 des_string_to_key(keystring, key); 743 des_key_sched(key, schedule); 744 745 while (read_ascii_block(input)) { 746 des_ecb_encrypt(input, output, schedule, FALSE); 747 printf("%s", output); 748 } 749 750 if (output[0]) { 751 if (output[strlen(output)-1] != '\n') { 752 printf("\n"); 753 } 754 } else { 755 printf("\n"); 756 } 757 return(0); 758 } 759 760 #endif 277 #endif -
zephyr.c
r451db9e re2a620b 516 516 } 517 517 /* deal with MIT Discuss messages */ 518 else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4")) { 518 else if (!strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3 ($5)\nSubject: $4") || 519 !strcasecmp(n->z_default_format, "New transaction [$1] entered in $2\nFrom: $3\nSubject: $4")) { 519 520 char *msg, *field1, *field2, *field3, *field4, *field5; 520 521 … … 814 815 ZGetLocations(&locations,&one); 815 816 myuser=short_zuser(user); 816 sprintf(out , "%s%s: %s\t%s\t%s\n", out, myuser,817 sprintf(out + strlen(out), "%s: %s\t%s\t%s\n", myuser, 817 818 locations.host ? locations.host : "?", 818 819 locations.tty ? locations.tty : "?", … … 1203 1204 1204 1205 #ifdef HAVE_LIBZEPHYR 1205 void owl_zephyr_process_events( ) {1206 void owl_zephyr_process_events(owl_dispatch *d) { 1206 1207 int zpendcount=0; 1207 1208 ZNotice_t notice; … … 1235 1236 1236 1237 #else 1237 void owl_zephyr_process_events( ) {1238 1239 } 1240 #endif 1238 void owl_zephyr_process_events(owl_dispatch *d) { 1239 1240 } 1241 #endif -
zwrite.c
r3f3ee61 r823671c 195 195 { 196 196 int i, j; 197 char to[LINE];197 char *to; 198 198 199 199 if (z->noping) return; … … 209 209 for (i=0; i<j; i++) { 210 210 if (strcmp(z->realm, "")) { 211 sprintf(to,"%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);211 to = owl_sprintf("%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm); 212 212 } else { 213 strcpy(to,owl_list_get_element(&(z->recips), i));213 to = owl_strdup(owl_list_get_element(&(z->recips), i)); 214 214 } 215 215 send_ping(to); 216 owl_free(to); 216 217 } 217 218 … … 221 222 { 222 223 int i, j; 223 char toline[LINE];224 char *toline = NULL; 224 225 char *tmp = NULL; 225 226 … … 228 229 j=owl_list_get_size(&(z->recips)); 229 230 if (j>0 && z->cc) { 230 strcpy(toline,"CC: ");231 toline = owl_strdup( "CC: "); 231 232 for (i=0; i<j; i++) { 233 tmp = toline; 232 234 if (strcmp(z->realm, "")) { 233 sprintf(toline,"%s%s@%s ", toline, (char *) owl_list_get_element(&(z->recips), i), z->realm);235 toline = owl_sprintf( "%s%s@%s ", toline, (char *) owl_list_get_element(&(z->recips), i), z->realm); 234 236 } else { 235 sprintf(toline, "%s%s ", toline, (char *) owl_list_get_element(&(z->recips), i)); 236 } 237 toline = owl_sprintf( "%s%s ", toline, (char *) owl_list_get_element(&(z->recips), i)); 238 } 239 owl_free(tmp); 240 tmp = NULL; 237 241 } 238 242 tmp = owl_get_iso_8859_1_if_possible(msg); 239 243 z->message=owl_sprintf("%s\n%s", toline, tmp); 244 owl_free(toline); 240 245 } else { 241 246 z->message=owl_get_iso_8859_1_if_possible(msg); … … 259 264 { 260 265 int i, j; 261 char to[LINE];266 char *to = NULL; 262 267 263 268 if (z->message==NULL) return(-1); … … 267 272 for (i=0; i<j; i++) { 268 273 if (strcmp(z->realm, "")) { 269 sprintf(to,"%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);274 to = owl_sprintf("%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm); 270 275 } else { 271 strcpy(to,owl_list_get_element(&(z->recips), i));276 to = owl_strdup( owl_list_get_element(&(z->recips), i)); 272 277 } 273 278 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message); 279 owl_free(to); 280 to = NULL; 274 281 } 275 282 } else { 276 sprintf(to,"@%s", z->realm);283 to = owl_sprintf( "@%s", z->realm); 277 284 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message); 278 285 } 286 owl_free(to); 279 287 return(0); 280 288 } -
.gitignore
r6b7e7a5 r8d07892a 23 23 varstubs.c 24 24 *~ 25 libfaim/rxhandlers.c.orig
Note: See TracChangeset
for help on using the changeset viewer.