/*{{{ clean*/ void clean(int n) { m_setcursor(CS_BLOCK); m_pop(); m_flush(); m_ttyreset(); exit(n); }
/*{{{ clean*/ void clean(int n) { m_bitdestroy(EYE_BITMAP); m_setcursor(CS_BLOCK); m_pop(); m_flush(); m_ttyreset(); exit(n); }
int main(int argc, char *argv[]) { int slp = 0; ckmgrterm( *argv ); if (argc>1 && strcmp(argv[1],"-s")==0) slp++; m_setup(0); m_push(P_EVENT|P_FLAGS); get_size(&x, &y, &hsize, &vsize); rad = (vsize+hsize)>>6;/* size is the avg. of dims. / 32 */ vx = 5; /* constant horizontal velocity */ vy = 0; /* initial vertical velocity of zero */ x = rad + 1; y = rad + 1; bcolor = random()%24; m_bcolor(bcolor); while((lcolor = random()%24) == bcolor); m_linecolor(BIT_SRC,lcolor); m_fcolor(lcolor); m_clear(); m_circle(x,y,rad); for(;;) { x1 = x +vx; /* add velocity to x */ if (x1 > MAXX-rad || x1 < rad) { /* fix coords if over border */ vx *= -1; x1 += vx; } vy += ACC; /* accelerate vertical velocity */ y1 = y + vy; /* add velocity to y */ if (y1 > MAXY-rad || y1 < rad) { m_circle(x1,MAXY-rad,rad); vy = -vy * 95 /100; if (abs(vy) < ACC) { usleep(900000); } y1 += vy; } m_circle(x1,y1,rad); /* draw new position */ x = x1; /* reset x and y */ y = y1; m_flush(); if (slp) usleep(90000); } return 0; }
/* * Send output to stdout ( = modem) */ int dosend(char *text) { #ifdef HAVE_USLEEP /* 200 ms delay. */ usleep(200000); #endif /* Before we send anything, flush input buffer. */ m_flush(0); memset(inbuf, 0, sizeof(inbuf)); newline = "\r"; return output(text, stdout); }
/* * Run kermit. Used to do this in the main window, but newer * versions of kermit are too intelligent and just want a tty * for themselves or they won't function ok. Shame. */ void kermit(void) { int status, pid, n; char * translated_cmdline; char *kermit_path = P_KERMIT; if (!kermit_path || !*kermit_path) { werror("No kermit path defined!"); return; } /* Clear screen, set keyboard modes etc. */ mc_wleave(); switch (pid = fork()) { case -1: mc_wreturn(); werror(_("Out of memory: could not fork()")); return; case 0: /* Child */ close(portfd); /* Remove lockfile */ lockfile_remove(); for (n = 0; n < _NSIG; n++) signal(n, SIG_DFL); translated_cmdline = translate(P_KERMIT); if (translated_cmdline != NULL) { fastexec(translated_cmdline); free(translated_cmdline); } exit(1); default: /* Parent */ break; } m_wait(&status); /* Restore screen and keyboard modes */ mc_wreturn(); /* Re-create lockfile */ lockfile_create(); m_flush(portfd); port_init(); }
/*{{{ m_getmousepos*/ int m_getmousepos(int *x, int *y, int *b) { char line[MAXLINE]; _m_ttyset(); m_getinfo(G_MOUSE); m_flush(); fgets(line,sizeof(line),m_termin); if (*line<'0' || *line>'9') { strcpy(m_linebuf,line); fgets(line,sizeof(line),m_termin); m_sendme(m_linebuf); } _m_ttyreset(); return (sscanf(line,"%d %d %d",x,y,b)==3); }
/* this functions opens and configure the serial port */ void cfgport(void) { if ((portfd = open(cfg.port, O_RDWR)) == -1) { printFatal("Unable to open serial port"); } /* these functions, declared on sysdep1.c * configure the serial port * these functions are from minicom source */ m_savestate(portfd); m_setparms(portfd, cfg.baudrate, cfg.parity, cfg.databits, 1, 0); m_nohang(portfd); m_hupcl(portfd, 1); m_flush(portfd); }
/*{{{ main*/ int main(int argc, char *argv[]) { /*{{{ variables*/ int lx,ly,rx,ry,x,y,b, my_x, my_y, my_width, my_height, screen_width, screen_height, screen_depth, puiple, keypress; char evstr[10]; int ox=-1, oy=-1; /*}}} */ /*{{{ setup*/ ckmgrterm(argv[0]); m_setup(M_MODEOK); signal(SIGINT,clean); signal(SIGTERM,clean); m_ttyset(); m_push(P_ALL); m_setmode(M_ABS); m_setcursor(CS_INVIS); m_setevent(REDRAW, "|R\n"); m_setevent(RESHAPE, "|r\n"); m_setevent(MOVE, "|m\n"); m_flush(); /*}}} */ m_getwindowsize(&my_width,&my_height); m_getwindowposition(&my_x,&my_y); m_getscreensize(&screen_width,&screen_height,&screen_depth); mkeye(my_width/2,my_height,&puiple); redraw(my_width,my_height); do { m_flush(); switch (m_getevent(100,&keypress,evstr,sizeof(evstr))) { case EV_TIMEOUT: { int olx,oly,orx,ory; assert(m_getmousepos(&x,&y,&b)); if (x!=ox || y!=oy) { /*{{{ left eye*/ olx=lx; oly=ly; lx=30*(x-(my_x+my_width/4))/screen_width; ly=30*(y-(my_y+my_height/2))/screen_height; while (lx*lx+ly*ly>=25*25) { lx=(10*lx)/11; ly=(10*ly)/11; } lx=(puiple*lx)/10; ly=(puiple*ly)/10; /*}}} */ /*{{{ right eye*/ orx=rx; ory=ry; rx=30*(x-(my_x+(3*my_width)/4))/screen_width; ry=ly; while (rx*rx+ry*ry>=25*25) { rx=(10*rx)/11; ry=(10*ry)/11; } rx=(puiple*rx)/10; ry=(puiple*ry)/10; /*}}} */ if (ox!=-1) clr_puiple(my_width,my_height,puiple,olx,oly,orx,ory); set_puiple(my_width,my_height,puiple,lx,ly,rx,ry); } ox=x; oy=y; break; } case EV_KEYPRESS: break; case EV_EVENTSTR: { ox=-1; oy=-1; switch (*evstr) { case 'R': redraw(my_width,my_height); break; case 'r': { m_getwindowsize(&my_width,&my_height); m_getwindowposition(&my_x,&my_y); m_bitdestroy(EYE_BITMAP); m_bitdestroy(PUIPLE_BITMAP); mkeye(my_width/2,my_height,&puiple); redraw(my_width,my_height); break; } case 'm': m_getwindowposition(&my_x,&my_y); break; default: assert(0); } break; } default: assert(0); } } while (keypress!='q'); clean(0); return 255; }
/* * Open the terminal. * * \return -1 on error, 0 on success */ int open_term(int doinit, int show_win_on_error, int no_msgs) { struct stat stt; union { char bytes[128]; int kermit; } buf; int fd, n = 0; int pid; #ifdef HAVE_ERRNO_H int s_errno; #endif #ifdef USE_SOCKET #define SOCKET_PREFIX "unix#" portfd_is_socket = portfd_is_connected = 0; if (strncmp(dial_tty, SOCKET_PREFIX, strlen(SOCKET_PREFIX)) == 0) { portfd_is_socket = 1; } #endif if (portfd_is_socket) goto nolock; #if !HAVE_LOCKDEV /* First see if the lock file directory is present. */ if (P_LOCK[0] && stat(P_LOCK, &stt) == 0) { #ifdef SVR4_LOCKS stat(dial_tty, &stt); sprintf(lockfile, "%s/LK.%03d.%03d.%03d", P_LOCK, major(stt.st_dev), major(stt.st_rdev), minor(stt.st_rdev)); #else /* SVR4_LOCKS */ snprintf(lockfile, sizeof(lockfile), "%s/LCK..%s", P_LOCK, mdevlockname(dial_tty, buf.bytes, sizeof(buf.bytes))); #endif /* SVR4_LOCKS */ } else lockfile[0] = 0; if (doinit > 0 && lockfile[0] && (fd = open(lockfile, O_RDONLY)) >= 0) { n = read(fd, buf.bytes, 127); close(fd); if (n > 0) { pid = -1; if (n == 4) /* Kermit-style lockfile. */ pid = buf.kermit; else { /* Ascii lockfile. */ buf.bytes[n] = 0; sscanf(buf.bytes, "%d", &pid); } if (pid > 0 && kill((pid_t)pid, 0) < 0 && errno == ESRCH) { fprintf(stderr, _("Lockfile is stale. Overriding it..\n")); sleep(1); unlink(lockfile); } else n = 0; } if (n == 0) { if (stdwin) mc_wclose(stdwin, 1); fprintf(stderr, _("Device %s is locked.\n"), dial_tty); return -1; } } #endif if (doinit > 0 && lockfile_create(no_msgs) != 0) return -1; nolock: /* Run a special program to disable callin if needed. */ if (doinit > 0 && P_CALLOUT[0]) { if (fastsystem(P_CALLOUT, NULL, NULL, NULL) < 0) { if (stdwin) mc_wclose(stdwin, 1); fprintf(stderr, _("Could not setup for dial out.\n")); lockfile_remove(); return -1; } } /* Now open the tty device. */ if (setjmp(albuf) == 0) { portfd = -1; signal(SIGALRM, get_alrm); alarm(20); #ifdef USE_SOCKET if (portfd_is_socket) { portfd_sock_addr.sun_family = AF_UNIX; strncpy(portfd_sock_addr.sun_path, dial_tty + strlen(SOCKET_PREFIX), sizeof(portfd_sock_addr.sun_path)-1); portfd_sock_addr.sun_path[sizeof(portfd_sock_addr.sun_path)-1] = 0; term_socket_connect(); } #endif /* USE_SOCKET */ if (!portfd_is_socket) { #if defined(O_NDELAY) && defined(F_SETFL) portfd = open(dial_tty, O_RDWR|O_NDELAY|O_NOCTTY); if (portfd >= 0) { /* Cancel the O_NDELAY flag. */ n = fcntl(portfd, F_GETFL, 0); fcntl(portfd, F_SETFL, n & ~O_NDELAY); } #else if (portfd < 0) portfd = open(dial_tty, O_RDWR|O_NOCTTY); #endif } if (portfd >= 0) { if (doinit > 0) m_savestate(portfd); port_init(); } } #ifdef HAVE_ERRNO_H s_errno = errno; #endif alarm(0); signal(SIGALRM, SIG_IGN); if (portfd < 0 && !portfd_is_socket) { if (!no_msgs) { if (doinit > 0) { if (stdwin) mc_wclose(stdwin, 1); #ifdef HAVE_ERRNO_H fprintf(stderr, _("minicom: cannot open %s: %s\n"), dial_tty, strerror(s_errno)); #else fprintf(stderr, _("minicom: cannot open %s. Sorry.\n"), dial_tty); #endif lockfile_remove(); return -1; } if (show_win_on_error) werror(_("Cannot open %s!"), dial_tty); } lockfile_remove(); return -1; } /* Set CLOCAL mode */ m_nohang(portfd); /* Set Hangup on Close if program crashes. (Hehe) */ m_hupcl(portfd, 1); if (doinit > 0) m_flush(portfd); return 0; }
/*{{{ main*/ int main(int argc, char *argv[]) { /*{{{ variables*/ enum { NOTHING, LOCAL, REMOTE } in=NOTHING; int c; int x,y; int mouse_x,mouse_y; int image_width,image_height; int image_xoffset=0,image_yoffset=0; int my_width,my_height; int err=0,usage=0; BITMAP *bp; FILE *input; static struct menu_entry menu[] = { { "quit","q" } }; char file[_POSIX_PATH_MAX]; /*}}} */ /*{{{ parse arguments*/ while ((c=getopt(argc,argv,"l:r:"))!=EOF) { switch (c) { /*{{{ l file*/ case 'l': { if ((input=fopen(optarg,"r"))==(FILE*)0) { fprintf(stderr,"%s: Can't open %s\r\n",argv[0],optarg); err=1; } else in=LOCAL; break; } /*}}} */ /*{{{ r file*/ case 'r': { char *cwd; in=REMOTE; if (*optarg!='/' && *optarg!='.') { if ((cwd=getcwd((char*)0,(size_t)0))!=(char*)0) { strcpy(file,cwd); strcat(file,"/"); strcat(file,optarg); } else { fprintf(stderr,"%s: Can't get current directory\r\n",argv[0]); err=1; } } else strcpy(file,optarg); break; } /*}}} */ /*{{{ default*/ default: { usage=1; break; } /*}}} */ } } if (err) exit(err); if (usage || optind!=argc) { fprintf(stderr,"Usage: mgrview [-l file | -r file]\n"); exit(1); } if (in==NOTHING) { in=LOCAL; input=stdin; } /*}}} */ /*{{{ setup*/ ckmgrterm(argv[0]); m_setup(M_MODEOK); signal(SIGINT,clean); signal(SIGTERM,clean); signal(SIGPIPE,clean); m_ttyset(); m_push(P_MENU|P_EVENT|P_FLAGS); m_setmode(M_ABS); m_setcursor(CS_INVIS); menu_load(1,1,menu); m_setevent(REDRAW, "R"); m_setevent(RESHAPE, "R"); m_setevent(BUTTON_1,"[%p]"); m_setevent(BUTTON_2,"m"); m_flush(); /*}}} */ if (in==LOCAL) { /*{{{ load bitmap to client space*/ if ((bp=bitmapread(input))==(BITMAP*)0) { fprintf(stderr,"%s: No MGR bitmap.\r\n",argv[0]); clean(1); } image_width=BIT_WIDE(bp); image_height=BIT_HIGH(bp); /*}}} */ /*{{{ transfer bitmap to server space*/ m_func(BIT_SRC); m_bitcreate(IMAGE_BITMAP,image_width,image_height); m_bitldto(image_width,image_height,0,0,IMAGE_BITMAP,bit_size(image_width,image_height,BIT_DEPTH(bp))); fwrite(BIT_DATA(bp),bit_size(image_width,image_height,BIT_DEPTH(bp)),1,m_termout); m_flush(); bit_destroy(bp); /*}}} */ } else if (in==REMOTE) { /*{{{ transfer bitmap from server fs to server space*/ m_bitfromfile(IMAGE_BITMAP,file); m_get(); if (sscanf(m_linebuf,"%d %d",&image_width,&image_height)<2) { fprintf(stderr,"%s: No MGR bitmap.\r\n",argv[0]); clean(1); } /*}}} */ } /*{{{ user interaction*/ get_size((int*)0,(int*)0,&my_width,&my_height); display(image_xoffset,image_yoffset,my_width,my_height,image_width,image_height); m_flush(); while ((c=getc(m_termin))!='q') switch (c) { /*{{{ m -- left button displays menu*/ case 'm': { m_selectmenu(1); m_flush(); break; } /*}}} */ /*{{{ [%d %d] -- right button*/ case '[': { fscanf(m_termin,"%d %d]",&mouse_x,&mouse_y); /*{{{ compute new x start*/ if (my_width>image_width) image_xoffset=0; else if (mouse_x<=0) image_xoffset=0; else if (mouse_x>=my_width) image_xoffset=my_width-image_width; else { /*{{{ move x start by difference from mouse and middle*/ image_xoffset=image_xoffset-(mouse_x-my_width/2); /*}}} */ /*{{{ check and corrent range of x start*/ if (image_xoffset<my_width-image_width) image_xoffset=my_width-image_width; else if (image_xoffset>0) image_xoffset=0; /*}}} */ } /*}}} */ /*{{{ compute new y start*/ if (my_height>image_height) image_yoffset=0; else if (mouse_y<=0) image_yoffset=0; else if (mouse_y>=my_height) image_yoffset=my_height-image_height; else { /*{{{ move y start by difference from mouse and middle*/ image_yoffset=image_yoffset-(mouse_y-my_height/2); /*}}} */ /*{{{ check and corrent range of y start*/ if (image_yoffset<my_height-image_height) image_yoffset=my_height-image_height; else if (image_yoffset>0) image_yoffset=0; /*}}} */ } /*}}} */ display(image_xoffset,image_yoffset,my_width,my_height,image_width,image_height); m_flush(); break; } /*}}} */ /*{{{ R -- redraw*/ case 'R': { get_size((int*)0,(int*)0,&my_width,&my_height); /*{{{ compute new x offset*/ if (my_width<image_width) { if (image_xoffset<my_width-image_width) image_xoffset=my_width-image_width; } else image_xoffset=0; /*}}} */ /*{{{ compute new y offset*/ if (my_height<image_height) { if (image_yoffset<my_height-image_height) image_yoffset=my_height-image_height; } else image_yoffset=0; /*}}} */ m_func(BIT_CLR); m_bitwrite(0,0,my_width,my_height); m_func(BIT_SRC); m_bitcopyto(image_xoffset,image_yoffset,image_width,image_height,0,0,WINDOW_BITMAP,IMAGE_BITMAP); m_flush(); break; } /*}}} */ } /*}}} */ /*{{{ exit*/ m_bitdestroy(IMAGE_BITMAP); get_colrow(&x,&y); m_move(0,y-1); clean(0); /* NOTREACHED */ return 255; /*}}} */ }
/*{{{ update*/ void vd_update(void) { m_flush(); }
/*{{{ main*/ int main(int argc, char *argv[]) { /*{{{ variables*/ enum { NOTHING, OTHER_FS, SAME_FS } in=NOTHING; int c; int mouse_x,mouse_y; int image_width,image_height; int image_xoffset=0,image_yoffset=0; int my_width,my_height; int image_depth,image_size; int err=0,usage=0; FILE *input=(FILE*)0; static struct menu_entry menu[] = { { "Normal","|n\n" }, { "Reverse","|r\n" }, { "-------", "" }, { "Quit","|q\n" } }; char file[_POSIX_PATH_MAX]; char event[20]; /*}}} */ /*{{{ parse arguments*/ while ((c=getopt(argc,argv,"ro:s:"))!=EOF) { switch (c) { /*{{{ r*/ case 'r': display_op=BIT_NOT(BIT_SRC); break; /*}}} */ /*{{{ o file*/ case 'o': { if ((input=fopen(optarg,"r"))==(FILE*)0) { fprintf(stderr,"%s: Can't open %s\r\n",argv[0],optarg); err=1; } else in=OTHER_FS; break; } /*}}} */ /*{{{ s file*/ case 's': { char *cwd; in=SAME_FS; if (*optarg!='/' && *optarg!='.') { if ((cwd=getcwd((char*)0,(size_t)0))!=(char*)0) { strcpy(file,cwd); strcat(file,"/"); strcat(file,optarg); } else { fprintf(stderr,"%s: Can't get current directory\r\n",argv[0]); err=1; } } else strcpy(file,optarg); break; } /*}}} */ /*{{{ default*/ default: { usage=1; break; } /*}}} */ } } if (err) exit(err); if (usage || optind!=argc) { fprintf(stderr,"Usage: mgrview [-o file | -s file]\n"); exit(1); } if (in==NOTHING) { in=OTHER_FS; input=stdin; } /*}}} */ /*{{{ setup*/ ckmgrterm(argv[0]); m_setup(M_MODEOK); signal(SIGINT,clean); signal(SIGTERM,clean); signal(SIGPIPE,clean); m_ttyset(); m_push(P_ALL); m_setmode(M_ABS); m_setcursor(CS_INVIS); menu_load(1,4,menu); m_setevent(REDRAW, "|R\n"); m_setevent(RESHAPE, "|R\n"); m_setevent(BUTTON_1,"|!%p!\n"); m_setevent(BUTTON_2,"|m\n"); m_flush(); /*}}} */ if (in==OTHER_FS) { /*{{{ variables*/ struct b_header bh; void *bp; /*}}} */ /*{{{ load bitmap to client space*/ if (fread(&bh,sizeof(struct b_header),1,input)!=1) { fprintf(stderr,"%s: Can't read header of bitmap.\r\n",argv[0]); clean(1); } if (!B_ISHDR8(&bh)) { fprintf(stderr,"%s: No MGR bitmap or old format.\r\n",argv[0]); clean(1); } B_GETHDR8(&bh,image_width,image_height,image_depth); image_size=B_SIZE8(image_width,image_height,image_depth); /*}}} */ /*{{{ transfer bitmap to server space*/ m_func(BIT_SRC); m_bitcreate(IMAGE_BITMAP,image_width,image_height); m_bitldto(image_width,image_height,0,0,IMAGE_BITMAP,image_size); bp=malloc(image_size); fread(bp,image_size,1,input); fwrite(bp,image_size,1,m_termout); free(bp); /*}}} */ } else if (in==SAME_FS) /*{{{ transfer bitmap from server fs to server space*/ { m_bitfromfile(IMAGE_BITMAP,file); m_get(); if (sscanf(m_linebuf,"%d %d",&image_width,&image_height)<2) { fprintf(stderr,"%s: MGR server can't load MGR bitmap.\r\n",argv[0]); clean(1); } } /*}}} */ /*{{{ user interaction*/ m_getwindowsize(&my_width,&my_height); display(image_xoffset,image_yoffset,my_width,my_height,image_width,image_height); m_flush(); do { if (m_getevent(10000,&c,event,sizeof(event))==EV_EVENTSTR) switch (event[0]) { /*{{{ n,r*/ case 'n': case 'r': { display_op=(c=='n' ? BIT_SRC : BIT_NOT(BIT_SRC)); m_func(display_op); m_bitcopyto(image_xoffset,image_yoffset,image_width,image_height,0,0,WINDOW_BITMAP,IMAGE_BITMAP); m_flush(); break; } /*}}} */ /*{{{ m -- left button displays menu*/ case 'm': { m_selectmenu(1); m_flush(); break; } /*}}} */ /*{{{ !%d %d! -- right button*/ case '!': { sscanf(event,"!%d %d!",&mouse_x,&mouse_y); /*{{{ compute new x start*/ if (my_width>image_width) image_xoffset=0; else if (mouse_x<=0) image_xoffset=0; else if (mouse_x>=my_width) image_xoffset=my_width-image_width; else { /*{{{ move x start by difference from mouse and middle*/ image_xoffset=image_xoffset-(mouse_x-my_width/2); /*}}} */ /*{{{ check and corrent range of x start*/ if (image_xoffset<my_width-image_width) image_xoffset=my_width-image_width; else if (image_xoffset>0) image_xoffset=0; /*}}} */ } /*}}} */ /*{{{ compute new y start*/ if (my_height>image_height) image_yoffset=0; else if (mouse_y<=0) image_yoffset=0; else if (mouse_y>=my_height) image_yoffset=my_height-image_height; else { /*{{{ move y start by difference from mouse and middle*/ image_yoffset=image_yoffset-(mouse_y-my_height/2); /*}}} */ /*{{{ check and corrent range of y start*/ if (image_yoffset<my_height-image_height) image_yoffset=my_height-image_height; else if (image_yoffset>0) image_yoffset=0; /*}}} */ } /*}}} */ display(image_xoffset,image_yoffset,my_width,my_height,image_width,image_height); m_flush(); break; } /*}}} */ /*{{{ R -- redraw*/ case 'R': { m_getwindowsize(&my_width,&my_height); /*{{{ compute new x offset*/ if (my_width<image_width) { if (image_xoffset<my_width-image_width) image_xoffset=my_width-image_width; } else image_xoffset=0; /*}}} */ /*{{{ compute new y offset*/ if (my_height<image_height) { if (image_yoffset<my_height-image_height) image_yoffset=my_height-image_height; } else image_yoffset=0; /*}}} */ m_func(BIT_CLR); m_bitwrite(0,0,my_width,my_height); m_func(display_op); m_bitcopyto(image_xoffset,image_yoffset,image_width,image_height,0,0,WINDOW_BITMAP,IMAGE_BITMAP); m_flush(); break; } /*}}} */ } } while (event[0]!='q'); /*}}} */ /*{{{ exit*/ m_bitdestroy(IMAGE_BITMAP); clean(0); /*}}} */ return 255; }
static int rsae_send_imsg(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding, unsigned int cmd) { int ret = 0; struct imsgbuf *ibuf; struct imsg imsg; int n, done = 0; const void *toptr; char *pkiname; size_t tlen; struct msg m; uint64_t id; if ((pkiname = RSA_get_ex_data(rsa, 0)) == NULL) return (0); /* * Send a synchronous imsg because we cannot defer the RSA * operation in OpenSSL's engine layer. */ m_create(p_ca, cmd, 0, 0, -1); rsae_reqid++; m_add_id(p_ca, rsae_reqid); m_add_string(p_ca, pkiname); m_add_data(p_ca, (const void *)from, (size_t)flen); m_add_size(p_ca, (size_t)RSA_size(rsa)); m_add_size(p_ca, (size_t)padding); m_flush(p_ca); ibuf = &p_ca->imsgbuf; while (!done) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) fatalx("imsg_read"); if (n == 0) fatalx("pipe closed"); while (!done) { if ((n = imsg_get(ibuf, &imsg)) == -1) fatalx("imsg_get error"); if (n == 0) break; log_imsg(PROC_PONY, PROC_CA, &imsg); switch (imsg.hdr.type) { case IMSG_CA_PRIVENC: case IMSG_CA_PRIVDEC: break; default: /* Another imsg is queued up in the buffer */ pony_imsg(p_ca, &imsg); imsg_free(&imsg); continue; } m_msg(&m, &imsg); m_get_id(&m, &id); if (id != rsae_reqid) fatalx("invalid response id"); m_get_int(&m, &ret); if (ret > 0) m_get_data(&m, &toptr, &tlen); m_end(&m); if (ret > 0) memcpy(to, toptr, tlen); done = 1; imsg_free(&imsg); } } mproc_event_add(p_ca); return (ret); }
void updown(int what, int nr) { #ifdef LOG_XFER #warning LOG_XFER defined! FILE *xfl; #endif const char *name[13]; int idx[13]; int r, f, g = 0; char *t = what == 'U' ? _("Upload") : _("Download"); char buf[160]; char buffirst[20]; char xfrstr[160] = ""; char trimbuf[160] = ""; char title[64]; const char *s =""; int pipefd[2]; int n, status; char * cmdline = NULL; char * translated_cmdline = NULL; WIN *win = (WIN *)NULL; if (mcd(what == 'U' ? P_UPDIR : P_DOWNDIR) < 0) return; /* Automatic? */ if (nr == 0) { for (f = 0; f < 12; f++) { if (P_PNAME(f)[0] && P_PUD(f) == what) { name[g] = P_PNAME(f); idx[g++] = f; } } name[g] = NULL; if (g == 0) return; r = mc_wselect(30, 7, name, NULL, t, stdattr, mfcolor, mbcolor) - 1; if (r < 0) return; g = idx[r]; } else g = nr; buf[0] = 0; /* jseymour file selector with choice of dir on zmodem, etc. download */ #if 1 { int multiple; /* 0:only directory, 1:one file, -1:any number */ size_t cmdline_length; if (P_MUL(g)=='Y') /* need file(s), or just a directory? */ multiple = what == 'U'? -1 : 0; else multiple = 1; /* only one allowed */ if (P_FSELW[0] == 'Y' && (what == 'U' || P_ASKDNDIR[0] == 'Y')) { s = filedir(multiple, what == 'U'? 0 : 1); if (s == NULL) return; } else if (P_PNN(g) == 'Y') { s = input(_("Please enter file names"), buf); if (s == NULL) return; } /* discard directory if "multiple" == 0 */ cmdline_length = strlen(P_PPROG(g)) + strlen((char*) (multiple == 0 ? "" : s)) + 1; /* + 1 for ' ' */ cmdline = malloc(cmdline_length + 1); /* + 1 for NUL */ if (cmdline == NULL) { werror(_("Out of memory: could allocate buffer for command line")); return; } snprintf(cmdline, cmdline_length + 1, "%s %s", P_PPROG(g), multiple == 0 ? "" : s); } #endif if (P_LOGXFER[0] == 'Y') do_log("%s", cmdline); /* jl 22.06.97 */ if (P_PFULL(g) == 'N') { win = mc_wopen(10, 7, 70, 13, BSINGLE, stdattr, mfcolor, mbcolor, 1, 0, 1); snprintf(title, sizeof(title), _("%.30s %s - Press CTRL-C to quit"), P_PNAME(g), what == 'U' ? _("upload") : _("download")); mc_wtitle(win, TMID, title); pipe(pipefd); } else mc_wleave(); m_flush(portfd); switch (udpid = fork()) { case -1: werror(_("Out of memory: could not fork()")); if (win) { close(pipefd[0]); close(pipefd[1]); mc_wclose(win, 1); } else mc_wreturn(); mcd(""); if(cmdline) free(cmdline); return; case 0: /* Child */ if (P_PIORED(g) == 'Y') { dup2(portfd, 0); dup2(portfd, 1); } if (win) { dup2(pipefd[1], 2); close(pipefd[0]); if (pipefd[1] != 2) close(pipefd[1]); } lockfile_remove(); for (n = 1; n < _NSIG; n++) signal(n, SIG_DFL); translated_cmdline = translate(cmdline); if (translated_cmdline != NULL) { fastexec(translated_cmdline); free(translated_cmdline); } if(cmdline) free(cmdline); exit(1); default: /* Parent */ break; } if(cmdline) free(cmdline); if (win) { setcbreak(1); /* Cbreak, no echo. */ enab_sig(1, 0); /* But enable SIGINT */ } signal(SIGINT, udcatch); if (P_PIORED(g) == 'Y') { close(pipefd[1]); #ifdef LOG_XFER xfl=fopen("xfer.log","wb"); #endif while ((n = read(pipefd[0], buf, sizeof(buf))) > 0) { buf[n] = '\0'; mc_wputs(win, buf); timer_update(); /* Log the filenames & sizes jl 14.09.97 */ if (P_LOGXFER[0] == 'Y') { #ifdef LOG_XFER if (xfl) fprintf(xfl,">%s<\n",buf); #endif if (sscanf(buf, "%19s", buffirst)) { /* if / jl 29.09.97 */ if (!strncmp (buffirst, "Receiving", 9) || !strncmp (buffirst, "Sending", 7)) { if (xfrstr[0]) { trim (trimbuf, xfrstr, sizeof(trimbuf)); do_log ("%s", trimbuf); xfrstr[0] = 0; } trim (trimbuf, buf, sizeof(trimbuf)); do_log("%s", trimbuf); } else if (!strncmp (buffirst, "Bytes", 5)) { strncpy (xfrstr, buf, sizeof(xfrstr)); } buffirst[0] = 0; trimbuf[0] = 0; } } } #ifdef LOG_XFER if (xfl) fclose(xfl); #endif } /* Log the last file size jl 14.09.97 */ if (P_LOGXFER[0] == 'Y' && xfrstr[0]) { trim (trimbuf, xfrstr, sizeof(trimbuf)); do_log ("%s", trimbuf); xfrstr[0] = 0; } while (udpid != m_wait(&status)); if (win) { enab_sig(0, 0); signal(SIGINT, SIG_IGN); } if (win == (WIN *)0) mc_wreturn(); lockfile_create(); /* MARK updated 02/17/94 - Flush modem port before displaying READY msg */ /* because a BBS often displays menu text right after a download, and we */ /* don't want the modem buffer to be lost while waiting for key to be hit */ m_flush(portfd); port_init(); setcbreak(2); /* Raw, no echo. */ if (win) close(pipefd[0]); mcd(""); timer_update(); /* If we got interrupted, status != 0 */ if (win && (status & 0xFF00) == 0) { #if VC_MUSIC if (P_SOUND[0] == 'Y') { mc_wprintf(win, _("\n READY: press any key to continue...")); music(); } else sleep(1); #else /* MARK updated 02/17/94 - If there was no VC_MUSIC capability, */ /* then at least make some beeps! */ if (P_SOUND[0] == 'Y') mc_wprintf(win, "\007\007\007"); sleep(1); #endif } if (win) mc_wclose(win, 1); }