/*
This source file is part of Scol
For the latest info, see http://www.scolring.org

Copyright (c) 2011 Stephane Bisaro, aka Iri <iri@irizone.net>

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

For others informations, please contact us from http://www.scolring.org/
*/


#ifndef __LIBXML2_MAIN_H__
#define __LIBXML2_MAIN_H__


/* export from Scol kernel */
#if ((defined _WIN32) || (defined __WIN32__))
#include "scol_plugin_win.h"
#elif ((defined linux) || (defined __linux))
#include "scol_plugin_lin.h"
#else
#error no platform supported
#endif

/* libxml2 headers */
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlreader.h>

/* thread headers and defines */
#include <pthread.h>
#if ((defined _WIN32) || (defined __WIN32__))
#  include <windows.h>
#  define psleep(sec) Sleep ((sec) * 1000)
#elif ((defined linux) || (defined __linux))
#  include <unistd.h>
#  define psleep(sec) sleep ((sec))
#endif

#include <errno.h>

#include "macros.h"

#define COMMON_LIBXML2_PKG_NB       1



#define S_LIBSAX2_HANDLE            0
#define S_LIBREADER_HANDLE          1
#define S_LIBTREE_HANDLE            2


struct Subxml
{
    int flags;
    int mobj;
    mmachine sm;
    char *filename;
    char *enc_to;
    char *enc_from;
    char *buffer;
    int file;
    #if ((defined linux) || (defined __linux))
    pthread_t thread;
    pthread_t mthread;  /* main thread (mmachine) */
    #elif ((defined _WIN32) || (defined __WIN32__))
    HANDLE thread;
    DWORD mthread;
    #endif
};

struct S_xml
{
    struct _xmlSAXHandler sax;
    xmlTextReaderPtr reader;
    xmlDocPtr doc;
    struct Subxml *sub;
};
typedef struct S_xml *s_xml;


int ObjSax2;
int ObjXmlReader;
int ObjXmlTree;


/* functions definitions */
/* apis */
int SSAX_loadPackage (mmachine m);
int READER_loadPackage (mmachine m);
int TREE_loadPackage (mmachine m);


/* memory */
void s_xml2create_object (mmachine m, xmlParserCtxtPtr s);
void s_xml2create_object_sax (mmachine m, s_xml s);
void s_xml2create_object_reader (mmachine m, s_xml s);
void s_xml2create_object_tree (mmachine m, s_xml s);

/* ms windows */
#if ((defined _WIN32) || (defined __WIN32__))
void winHandleThreadError (LPTSTR funName);
#endif  /* ms windows */

#endif  /* __LIBXML2_MAIN_H__ */

