File: pop_get_subcommand.c

package info (click to toggle)
qpopper 2.3-4
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 560 kB
  • ctags: 415
  • sloc: ansic: 4,967; makefile: 153; sh: 43
file content (68 lines) | stat: -rw-r--r-- 2,115 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 1989 Regents of the University of California.
 * All rights reserved.  The Berkeley software License Agreement
 * specifies the terms and conditions for redistribution.
 */

#ifndef lint
static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
static char SccsId[] = "@(#)@(#)pop_get_subcommand.c	2.1  2.1 3/18/91";
#endif /* not lint */

#include <stdio.h>
#include <sys/types.h>
#if defined(SOLARIS2) || defined(SYSV) || defined(AIX)
#include <string.h>
#else
#include <strings.h>
#endif
#include "popper.h"

/* 
 *  get_subcommand: Extract a POP XTND subcommand from a client input line
 */

static xtnd_table subcommands[] = {
        "xmit",     0,  0,  pop_xmit,
	"xlst",	    1,  2,  pop_xlst,
        NULL
};

xtnd_table *pop_get_subcommand(p)
POP     *   p;
{
    xtnd_table      *   s;

    /*  Search for the POP command in the command/state table */
    for (s = subcommands; s->subcommand; s++) {

        if (strcmp(s->subcommand,p->pop_subcommand) == 0) {

            /*  Were too few parameters passed to the subcommand? */
            if ((p->parm_count-1) < s->min_parms) {
                pop_msg(p,POP_FAILURE,
                    "Too few arguments for the %s %s command.",
                        p->pop_command,p->pop_subcommand);
                return((xtnd_table *)0);
            }
            

            /*  Were too many parameters passed to the subcommand? */
            if ((p->parm_count-1) > s->max_parms) {
                pop_msg(p,POP_FAILURE,
                    "Too many arguments for the %s %s command.",
                        p->pop_command,p->pop_subcommand);
                return((xtnd_table *)0);
            }
            

            /*  Return a pointer to the entry for this subcommand 
                in the XTND command table */
            return (s);
        }
    }
    /*  The client subcommand was not located in the XTND command table */
    pop_msg(p,POP_FAILURE,
            "Unknown command: \"%s %s\".",p->pop_command,p->pop_subcommand);
    return((xtnd_table *)0);
}