/* mini
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2004-2006, Toni Thomsson <toni@tonjac.org> 
*/

#ifndef mini_h
#define mini_h

#include <windows.h>
#include <zz_default_error_data.h> // Don't remove, forces class to be exported when building an mini application DLL
/*
    Maximum CGI-parameter argument length
*/
#define MINI_ARGUMENTLEN 10240
#define MINI_DLL_API int __declspec(dllexport) __stdcall
#define MINI_EXPORT __declspec( dllexport )

/**
    MINI message body
*/
typedef struct tagMINI_MESSAGE_BODY{
    /** Key */
    char tag[256]; 
    /** Value */
    char value[256];
} MINI_MESSAGE_BODY;

/**
    MINI message container for signaling a C++ message listener

    @see CzzMessage
*/
typedef struct tagMINI_MESSAGE{
    /** Id */
    char id[100];
    /** Queue name */
    char queue[50];
    /** Creation time */
    long time;
    /** Dll name containing the listener */
    char library[256]; 
    /** Listener class */
    char listener[256];
    /** Extension pointer, usally a CzzMessage-object */
    void* extension;
    /** Message body */
    MINI_MESSAGE_BODY** body;
} MINI_MESSAGE;

/**
    Session object for MINI-fast-CGI programs

    @see CzzDb
*/
typedef struct tagMINI_SESSION{
    /** Id */
    char   id[40]; 
    /** Username */
    char   user[256];
    /** User role 0-9 */
    int    userrole;
    /** Remote ip address */
    char   ip[50]; 
    /** Creation time */
    int    time; 
    /** Locked, used internally do not update */
    int    locked;
    /** Pointer to a saved session object */
    void*  userdata; 
    void*  userdata_j; 
    /** Extension pointer, usally a CzzDb-object */
    void*  extension; 
    /** Number of users */
    int    usercount; 
    /** java */
    int    java;
    /** Last error message */
    char   last_error_message[512];
    /** Last error code */
    int    last_error_code;
    /** Rollback */
    int    rollback;
    /** Language */
    char   lang[3]; 
    /** Skin */
    char   skin[256];
} MINI_SESSION; 

#ifdef __cplusplus
    extern "C" {
#endif

/**
    Prototype for a mini-fast-cgi service

    @param  session    Session object
    @param  argc       Number of cgi-parameters
    @param  argv       Vector with cgi-parameters:

                     argv[0]   Always the name of the DLL
                     argv[n]   Name of parameter: -{name}
                     argv[n+1] Value of parameter {value}

                     example: -id myid

    @param  buff      Reply buffer, The buffer must be allocated with GlobalAlloc(). 
                      The buffer is freed by the caller when the call returns.
    @param  size      Size of buff
    @param  msg       Error message. Buffer allocated by the caller.
    @param  msglen    Maximum size of error message, equals the size of the buffer allocated by the caller

    @return
    0 if service is successful, or !0 of the service fails
             
*/
typedef int ( __stdcall MINI_DLL_SVC )( MINI_SESSION* session, 
                                        int argc, char** argv,  
                                        char** buff, int* size, 
                                        char* msg, int msglen );

/**
    Prototype for a message listener

    @param  message   Message container
    @param  msg       Error message. Buffer allocated by the caller.
    @param  msglen    Maximum size of error message, equals the size of the buffer allocated by the caller

    @return
    0 if listener is successful, or !0 of the listener fails
             
*/
typedef int ( __stdcall MINI_DLL_LISTENER )( MINI_MESSAGE* message,
                                                char* errmsg, int errmsglen );


#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* mini_h */