home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Mail / qpopper-2.4-MIHS / pop_get_command.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-11  |  3.8 KB  |  113 lines

  1. /*
  2.  * Copyright (c) 1989 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. /*
  8.  * Copyright (c) 1997 by Qualcomm Incorporated.
  9.  */
  10.  
  11.  
  12. #include <config.h>
  13. #include <stdio.h>
  14. #include <sys/types.h>
  15. #include <string.h>
  16. #if HAVE_STRINGS_H
  17. #include <strings.h>
  18. #endif
  19. #include "popper.h"
  20.  
  21. /* 
  22.  *  get_command:    Extract the command from an input line form a POP client
  23.  */
  24.  
  25. static state_table states[] = {
  26.         auth1,  "user", 1,  1,  pop_user,   {auth1, auth2},
  27.         auth2,  "pass", 1,  1,  pop_pass,   {halt,  trans},
  28.         auth1,  "auth", 1,  2,  pop_auth,   {auth1, auth1},
  29. #ifdef RPOP
  30.         auth2,  "rpop", 1,  1,  pop_rpop,   {halt,  trans},
  31. #endif
  32. #ifdef APOP
  33.         auth1,  "apop", 2,  2,  pop_apop,   {halt,  trans},
  34. #endif
  35.         auth1,  "quit", 0,  0,  pop_quit,   {halt,  halt},
  36.         auth2,  "quit", 0,  0,  pop_quit,   {halt,  halt},
  37.         trans,  "stat", 0,  0,  pop_stat,   {trans, trans},
  38.         trans,  "list", 0,  1,  pop_list,   {trans, trans},
  39.         trans,  "retr", 1,  1,  pop_send,   {trans, trans},
  40.         trans,  "dele", 1,  1,  pop_dele,   {trans, trans},
  41.         trans,  "noop", 0,  0,  NULL,       {trans, trans},
  42.         trans,  "rset", 0,  0,  pop_rset,   {trans, trans},
  43.         trans,  "top",  2,  2,  pop_send,   {trans, trans},
  44.         trans,  "last", 0,  0,  pop_last,   {trans, trans},
  45.         trans,  "xtnd", 1,  99, pop_xtnd,   {trans, trans},
  46.         trans,  "uidl", 0,  1,  pop_uidl,   {trans, trans},
  47.         trans,  "euidl",0,  1,  pop_euidl,  {trans, trans},
  48.         trans,  "quit", 0,  0,  pop_updt,   {halt,  halt},
  49.         (state) 0,  NULL,   0,  0,  NULL,       {halt,  halt},
  50. };
  51.  
  52. state_table *pop_get_command(p,mp)
  53. POP             *   p;
  54. register char   *   mp;         /*  Pointer to unparsed line 
  55.                                     received from the client */
  56. {
  57.     state_table     *   s;
  58.     char                buf[MAXMSGLINELEN];
  59.  
  60.     /*  Save a copy of the original client line */
  61. #ifdef DEBUG
  62.     if(p->debug) strncpy(buf, mp, sizeof(buf));
  63. #endif
  64.  
  65.     /*  Parse the message into the parameter array */
  66.     if ((p->parm_count = pop_parse(p,mp)) < 0) return(NULL);
  67.  
  68.     /*  Do not log cleartext passwords */
  69. #ifdef DEBUG
  70.     if(p->debug){
  71.         if(strcmp(p->pop_command,"pass") == 0)
  72.             pop_log(p,POP_DEBUG,"Received: \"%s xxxxxxxxx\"",p->pop_command);
  73.         else {
  74.             /*  Remove trailing <LF> */
  75.             buf[strlen(buf)-2] = '\0';
  76.             pop_log(p,POP_DEBUG,"Received: \"%s\"",buf);
  77.         }
  78.     }
  79. #endif
  80.  
  81.     /*  Search for the POP command in the command/state table */
  82.     for (s = states; s->command; s++) {
  83.  
  84.         /*  Is this a valid command for the current operating state? */
  85.         if (strcmp(s->command,p->pop_command) == 0
  86.              && s->ValidCurrentState == p->CurrentState) {
  87.  
  88.             /*  Were too few parameters passed to the command? */
  89.             if (p->parm_count < s->min_parms) {
  90.                 pop_msg(p,POP_FAILURE,
  91.                     "Too few arguments for the %s command.",p->pop_command);
  92.                 return((state_table *)0);
  93.             }
  94.             
  95.  
  96.             /*  Were too many parameters passed to the command? */
  97.             if (p->parm_count > s->max_parms) {
  98.                 pop_msg(p,POP_FAILURE,
  99.                     "Too many arguments for the %s command.",p->pop_command);
  100.                 return((state_table *)0);
  101.             }
  102.             
  103.  
  104.             /*  Return a pointer to the entry for this command in 
  105.                 the command/state table */
  106.             return (s);
  107.         }
  108.     }
  109.     /*  The client command was not located in the command/state table */
  110.     pop_msg(p,POP_FAILURE,"Unknown command: \"%s\".",p->pop_command);
  111.     return((state_table *)0);
  112. }
  113.