File: utilCgiEcho.c

package info (click to toggle)
ted 2.11-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 11,064 kB
  • ctags: 13,935
  • sloc: ansic: 120,446; makefile: 7,469; sh: 253
file content (111 lines) | stat: -rw-r--r-- 2,349 bytes parent folder | download | duplicates (3)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#   include	<utilCgiEcho.h>

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Echo some information on a cgi request.				*/
/*									*/
/************************************************************************/

void utilCgiEchoTaggedValueList(	TaggedValueList *	tvl,
					const char *		label,
					SimpleOutputStream *	sos )
    {
    int			i;
    const TaggedValue *	tv;

    sioOutPutString( "<TABLE>\r\n", sos );

    if  ( label && label[0] )
	{
	sioOutPutString( "<TR><TD COLSPAN=2><B>", sos );
	sioOutPutString( label, sos );
	sioOutPutString( "</B></TD></TR>\r\n", sos );
	}

    tv= tvl->tvlValues;
    for ( i= 0; i < tvl->tvlCount; tv++, i++ )
	{
	sioOutPutString( "<TR><TD>", sos );

	if  ( tv->tvName )
	    { sioOutPutString( tv->tvName, sos );	}
	else{ sioOutPutString( "&nbsp;", sos );		}

	sioOutPutString( "</TD>\r\n<TD>", sos );

	if  ( tv->tvValue )
	    { sioOutPutString( tv->tvValue, sos );	}
	else{ sioOutPutString( "&nbsp;", sos );		}

	sioOutPutString( "</TD></TR>\r\n", sos );
	}

    sioOutPutString( "</TABLE>\r\n", sos );

    return;
    }

void utilCgiEchoRequest(		const CGIRequest *	cgir,
					SimpleOutputStream *	sos )
    {
    if  ( cgir->cgirHeaderValues )
	{
	utilCgiEchoTaggedValueList( cgir->cgirHeaderValues, "Headers", sos );
	}

    if  ( cgir->cgirEnvironmentValues )
	{
	utilCgiEchoTaggedValueList( cgir->cgirEnvironmentValues,
							"Environment", sos );
	}

    if  ( cgir->cgirQueryValues )
	{
	utilCgiEchoTaggedValueList( cgir->cgirQueryValues, "Query", sos );
	}

    if  ( cgir->cgirCookies )
	{
	utilCgiEchoTaggedValueList( cgir->cgirCookies, "Cookies", sos );
	}

    return;
    }

#   ifdef EXAMPLE_CODE

int main(	int		argc,
		char **		argv )
    {
    int				rval= 0;
    CGIRequest *		cgir= (CGIRequest *)0;

    SimpleOutputStream *	sos= (SimpleOutputStream *)0;

    cgir= appCgiInGetRequest();
    if  ( ! cgir )
	{ XDEB(cgir); rval= -1; goto ready;	}

    sos= sioOutStdoutOpen();
    if  ( ! sos )
	{ XDEB(sos); rval= -1; goto ready;	}

    sioOutPutString( "Content-Type: text/html\r\n", sos );
    sioOutPutString( "\r\n", sos );

    utilCgiEchoRequest( cgir, sos );

  ready:

    if  ( sos )
	{ sioOutClose( sos );	}

    if  ( cgir )
	{ appCgiInFreeRequest( cgir );	}

    return rval;
    }

#   endif