File:  [ELWIX - Embedded LightWeight unIX -] / libaitwww / inc / aitwww.h
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Thu Mar 8 23:40:21 2012 UTC (12 years, 2 months ago) by misho
Branches: MAIN
CVS tags: HEAD
Initial revision

/*************************************************************************
* (C) 2012 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
*  by Michael Pounov <misho@elwix.org>
*
* $Author: misho $
* $Id: aitwww.h,v 1.1 2012/03/08 23:40:21 misho Exp $
*
**************************************************************************
The ELWIX and AITNET software is distributed under the following
terms:

All of the documentation and software included in the ELWIX and AITNET
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>

Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
	by Michael Pounov <misho@elwix.org>.  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
   must display the following acknowledgement:
This product includes software developed by Michael Pounov <misho@elwix.org>
ELWIX - Embedded LightWeight unIX and its contributors.
4. Neither the name of AITNET nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef __AITWWW_H
#define __AITWWW_H


struct tagCGI {
	char			*cgi_name;
	char			*cgi_value;

	SLIST_ENTRY(tagCGI)	cgi_node;
};
typedef SLIST_HEAD(, tagCGI) cgi_t;

struct tagMIME;
typedef SLIST_HEAD(, tagMIME) mime_t;

struct tagMIME {
	cgi_t			mime_header;

	struct iovec		mime_body;
	struct iovec		mime_prolog;
	struct iovec		mime_epilog;

	mime_t			*mime_attach;

	SLIST_ENTRY(tagMIME)	mime_node;
};


/*
 * www_initCGI() - Init CGI program
 *
 * return: NULL error or allocated cgi session
 */
cgi_t *www_initCGI(void);
/*
 * www_closeCGI() - Close and free all CGI resources
 *
 * @cgi = Inited cgi session
 * return: none
 */
void www_closeCGI(cgi_t ** __restrict cgi);
/*
 * www_parseQuery() - Parse CGI query string
 *
 * @str = String
 * return: NULL error or allocated cgi session
 */
cgi_t *www_parseQuery(const char *str);
/*
 * www_parseMultiPart() - Parse Multi part POST CGI query string
 *
 * @str = String
 * @ctlen = Content length
 * @ct = Content type
 * return: NULL error or allocated cgi session
 */
cgi_t *www_parseMultiPart(const char *str, int ctlen, const char *ct);
/*
 * www_getValue() - Get Value from CGI session
 *
 * @cgi = Inited cgi session
 * @name = Name of cgi variable
 * return: NULL not found or !=NULL value
 */
inline const char *www_getValue(cgi_t * __restrict cgi, const char *name);
/*
 * www_addValue() - Add new or update if exists CGI variable
 *
 * @cgi = Inited cgi session
 * @name = Name of cgi variable
 * @value = Value of cgi variable
 * return: -1 error, 0 add new one or 1 updated variable
 */
int www_addValue(cgi_t * __restrict cgi, const char *name, const char *value);
/*
 * www_delPair() - Delete CGI variable from session
 *
 * @cgi = Inited cgi session
 * @name = Name of cgi variable
 * return: -1 error, 0 not found or 1 deleted ok
 */
int www_delPair(cgi_t * __restrict cgi, const char *name);

/*
 * www_header() - Output initial html header
 *
 * @output = file handle
 * return: <1 error or >0 writed bytes
 */
inline int www_header(FILE *output);

/*
 * www_parseAttributes() - Parse attributes
 *
 * @ct = Content type
 * return: NULL error or !=NULL attributes
 */
inline cgi_t *www_parseAttributes(const char **ct);
/*
 * www_freeAttributes() - Free attributes
 *
 * @attr = Attributes
 * return: none
 */
inline void www_freeAttributes(cgi_t ** __restrict attr);
/*
 * www_getAttribute() - Get attribute by name
 *
 * @attr = Attributes
 * @name = Name of attribute
 * return: NULL not found or !=NULL attribute value
 */
inline const char *www_getAttribute(cgi_t * __restrict attr, const char *name);


#endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>