Создание  
  О компании  Программ Устройств   Linux    
  Контакты   Обучение  
    Инвестиционные проекты

LsoL

  Обслуживание    
  Продукция     Советы  
   

Модуль HTTP сервера


Contents:

Overview

Возможности:
  • Разбор параметров запроса.
  • Предоставление параметров в удобном виде.
  • По входящему запроса вызов калбэк функции.
  • Возврат данных от хост программы.
  • Возврат файлов,
  • Обработка SSI страниц, включения в SSI данных от хост программы.
  • Запуск и обработка CGI скриптов
  • Загрузка, исполнение, ISAPI библиотек.
  • Подключается как DLL.
    Заголовочный файл (хидер)      





    :


  • Usage





    This is HTTP server.
    For it just call SetHTTPServer. The callback function will call when somebody required anything from server.
    The host program may just return zero by this callback, and in this case the server will work with this request.
    The host program may return the error code, and in this case request will be declined.
    The host program may get http control withelp GetHTTPControl and request params withelp GetRequestVar and return anything to the client withelp SRVSend ot SRVprintf functions.




    Functios









    type of stream
    typedef void * ServerStream;



    HTTPReqCallback
    type for callback function that will call for each request, after request recived, before server do anything other.
    typedef int (* HTTPReqCallback)(ServerStream * stream, char * reqname, int method);
    Parameters:
    The stream may be used by host program for next request.
    The reqname it is name of requested flie.
    The method defined there: METHOD_GET METHOD_POST METHOD_HEAD
    Return value:
    If this callback return zero, the server will still work the request.
    If this callback return subzero the server understan that host program
    If this callback return value above zero, the server return it to client as error code and return error page.


    SetHTTPServer
    The host program must only call SetHTTPServer function, that create server thread
    int SetHTTPServer(HTTPReqCallback callback=NULL, int port=0);
    Parameters:
    The callback -- callback function that will call for each request, after request recived, before server do anything other
    by default NULL -- int this case the server will just work with request.
    The port -- TCP/IP port. If used default value zero, the server use value from config, by default 80.
    Return value:
    Zero if sucess.
    Subzero if fail



    SRVSendHead
    Required to send http control header before send reply. For it you may use next function:
    int SRVSendHead(ServerStream * stream, int code=200, char * content_type="text/html", char * advanced=NULL, ...);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    The code by default 200 mean sucess.
    The content_type -- type of reply.
    advanced -- advanced header field in format "Name: Value" and NULL after the last param.
    Return value:
    Zero if sucess.
    Subzero if fail


    If the method was POST server will not load POST before callback didn't call next function.
    SRVLoadPost
    After call all POST vars will be avilable by GetRequestVar function.
    int SRVLoadPost();
    Return value:
    Zero if sucess.
    Subzero if fail


    SRVSend
    The host program may send data to the client with next functions:
    int SRVSend(ServerStream * stream, void * bufer, int size);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    The bufer -- bufer to send
    The size -- size of bufer
    Return value:
    Number of bytes that has been send.
    Zero if error

    SRVprintf

    int SRVprintf(ServerStream * stream, char * format, ...);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    The format -- format like in stdio printf
    ... params by format
    Return value:
    Number of bytes that has been send.
    Zero if error


    SRVRecv
    If you would like reveive the data yourself, without SRVLoadPost you may use SRVRecv:
    int SRVRecv(ServerStream * stream, void * bufer, int l);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    The bufer -- bufer to recive
    The size -- size of bufer
    Return value:
    Number of bytes that has been recive.
    Zero if error


    GetHTTPControl
    To get param from HTTP control header you may use next function:
    char * GetHTTPControl(ServerStream * stream, char * control );
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    control -- the name of required control
    Return value:
    pointer to the string with value.
    The NULL pointer if no control present.


    GetRequestVar
    To get param from request you may use next function:
    char * GetRequestVar(ServerStream * stream, char * var );
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    var -- the name of required variable
    Return value:
    pointer to the string with value.
    The NULL pointer if no control present.



    GetAUTHName
    To get info about autorization use next functions:
    char * GetAUTHName(ServerStream * stream);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    Return value:
    pointer to user name.
    GetAUTHPassw
    The NULL pointer if no control present.
    char * GetAUTHPassw(ServerStream * stream);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    Return value:
    pointer to password.
    The NULL pointer if no control present.



    Advanced info about connection you may get with next functions.
    GetRemoteIP

    ulong GetRemoteIP(ServerStream * stream);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    Return value:
    IP address of remote.

    GetRemoteAddr

    int GetRemoteAddr(void * addr, int buflen);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    Return value:
    address of remote.in sockaddr struct
    GetSocket

    int GetSocket(ServerStream * stream);
    Parameters:
    The stream -- pointer to stream that was transfer to callback function.
    Return value:
    socket


    The host program may load all params for module from separate file,
    LoadConfig
    or my set required params directly, or use default values.
    int LoadConfig(char * filename="http.cfg");
    Parameters:
    The filename -- name of configuration file.
    Return value:
    Zero if sucess.
    Subzero if fail


    SetConfigParam
    You may set all params directly:
    void SetConfigParam(char * param, int val);
    Parameters:
    The param -- name of param
    val -- value.
    SetConfigParam

    void SetConfigParam(char * param, char * val);
    Parameters:
    The param -- name of param
    val -- value.

    To get current values of configuration params you may use next functions:
    GetConfigParamInt
    For integer params:
    int GetConfigParamInt(char * param);
    Parameters:
    The param -- name of param

    SetConfigParamStr
    For string params:
    char *SetConfigParamStr(char * param);
    Parameters:
    The param -- name of param