#include #include #include #include #include #include #include #include "owl.h" static const char fileIdent[] = "$Id$"; void owl_function_noop(void) { return; } char *owl_function_command(char *cmdbuff) { owl_function_debugmsg("executing command: %s", cmdbuff); return owl_cmddict_execute(owl_global_get_cmddict(&g), owl_global_get_context(&g), cmdbuff); } void owl_function_command_norv(char *cmdbuff) { char *rv; rv = owl_function_command(cmdbuff); if (rv) owl_free(rv); } void owl_function_command_alias(char *alias_from, char *alias_to) { owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to); } owl_cmd *owl_function_get_cmd(char *name) { return owl_cmddict_find(owl_global_get_cmddict(&g), name); } void owl_function_show_commands() { owl_list l; owl_fmtext fm; owl_fmtext_init_null(&fm); owl_fmtext_append_bold(&fm, "Commands: "); owl_fmtext_append_normal(&fm, "(use 'show command ' for details)\n"); owl_cmddict_get_names(owl_global_get_cmddict(&g), &l); owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe); owl_fmtext_append_normal(&fm, "\n"); owl_function_popless_fmtext(&fm); owl_cmddict_namelist_free(&l); owl_fmtext_free(&fm); } char *owl_function_cmd_describe(void *name) { owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name); if (cmd) return owl_cmd_describe(cmd); else return(NULL); } void owl_function_show_command(char *name) { owl_function_help_for_command(name); } void owl_function_adminmsg(char *header, char *body) { owl_message *m; int followlast; followlast=owl_global_should_followlast(&g); m=owl_malloc(sizeof(owl_message)); owl_message_create_admin(m, header, body); owl_messagelist_append_element(owl_global_get_msglist(&g), m); owl_view_consider_message(owl_global_get_current_view(&g), m); if (followlast) owl_function_lastmsg_noredisplay(); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); if (owl_popwin_is_active(owl_global_get_popwin(&g))) { owl_popwin_refresh(owl_global_get_popwin(&g)); } wnoutrefresh(owl_global_get_curs_recwin(&g)); owl_global_set_needrefresh(&g); } void owl_function_adminmsg_outgoing(char *header, char *body, char *zwriteline) { owl_message *m; int followlast; followlast=owl_global_should_followlast(&g); m=owl_malloc(sizeof(owl_message)); owl_message_create_admin(m, header, body); owl_message_set_admin_outgoing(m, zwriteline); owl_messagelist_append_element(owl_global_get_msglist(&g), m); owl_view_consider_message(owl_global_get_current_view(&g), m); if (followlast) owl_function_lastmsg_noredisplay(); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); if (owl_popwin_is_active(owl_global_get_popwin(&g))) { owl_popwin_refresh(owl_global_get_popwin(&g)); } wnoutrefresh(owl_global_get_curs_recwin(&g)); owl_global_set_needrefresh(&g); } void owl_function_zwrite_setup(char *line) { owl_editwin *e; char buff[1024]; owl_zwrite z; int ret; /* check the arguments */ ret=owl_zwrite_create_from_line(&z, line); if (ret) { owl_function_makemsg("Error in zwrite arugments"); owl_zwrite_free(&z); return; } /* send a ping if necessary */ if (owl_global_is_txping(&g)) { owl_zwrite_send_ping(&z); } owl_zwrite_free(&z); /* create and setup the editwin */ e=owl_global_get_typwin(&g); owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE); if (!owl_global_is_lockout_ctrld(&g)) { owl_function_makemsg("Type your zephyr below. End with ^D or a dot on a line by itself. ^C will quit."); } else { owl_function_makemsg("Type your zephyr below. End with a dot on a line by itself. ^C will quit."); } owl_editwin_clear(e); owl_editwin_set_dotsend(e); strcpy(buff, "----> "); strcat(buff, line); strcat(buff, "\n"); owl_editwin_set_locktext(e, buff); /* make it active */ owl_global_set_typwin_active(&g); } void owl_function_zwrite(char *line) { char *tmpbuff, buff[1024]; owl_zwrite z; int i, j; /* create the zwrite and send the message */ owl_zwrite_create_from_line(&z, line); owl_zwrite_send_message(&z, owl_editwin_get_text(owl_global_get_typwin(&g))); owl_function_makemsg("Waiting for ack..."); /* display the message as an admin message in the receive window */ if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) { tmpbuff=owl_malloc(strlen(owl_editwin_get_text(owl_global_get_typwin(&g)))+1024); owl_zwrite_get_recipstr(&z, buff); sprintf(tmpbuff, "Message sent to %s", buff); owl_function_adminmsg_outgoing(tmpbuff, owl_editwin_get_text(owl_global_get_typwin(&g)), line); owl_free(tmpbuff); } /* log it if we have logging turned on */ if (owl_global_is_logging(&g) && owl_zwrite_is_personal(&z)) { j=owl_zwrite_get_numrecips(&z); for (i=0; iviewsize-1) curmsg=viewsize-1; if (curmsg<0) curmsg=0; for (i=curmsg+1; iowl_view_get_size(v)-1) i=owl_view_get_size(v)-1; if (!found) { owl_function_makemsg("already at last%s message%s%s", skip_deleted?" non-deleted":"", filter?" in ":"", filter?filter:""); if (!skip_deleted) owl_function_beep(); } if (last_if_none || found) { owl_global_set_curmsg(&g, i); owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_direction_downwards(&g); } } void owl_function_prevmsg_full(char *filter, int skip_deleted, int first_if_none) { int curmsg, i, viewsize, found; owl_view *v; owl_filter *f = NULL; owl_message *m; v=owl_global_get_current_view(&g); if (filter) { f=owl_global_get_filter(&g, filter); if (!f) { owl_function_makemsg("No %s filter defined", filter); return; } } curmsg=owl_global_get_curmsg(&g); viewsize=owl_view_get_size(v); found=0; /* just check to make sure we're in bounds... */ if (curmsg>viewsize-1) curmsg=viewsize-1; if (curmsg<0) curmsg=0; for (i=curmsg-1; i>=0; i--) { m=owl_view_get_element(v, i); if (skip_deleted && owl_message_is_delete(m)) continue; if (f && !owl_filter_message_match(f, m)) continue; found = 1; break; } if (i<0) i=0; if (!found) { owl_function_makemsg("already at first%s message%s%s", skip_deleted?" non-deleted":"", filter?" in ":"", filter?filter:""); if (!skip_deleted) owl_function_beep(); } if (first_if_none || found) { owl_global_set_curmsg(&g, i); owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_direction_upwards(&g); } } void owl_function_nextmsg() { owl_function_nextmsg_full(NULL, 0, 1); } void owl_function_prevmsg() { owl_function_prevmsg_full(NULL, 0, 1); } void owl_function_nextmsg_notdeleted() { owl_function_nextmsg_full(NULL, 1, 1); } void owl_function_prevmsg_notdeleted() { owl_function_prevmsg_full(NULL, 1, 1); } void owl_function_nextmsg_personal() { owl_function_nextmsg_full("personal", 0, 0); } void owl_function_prevmsg_personal() { owl_function_prevmsg_full("personal", 0, 0); } /* if move_after is 1, moves after the delete */ void owl_function_deletecur(int move_after) { int curmsg; owl_view *v; v=owl_global_get_current_view(&g); /* bail if there's no current message */ if (owl_view_get_size(v) < 1) { owl_function_makemsg("No current message to delete"); return; } /* mark the message for deletion */ curmsg=owl_global_get_curmsg(&g); owl_view_delete_element(v, curmsg); if (move_after) { /* move the poiner in the appropriate direction * to the next undeleted msg */ if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { owl_function_prevmsg_notdeleted(); } else { owl_function_nextmsg_notdeleted(); } } } void owl_function_undeletecur(int move_after) { int curmsg; owl_view *v; v=owl_global_get_current_view(&g); if (owl_view_get_size(v) < 1) { owl_function_makemsg("No current message to undelete"); return; } curmsg=owl_global_get_curmsg(&g); owl_view_undelete_element(v, curmsg); if (move_after) { if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { if (curmsg>0) { owl_function_prevmsg(); } else { owl_function_nextmsg(); } } else { owl_function_nextmsg(); } } owl_mainwin_redisplay(owl_global_get_mainwin(&g)); } void owl_function_expunge() { int curmsg; owl_message *m; owl_messagelist *ml; owl_view *v; int i, j; curmsg=owl_global_get_curmsg(&g); v=owl_global_get_current_view(&g); ml=owl_global_get_msglist(&g); /* first try to move to an undeleted message in the view*/ m=owl_view_get_element(v, curmsg); if (owl_message_is_delete(m)) { /* try to find the next undeleted message */ j=owl_view_get_size(v); for (i=curmsg; i0; i--) { if (!owl_message_is_delete(owl_view_get_element(v, i))) { owl_global_set_curmsg(&g, i); break; } } } } /* expunge the message list */ owl_messagelist_expunge(ml); /* update all views (we only have one right now) */ owl_view_recalculate(v); if (curmsg>owl_view_get_size(v)-1) { owl_global_set_curmsg(&g, owl_view_get_size(v)-1); if (owl_global_get_curmsg(&g)<0) { owl_global_set_curmsg(&g, 0); } owl_function_calculate_topmsg(OWL_DIRECTION_NONE); } /* if there are no messages set the direction to down in case we delete everything upwards */ owl_global_set_direction_downwards(&g); owl_function_makemsg("Messages expunged"); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); } void owl_function_firstmsg() { owl_global_set_curmsg(&g, 0); owl_global_set_topmsg(&g, 0); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_direction_downwards(&g); } void owl_function_lastmsg_noredisplay() { int curmsg; owl_view *v; v=owl_global_get_current_view(&g); curmsg=owl_view_get_size(v)-1; if (curmsg<0) curmsg=0; owl_global_set_curmsg(&g, curmsg); owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_direction_downwards(&g); } void owl_function_lastmsg() { owl_function_lastmsg_noredisplay(); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); } void owl_function_shift_right() { owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_needrefresh(&g); } void owl_function_shift_left() { int shift; shift=owl_global_get_rightshift(&g); if (shift>=10) { owl_global_set_rightshift(&g, shift-10); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_needrefresh(&g); } else { owl_function_beep(); owl_function_makemsg("Already full left"); } } void owl_function_unsuball() { unsuball(); owl_function_makemsg("Unsubscribed from all messages."); } void owl_function_loadsubs(char *file) { int ret; ret=owl_zephyr_loadsubs(file); if (ret==0) { owl_function_makemsg("Subscribed to messages from file."); } else if (ret==-1) { owl_function_makemsg("Could not open file."); } else { owl_function_makemsg("Error subscribing to messages from file."); } } void owl_function_suspend() { endwin(); printf("\n"); kill(getpid(), SIGSTOP); /* resize to reinitialize all the windows when we come back */ owl_command_resize(); } void owl_function_zaway_toggle() { if (!owl_global_is_zaway(&g)) { owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g)); owl_function_zaway_on(); } else { owl_function_zaway_off(); } } void owl_function_zaway_on() { owl_global_set_zaway_on(&g); owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g)); } void owl_function_zaway_off() { owl_global_set_zaway_off(&g); owl_function_makemsg("zaway off"); } void owl_function_quit() { char *ret; /* zlog out if we need to */ if (owl_global_is_shutdownlogout(&g)) { owl_function_zlog_out(); } /* execute the commands in shutdown */ ret = owl_config_execute("owl::shutdown();"); if (ret) owl_free(ret); /* final clean up */ unsuball(); ZClosePort(); endwin(); owl_function_debugmsg("Quitting Owl"); exit(0); } void owl_function_zlog_in() { char *exposure, *eset; int ret; eset=EXPOSE_REALMVIS; exposure=ZGetVariable("exposure"); if (exposure==NULL) { eset=EXPOSE_REALMVIS; } else if (!strcasecmp(exposure,EXPOSE_NONE)) { eset = EXPOSE_NONE; } else if (!strcasecmp(exposure,EXPOSE_OPSTAFF)) { eset = EXPOSE_OPSTAFF; } else if (!strcasecmp(exposure,EXPOSE_REALMVIS)) { eset = EXPOSE_REALMVIS; } else if (!strcasecmp(exposure,EXPOSE_REALMANN)) { eset = EXPOSE_REALMANN; } else if (!strcasecmp(exposure,EXPOSE_NETVIS)) { eset = EXPOSE_NETVIS; } else if (!strcasecmp(exposure,EXPOSE_NETANN)) { eset = EXPOSE_NETANN; } ret=ZSetLocation(eset); if (ret != ZERR_NONE) { /* char buff[LINE]; sprintf(buff, "Error setting location: %s", error_message(ret)); owl_function_makemsg(buff); */ } } void owl_function_zlog_out() { int ret; ret=ZUnsetLocation(); if (ret != ZERR_NONE) { /* char buff[LINE]; sprintf(buff, "Error unsetting location: %s", error_message(ret)); owl_function_makemsg(buff); */ } } void owl_function_makemsg(char *fmt, ...) { va_list ap; char buff[2048]; va_start(ap, fmt); werase(owl_global_get_curs_msgwin(&g)); vsnprintf(buff, 2048, fmt, ap); owl_function_debugmsg("makemsg: %s", buff); waddstr(owl_global_get_curs_msgwin(&g), buff); wnoutrefresh(owl_global_get_curs_msgwin(&g)); owl_global_set_needrefresh(&g); va_end(ap); } void owl_function_errormsg(char *fmt, ...) { va_list ap; char buff[2048]; va_start(ap, fmt); werase(owl_global_get_curs_msgwin(&g)); vsnprintf(buff, 2048, fmt, ap); owl_function_debugmsg("ERROR: %s", buff); waddstr(owl_global_get_curs_msgwin(&g), buff); waddstr(owl_global_get_curs_msgwin(&g), "ERROR: "); wnoutrefresh(owl_global_get_curs_msgwin(&g)); owl_global_set_needrefresh(&g); va_end(ap); } void owl_function_openurl() { /* visit the first url in the current message */ owl_message *m; owl_view *v; char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE]; int webbrowser; webbrowser = owl_global_get_webbrowser(&g); if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) { owl_function_makemsg("No browser selected"); return; } v=owl_global_get_current_view(&g); if (owl_view_get_size(v)==0) { owl_function_makemsg("No current message selected"); return; } m=owl_view_get_element(v, owl_global_get_curmsg(&g)); text=owl_message_get_text(m); /* First look for a good URL */ if ((ptr1=strstr(text, "http://"))!=NULL) { ptr2=strpbrk(ptr1, " \n\t"); if (ptr2) { strncpy(url, ptr1, ptr2-ptr1+1); url[ptr2-ptr1+1]='\0'; } else { strcpy(url, ptr1); } /* if we had */ if (ptr1>text && ptr1[-1]=='<') { if (url[strlen(url)-1]=='>') { url[strlen(url)-1]='\0'; } } } else if ((ptr1=strstr(text, "https://"))!=NULL) { /* Look for an https URL */ ptr2=strpbrk(ptr1, " \n\t"); if (ptr2) { strncpy(url, ptr1, ptr2-ptr1+1); url[ptr2-ptr1+1]='\0'; } else { strcpy(url, ptr1); } /* if we had */ if (ptr1>text && ptr1[-1]=='<') { if (url[strlen(url)-1]=='>') { url[strlen(url)-1]='\0'; } } } else if ((ptr1=strstr(text, "www."))!=NULL) { /* if we can't find a real url look for www.something */ ptr2=strpbrk(ptr1, " \n\t"); if (ptr2) { strncpy(url, ptr1, ptr2-ptr1+1); url[ptr2-ptr1+1]='\0'; } else { strcpy(url, ptr1); } } else { owl_function_beep(); owl_function_makemsg("Could not find URL to open."); return; } /* Make sure there aren't any quotes or \'s in the url */ for (ptr1 = url; *ptr1; ptr1++) { if (*ptr1 == '"' || *ptr1 == '\\') { owl_function_beep(); owl_function_makemsg("URL contains invalid characters."); return; } } /* NOTE: There are potentially serious security issues here... */ /* open the page */ owl_function_makemsg("Opening %s", url); if (webbrowser == OWL_WEBBROWSER_NETSCAPE) { snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url); system(tmpbuff); } else if (webbrowser == OWL_WEBBROWSER_GALEON) { snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url); system(tmpbuff); } } void owl_function_calculate_topmsg(int direction) { int recwinlines, y, savey, i, j, topmsg, curmsg, foo; owl_mainwin *mw; owl_view *v; mw=owl_global_get_mainwin(&g); topmsg=owl_global_get_topmsg(&g); curmsg=owl_global_get_curmsg(&g); v=owl_global_get_current_view(&g); recwinlines=owl_global_get_recwin_lines(&g); if (owl_view_get_size(v) < 1) { return; } /* Find number of lines from top to bottom of curmsg (store in savey) */ savey=0; for (i=topmsg; i<=curmsg; i++) { savey+=owl_message_get_numlines(owl_view_get_element(v, i)); } /* If the direction is DOWNWARDS but we're off the bottom of the * screen, then set the topmsg to curmsg and scroll UPWARDS */ if (direction == OWL_DIRECTION_DOWNWARDS) { if (savey > recwinlines) { topmsg=curmsg; savey=owl_message_get_numlines(owl_view_get_element(v, curmsg)); direction=OWL_DIRECTION_UPWARDS; } } /* If our bottom line is less than 1/4 down the screen then scroll up */ if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) { if (savey < (recwinlines / 4)) { y=0; for (j=curmsg; j>=0; j--) { foo=owl_message_get_numlines(owl_view_get_element(v, j)); /* will we run the curmsg off the screen? */ if ((foo+y) >= recwinlines) { j++; if (j>curmsg) j=curmsg; break; } /* have saved 1/2 the screen space? */ y+=foo; if (y > (recwinlines / 2)) break; } if (j<0) j=0; owl_global_set_topmsg(&g, j); return; } } if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) { /* If curmsg bottom line is more than 3/4 down the screen then scroll down */ if (savey > ((recwinlines * 3)/4)) { y=0; /* count lines from the top until we can save 1/2 the screen size */ for (j=topmsg; j (recwinlines / 2)) break; } if (j==curmsg) { j--; } owl_global_set_topmsg(&g, j+1); return; } } } void owl_function_resize() { owl_global_set_resize_pending(&g); } void owl_function_run_buffercommand() { char *buff; buff=owl_global_get_buffercommand(&g); if (!strncmp(buff, "zwrite ", 7)) { owl_function_zwrite(buff); } } void owl_function_debugmsg(char *fmt, ...) { FILE *file; time_t now; char buff1[LINE], buff2[LINE]; va_list ap; va_start(ap, fmt); if (!owl_global_is_debug_fast(&g)) return; file=fopen(owl_global_get_debug_file(&g), "a"); if (!file) return; now=time(NULL); strcpy(buff1, ctime(&now)); buff1[strlen(buff1)-1]='\0'; owl_global_get_runtime_string(&g, buff2); fprintf(file, "[%i - %s - %s]: ", (int) getpid(), buff1, buff2); vfprintf(file, fmt, ap); fprintf(file, "\n"); fclose(file); va_end(ap); } void owl_function_refresh() { owl_function_resize(); } void owl_function_beep() { if (owl_global_is_bell(&g)) { beep(); } } void owl_function_subscribe(char *class, char *inst, char *recip) { int ret; ret=owl_zephyr_sub(class, inst, recip); if (ret) { owl_function_makemsg("Error subscribing."); } else { owl_function_makemsg("Subscribed."); } } void owl_function_unsubscribe(char *class, char *inst, char *recip) { int ret; ret=owl_zephyr_unsub(class, inst, recip); if (ret) { owl_function_makemsg("Error subscribing."); } else { owl_function_makemsg("Unsubscribed."); } } void owl_function_set_cursor(WINDOW *win) { wnoutrefresh(win); } void owl_function_full_redisplay() { redrawwin(owl_global_get_curs_recwin(&g)); redrawwin(owl_global_get_curs_sepwin(&g)); redrawwin(owl_global_get_curs_typwin(&g)); redrawwin(owl_global_get_curs_msgwin(&g)); wnoutrefresh(owl_global_get_curs_recwin(&g)); wnoutrefresh(owl_global_get_curs_sepwin(&g)); wnoutrefresh(owl_global_get_curs_typwin(&g)); wnoutrefresh(owl_global_get_curs_msgwin(&g)); sepbar(""); owl_function_makemsg(""); owl_global_set_needrefresh(&g); } void owl_function_popless_text(char *text) { owl_popwin *pw; owl_viewwin *v; pw=owl_global_get_popwin(&g); v=owl_global_get_viewwin(&g); owl_popwin_up(pw); owl_viewwin_init_text(v, owl_popwin_get_curswin(pw), owl_popwin_get_lines(pw), owl_popwin_get_cols(pw), text); owl_popwin_refresh(pw); owl_viewwin_redisplay(v, 0); owl_global_set_needrefresh(&g); } void owl_function_popless_fmtext(owl_fmtext *fm) { owl_popwin *pw; owl_viewwin *v; pw=owl_global_get_popwin(&g); v=owl_global_get_viewwin(&g); owl_popwin_up(pw); owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw), owl_popwin_get_lines(pw), owl_popwin_get_cols(pw), fm); owl_popwin_refresh(pw); owl_viewwin_redisplay(v, 0); owl_global_set_needrefresh(&g); } void owl_function_about() { char buff[5000]; sprintf(buff, "This is owl version %s\n", OWL_VERSION_STRING); strcat(buff, "\nOwl was written by James Kretchmar at the Massachusetts\n"); strcat(buff, "Institute of Technology. The first version, 0.5, was\n"); strcat(buff, "released in March 2002\n"); strcat(buff, "\n"); strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n"); strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n"); strcat(buff, "between Witches and Wizards.\n"); strcat(buff, "\n"); strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n"); strcat(buff, "\n"); strcat(buff, "Permission to use, copy, modify, and distribute this\n"); strcat(buff, "software and its documentation for any purpose and without\n"); strcat(buff, "fee is hereby granted, provided that the above copyright\n"); strcat(buff, "notice and this permission notice appear in all copies\n"); strcat(buff, "and in supporting documentation. No representation is\n"); strcat(buff, "made about the suitability of this software for any\n"); strcat(buff, "purpose. It is provided \"as is\" without express\n"); strcat(buff, "or implied warranty.\n"); owl_function_popless_text(buff); } void owl_function_info() { owl_message *m; ZNotice_t *n; char buff[2048], tmpbuff[1024]; char *ptr; int i, j, fields, len; owl_view *v; v=owl_global_get_current_view(&g); if (owl_view_get_size(v)==0) { owl_function_makemsg("No message selected\n"); return; } m=owl_view_get_element(v, owl_global_get_curmsg(&g)); if (!owl_message_is_zephyr(m)) { sprintf(buff, "Owl Message Id: %i\n", owl_message_get_id(m)); sprintf(buff, "%sTime : %s\n", buff, owl_message_get_timestr(m)); owl_function_popless_text(buff); return; } n=owl_message_get_notice(m); sprintf(buff, "Owl Msg ID: %i\n", owl_message_get_id(m)); sprintf(buff, "%sClass : %s\n", buff, n->z_class); sprintf(buff, "%sInstance : %s\n", buff, n->z_class_inst); sprintf(buff, "%sSender : %s\n", buff, n->z_sender); sprintf(buff, "%sRecip : %s\n", buff, n->z_recipient); sprintf(buff, "%sOpcode : %s\n", buff, n->z_opcode); strcat(buff, "Kind : "); if (n->z_kind==UNSAFE) { strcat(buff, "UNSAFE\n"); } else if (n->z_kind==UNACKED) { strcat(buff, "UNACKED\n"); } else if (n->z_kind==ACKED) { strcat(buff, "ACKED\n"); } else if (n->z_kind==HMACK) { strcat(buff, "HMACK\n"); } else if (n->z_kind==HMCTL) { strcat(buff, "HMCTL\n"); } else if (n->z_kind==SERVACK) { strcat(buff, "SERVACK\n"); } else if (n->z_kind==SERVNAK) { strcat(buff, "SERVNAK\n"); } else if (n->z_kind==CLIENTACK) { strcat(buff, "CLIENTACK\n"); } else if (n->z_kind==STAT) { strcat(buff, "STAT\n"); } else { strcat(buff, "ILLEGAL VALUE\n"); } sprintf(buff, "%sTime : %s\n", buff, owl_message_get_timestr(m)); sprintf(buff, "%sHost : %s\n", buff, owl_message_get_hostname(m)); sprintf(buff, "%sPort : %i\n", buff, n->z_port); strcat(buff, "Auth : "); if (n->z_auth == ZAUTH_FAILED) { strcat(buff, "FAILED\n"); } else if (n->z_auth == ZAUTH_NO) { strcat(buff, "NO\n"); } else if (n->z_auth == ZAUTH_YES) { strcat(buff, "YES\n"); } else { sprintf(buff, "%sUnknown State (%i)\n", buff, n->z_auth); } sprintf(buff, "%sCheckd Ath: %i\n", buff, n->z_checked_auth); sprintf(buff, "%sMulti notc: %s\n", buff, n->z_multinotice); sprintf(buff, "%sNum other : %i\n", buff, n->z_num_other_fields); sprintf(buff, "%sMsg Len : %i\n", buff, n->z_message_len); sprintf(buff, "%sFields : %i\n", buff, owl_zephyr_get_num_fields(n)); fields=owl_zephyr_get_num_fields(n); for (i=0; iz_default_format); owl_function_popless_text(buff); } void owl_function_curmsg_to_popwin() { owl_popwin *pw; owl_view *v; owl_message *m; v = owl_global_get_current_view(&g); pw=owl_global_get_popwin(&g); if (owl_view_get_size(v)==0) { owl_function_makemsg("No current message"); return; } m=owl_view_get_element(v, owl_global_get_curmsg(&g)); owl_function_popless_fmtext(owl_message_get_fmtext(m)); } void owl_function_page_curmsg(int step) { /* scroll down or up within the current message IF the message is truncated */ int offset, curmsg, lines; owl_view *v; owl_message *m; offset=owl_global_get_curmsg_vert_offset(&g); v=owl_global_get_current_view(&g); if (owl_view_get_size(v)==0) return; curmsg=owl_global_get_curmsg(&g); m=owl_view_get_element(v, curmsg); lines=owl_message_get_numlines(m); if (offset==0) { /* Bail if the curmsg isn't the last one displayed */ if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) { owl_function_makemsg("The entire message is already displayed"); return; } /* Bail if we're not truncated */ if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) { owl_function_makemsg("The entire message is already displayed"); return; } } /* don't scroll past the last line */ if (step>0) { if (offset+step > lines-1) { owl_global_set_curmsg_vert_offset(&g, lines-1); } else { owl_global_set_curmsg_vert_offset(&g, offset+step); } } /* would we be before the beginning of the message? */ if (step<0) { if (offset+step<0) { owl_global_set_curmsg_vert_offset(&g, 0); } else { owl_global_set_curmsg_vert_offset(&g, offset+step); } } /* redisplay */ owl_mainwin_redisplay(owl_global_get_mainwin(&g)); owl_global_set_needrefresh(&g); } void owl_function_resize_typwin(int newsize) { owl_global_set_typwin_lines(&g, newsize); owl_function_resize(); } void owl_function_typwin_grow() { int i; i=owl_global_get_typwin_lines(&g); owl_function_resize_typwin(i+1); } void owl_function_typwin_shrink() { int i; i=owl_global_get_typwin_lines(&g); if (i>2) { owl_function_resize_typwin(i-1); } } void owl_function_mainwin_pagedown() { int i; i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g)); if (i<0) return; owl_global_set_curmsg(&g, i); owl_function_nextmsg(); } void owl_function_mainwin_pageup() { owl_global_set_curmsg(&g, owl_global_get_topmsg(&g)); owl_function_prevmsg(); } void owl_function_getsubs() { int ret, num, i, one; ZSubscription_t sub; char *buff; one = 1; ret=ZRetrieveSubscriptions(0, &num); if (ret == ZERR_TOOMANYSUBS) { } buff=malloc(num*200); strcpy(buff, ""); for (i=0; i\n", buff, sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient); } } owl_function_popless_text(buff); free(buff); ZFlushSubscriptions(); } #define PABUFLEN 5000 void owl_function_printallvars() { char buff[PABUFLEN], *pos, *name; owl_list varnames; int i, numvarnames, rem; pos = buff; pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE"); pos += sprintf(pos, "%-20s %s\n", "--------", "-----"); owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); rem = (buff+PABUFLEN)-pos-1; numvarnames = owl_list_get_size(&varnames); for (i=0; i' for details)\n"); owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); owl_variable_get_summaryheader(&fm); numvarnames = owl_list_get_size(&varnames); for (i=0; i", mclass, minst); } else { cmdprefix = "start-command zpunt "; cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+3); strcpy(cmd, cmdprefix); strcat(cmd, mclass); if (type) { strcat(cmd, " "); strcat(cmd, minst); } else { strcat(cmd, " *"); } owl_function_command(cmd); owl_free(cmd); } } void owl_function_color_current_filter(char *color) { owl_filter *f; char *name; name=owl_view_get_filtname(owl_global_get_current_view(&g)); f=owl_global_get_filter(&g, name); if (!f) { owl_function_makemsg("Unknown filter"); return; } /* don't touch the all filter */ if (!strcmp(name, "all")) { owl_function_makemsg("You may not change the 'all' filter."); return; } /* deal with the case of trying change the filter color */ owl_filter_set_color(f, owl_util_string_to_color(color)); owl_global_set_needrefresh(&g); owl_mainwin_redisplay(owl_global_get_mainwin(&g)); } void owl_function_show_colors() { owl_fmtext fm; owl_fmtext_init_null(&fm); owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT); owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED); owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN); owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW); owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE); owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA); owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN); owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE); owl_function_popless_fmtext(&fm); owl_fmtext_free(&fm); } void owl_function_zpunt(char *class, char *inst, char *recip, int direction) { /* add the given class, inst, recip to the punt list for filtering. * if direction==0 then punt * if direction==1 then unpunt */ owl_filter *f; owl_list *fl; char *buff; int ret, i, j; fl=owl_global_get_puntlist(&g); /* first, create the filter */ f=malloc(sizeof(owl_filter)); buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100); if (!strcmp(recip, "*")) { sprintf(buff, "class ^%s$ and instance ^%s$", class, inst); } else { sprintf(buff, "class ^%s$ and instance ^%s$ and recipient %s", class, inst, recip); } owl_function_debugmsg("About to filter %s", buff); ret=owl_filter_init_fromstring(f, "punt-filter", buff); owl_free(buff); if (ret) { owl_function_makemsg("Error creating filter for zpunt"); owl_filter_free(f); return; } /* Check for an identical filter */ j=owl_list_get_size(fl); for (i=0; i' for details)\n"); owl_keyhandler_get_keymap_names(kh, &l); owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary); owl_fmtext_append_normal(&fm, "\n"); numkm = owl_list_get_size(&l); for (i=0; i