aboutsummaryrefslogtreecommitdiff
path: root/Src/replicant/jnetlib/httpuserv.h
blob: d6015067e1b629bef690450dd692d43d0a83b263 (plain) (blame)
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
/*
** JNetLib
** Copyright (C) 2012 Nullsoft, Inc.
** Author: Ben Allison
** File: httpuserv.h - JNL interface for doing HTTPU (HTTP over UDP)
** This is half-baked so far.  Need to think things through a touch more
*/

#pragma once

#include "udpconnection.h"
#include "headers.h"

class JNL_HTTPUServ
{
public:
    JNL_HTTPUServ();
    ~JNL_HTTPUServ();

    // pass this a connection that has just received a packet
    int         process( JNL_UDPConnection *m_con );

    const char *geterrorstr()                                         { return m_errstr; }

    // use these when state returned by run() is 2 
    const char *get_request_uri();                            // file portion of http request
    const char *get_request_parm( const char *parmname );     // parameter portion (after ?)
    const char *getallheaders()                                       { return recvheaders.GetAllHeaders(); } // double null terminated, null delimited list
    const char *getheader( const char *headername );
    const char *get_method()                                          { return m_method; }

    void        set_reply_string( const char *reply_string ); // should be HTTP/1.1 OK or the like
    void        set_reply_header( const char *header );       // i.e. "content-size: 12345"

    void        send_reply( JNL_UDPConnection *m_con );       // sends a reply to the given UDP socket.  it must have been setup beforehand with the appropriate peer

    void reset();                                             // prepare for another request 

    int get_http_version()                                            { return http_ver; }

protected:
    void seterrstr( const char *str )                                 { if ( m_errstr ) free( m_errstr ); m_errstr = _strdup( str ); }

    int          m_reply_ready;
    int          http_ver;

    char        *m_errstr;
    char        *m_reply_headers;
    char        *m_reply_string;
    JNL_Headers  recvheaders;
    char        *m_recv_request; // either double-null terminated, or may contain parameters after first null.
    char        *m_method;
};