1
0

httpuserv.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. ** JNetLib
  3. ** Copyright (C) 2012 Nullsoft, Inc.
  4. ** Author: Ben Allison
  5. ** File: httpuserv.h - JNL interface for doing HTTPU (HTTP over UDP)
  6. ** This is half-baked so far. Need to think things through a touch more
  7. */
  8. #pragma once
  9. #include "udpconnection.h"
  10. #include "headers.h"
  11. class JNL_HTTPUServ
  12. {
  13. public:
  14. JNL_HTTPUServ();
  15. ~JNL_HTTPUServ();
  16. // pass this a connection that has just received a packet
  17. int process( JNL_UDPConnection *m_con );
  18. const char *geterrorstr() { return m_errstr; }
  19. // use these when state returned by run() is 2
  20. const char *get_request_uri(); // file portion of http request
  21. const char *get_request_parm( const char *parmname ); // parameter portion (after ?)
  22. const char *getallheaders() { return recvheaders.GetAllHeaders(); } // double null terminated, null delimited list
  23. const char *getheader( const char *headername );
  24. const char *get_method() { return m_method; }
  25. void set_reply_string( const char *reply_string ); // should be HTTP/1.1 OK or the like
  26. void set_reply_header( const char *header ); // i.e. "content-size: 12345"
  27. 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
  28. void reset(); // prepare for another request
  29. int get_http_version() { return http_ver; }
  30. protected:
  31. void seterrstr( const char *str ) { if ( m_errstr ) free( m_errstr ); m_errstr = _strdup( str ); }
  32. int m_reply_ready;
  33. int http_ver;
  34. char *m_errstr;
  35. char *m_reply_headers;
  36. char *m_reply_string;
  37. JNL_Headers recvheaders;
  38. char *m_recv_request; // either double-null terminated, or may contain parameters after first null.
  39. char *m_method;
  40. };