Lines Matching refs:p
83 prompt_Display(struct prompt *p) in prompt_Display() argument
89 if (p->TermMode || !p->needprompt) in prompt_Display()
92 p->needprompt = 0; in prompt_Display()
94 if (p->nonewline) in prompt_Display()
95 p->nonewline = 0; in prompt_Display()
97 fprintf(p->Term, "\n"); in prompt_Display()
99 if (p->auth == LOCAL_AUTH) in prompt_Display()
104 if (p->bundle->ncp.ipcp.fsm.state == ST_OPENED) in prompt_Display()
107 else if (!Enabled(p->bundle, OPT_IPCP) && in prompt_Display()
108 p->bundle->ncp.ipv6cp.fsm.state == ST_OPENED) in prompt_Display()
111 else if (bundle_Phase(p->bundle) == PHASE_NETWORK) in prompt_Display()
113 else if (bundle_Phase(p->bundle) == PHASE_AUTHENTICATE) in prompt_Display()
127 fprintf(p->Term, "%s%s%s> ", pconnect, pauth, shostname); in prompt_Display()
128 fflush(p->Term); in prompt_Display()
135 struct prompt *p = descriptor2prompt(d); in prompt_UpdateSet() local
140 if (!p->active) in prompt_UpdateSet()
143 if (p->fd_in >= 0) { in prompt_UpdateSet()
145 FD_SET(p->fd_in, r); in prompt_UpdateSet()
146 log_Printf(LogTIMER, "prompt %s: fdset(r) %d\n", p->src.from, p->fd_in); in prompt_UpdateSet()
150 FD_SET(p->fd_in, e); in prompt_UpdateSet()
151 log_Printf(LogTIMER, "prompt %s: fdset(e) %d\n", p->src.from, p->fd_in); in prompt_UpdateSet()
154 if (sets && *n < p->fd_in + 1) in prompt_UpdateSet()
155 *n = p->fd_in + 1; in prompt_UpdateSet()
158 prompt_Display(p); in prompt_UpdateSet()
166 struct prompt *p = descriptor2prompt(d); in prompt_IsSet() local
167 return p->fd_in >= 0 && FD_ISSET(p->fd_in, fdset); in prompt_IsSet()
172 prompt_ShowHelp(struct prompt *p) in prompt_ShowHelp() argument
174 prompt_Printf(p, "The following commands are available:\n"); in prompt_ShowHelp()
175 prompt_Printf(p, " ~p\tEnter Packet mode\n"); in prompt_ShowHelp()
176 prompt_Printf(p, " ~t\tShow timers\n"); in prompt_ShowHelp()
177 prompt_Printf(p, " ~m\tShow memory map\n"); in prompt_ShowHelp()
178 prompt_Printf(p, " ~.\tTerminate program\n"); in prompt_ShowHelp()
179 prompt_Printf(p, " ~?\tThis help\n"); in prompt_ShowHelp()
186 struct prompt *p = descriptor2prompt(d); in prompt_Read() local
192 if (p->TermMode == NULL) { in prompt_Read()
193 n = read(p->fd_in, linebuff, sizeof linebuff - 1); in prompt_Read()
199 p->nonewline = 1; /* Maybe command_Decode does a prompt */ in prompt_Read()
200 prompt_Required(p); in prompt_Read()
203 log_PromptContext = p; in prompt_Read()
204 if (!command_Decode(bundle, linebuff, n, p, p->src.from)) in prompt_Read()
205 prompt_Printf(p, "Syntax error\n"); in prompt_Read()
209 log_Printf(LogPHASE, "%s: Client connection closed.\n", p->src.from); in prompt_Read()
210 if (!p->owner) in prompt_Read()
212 prompt_Destroy(p, 0); in prompt_Read()
217 switch (p->TermMode->state) { in prompt_Read()
219 prompt_Printf(p, "Link lost, terminal mode.\n"); in prompt_Read()
220 prompt_TtyCommandMode(p); in prompt_Read()
221 p->nonewline = 0; in prompt_Read()
222 prompt_Required(p); in prompt_Read()
229 prompt_Printf(p, "\nPacket mode detected.\n"); in prompt_Read()
230 prompt_TtyCommandMode(p); in prompt_Read()
231 p->nonewline = 0; in prompt_Read()
243 n = read(p->fd_in, &ch, 1); in prompt_Read()
247 switch (p->readtilde) { in prompt_Read()
250 p->readtilde = 1; in prompt_Read()
252 if (physical_Write(p->TermMode->physical, &ch, n) < 0) { in prompt_Read()
254 prompt_TtyCommandMode(p); in prompt_Read()
260 prompt_ShowHelp(p); in prompt_Read()
263 datalink_Up(p->TermMode, 0, 1); in prompt_Read()
264 prompt_Printf(p, "\nPacket mode.\n"); in prompt_Read()
265 prompt_TtyCommandMode(p); in prompt_Read()
268 prompt_TtyCommandMode(p); in prompt_Read()
269 p->nonewline = 0; in prompt_Read()
270 prompt_Required(p); in prompt_Read()
273 timer_Show(0, p); in prompt_Read()
285 arg.cx = p->TermMode; in prompt_Read()
286 arg.prompt = p; in prompt_Read()
292 if (physical_Write(p->TermMode->physical, &ch, n) < 0) { in prompt_Read()
294 prompt_TtyCommandMode(p); in prompt_Read()
298 p->readtilde = 0; in prompt_Read()
316 struct prompt *p = (struct prompt *)malloc(sizeof(struct prompt)); in prompt_Create() local
318 if (p != NULL) { in prompt_Create()
319 p->desc.type = PROMPT_DESCRIPTOR; in prompt_Create()
320 p->desc.UpdateSet = prompt_UpdateSet; in prompt_Create()
321 p->desc.IsSet = prompt_IsSet; in prompt_Create()
322 p->desc.Read = prompt_Read; in prompt_Create()
323 p->desc.Write = prompt_Write; in prompt_Create()
329 free(p); in prompt_Create()
332 p->fd_in = STDIN_FILENO; in prompt_Create()
333 p->fd_out = STDOUT_FILENO; in prompt_Create()
334 p->Term = stdout; in prompt_Create()
335 p->owner = NULL; in prompt_Create()
336 p->auth = LOCAL_AUTH; in prompt_Create()
337 p->src.type = "Controller"; in prompt_Create()
338 strncpy(p->src.from, tty, sizeof p->src.from - 1); in prompt_Create()
339 p->src.from[sizeof p->src.from - 1] = '\0'; in prompt_Create()
340 tcgetattr(p->fd_in, &p->oldtio); /* Save original tty mode */ in prompt_Create()
342 p->fd_in = p->fd_out = fd; in prompt_Create()
343 p->Term = fdopen(fd, "a+"); in prompt_Create()
344 p->owner = s; in prompt_Create()
345 p->auth = *s->cfg.passwd ? LOCAL_NO_AUTH : LOCAL_AUTH; in prompt_Create()
346 p->src.type = "unknown"; in prompt_Create()
347 *p->src.from = '\0'; in prompt_Create()
349 p->TermMode = NULL; in prompt_Create()
350 p->nonewline = 1; in prompt_Create()
351 p->needprompt = 1; in prompt_Create()
352 p->readtilde = 0; in prompt_Create()
353 p->bundle = bundle; in prompt_Create()
354 log_RegisterPrompt(p); in prompt_Create()
357 return p; in prompt_Create()
361 prompt_Destroy(struct prompt *p, int verbose) in prompt_Destroy() argument
363 if (p) { in prompt_Destroy()
364 if (p->Term != stdout) { in prompt_Destroy()
365 fclose(p->Term); in prompt_Destroy()
366 close(p->fd_in); in prompt_Destroy()
367 if (p->fd_out != p->fd_in) in prompt_Destroy()
368 close(p->fd_out); in prompt_Destroy()
370 log_Printf(LogPHASE, "%s: Client connection dropped.\n", p->src.from); in prompt_Destroy()
372 prompt_TtyOldMode(p); in prompt_Destroy()
374 log_UnRegisterPrompt(p); in prompt_Destroy()
375 free(p); in prompt_Destroy()
380 prompt_Printf(struct prompt *p, const char *fmt,...) in prompt_Printf() argument
382 if (p && p->active) { in prompt_Printf()
386 prompt_vPrintf(p, fmt, ap); in prompt_Printf()
392 prompt_vPrintf(struct prompt *p, const char *fmt, va_list ap) in prompt_vPrintf() argument
394 if (p && p->active) { in prompt_vPrintf()
398 if (p->TermMode) { in prompt_vPrintf()
411 vfprintf(p->Term, pfmt, ap); in prompt_vPrintf()
412 fflush(p->Term); in prompt_vPrintf()
413 p->nonewline = 1; in prompt_vPrintf()
418 prompt_TtyInit(struct prompt *p) in prompt_TtyInit() argument
420 int stat, fd = p ? p->fd_in : STDIN_FILENO; in prompt_TtyInit()
429 if (p) in prompt_TtyInit()
430 newtio = p->oldtio; in prompt_TtyInit()
437 if (!p) in prompt_TtyInit()
443 if (p) in prompt_TtyInit()
444 p->comtio = newtio; in prompt_TtyInit()
451 prompt_TtyCommandMode(struct prompt *p) in prompt_TtyCommandMode() argument
456 tcgetattr(p->fd_in, &newtio); in prompt_TtyCommandMode()
458 newtio.c_iflag = p->oldtio.c_iflag; in prompt_TtyCommandMode()
460 tcsetattr(p->fd_in, TCSADRAIN, &newtio); in prompt_TtyCommandMode()
462 stat = fcntl(p->fd_in, F_GETFL, 0); in prompt_TtyCommandMode()
465 fcntl(p->fd_in, F_SETFL, stat); in prompt_TtyCommandMode()
468 p->TermMode = NULL; in prompt_TtyCommandMode()
475 prompt_TtyTermMode(struct prompt *p, struct datalink *dl) in prompt_TtyTermMode() argument
479 if (p->Term == stdout) in prompt_TtyTermMode()
480 tcsetattr(p->fd_in, TCSADRAIN, &p->comtio); in prompt_TtyTermMode()
482 stat = fcntl(p->fd_in, F_GETFL, 0); in prompt_TtyTermMode()
485 fcntl(p->fd_in, F_SETFL, stat); in prompt_TtyTermMode()
487 p->TermMode = dl; in prompt_TtyTermMode()
491 prompt_TtyOldMode(struct prompt *p) in prompt_TtyOldMode() argument
495 stat = fcntl(p->fd_in, F_GETFL, 0); in prompt_TtyOldMode()
498 fcntl(p->fd_in, F_SETFL, stat); in prompt_TtyOldMode()
501 if (p->Term == stdout) in prompt_TtyOldMode()
502 tcsetattr(p->fd_in, TCSADRAIN, &p->oldtio); in prompt_TtyOldMode()
506 prompt_pgrp(struct prompt *p) in prompt_pgrp() argument
508 return tcgetpgrp(p->fd_in); in prompt_pgrp()
550 prompt_Continue(struct prompt *p) in prompt_Continue() argument
553 if (getpgrp() == prompt_pgrp(p)) { in prompt_Continue()
554 prompt_TtyCommandMode(p); in prompt_Continue()
555 p->nonewline = 1; in prompt_Continue()
556 prompt_Required(p); in prompt_Continue()
557 log_ActivatePrompt(p); in prompt_Continue()
558 } else if (!p->owner) { in prompt_Continue()
562 bgtimer.arg = p; in prompt_Continue()
568 prompt_Suspend(struct prompt *p) in prompt_Suspend() argument
570 if (getpgrp() == prompt_pgrp(p)) { in prompt_Suspend()
571 prompt_TtyOldMode(p); in prompt_Suspend()
572 log_DeactivatePrompt(p); in prompt_Suspend()