ApacheConnector.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // ApacheConnector.h
  3. //
  4. // Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
  5. // and Contributors.
  6. //
  7. // SPDX-License-Identifier: BSL-1.0
  8. //
  9. #ifndef ApacheConnector_ApacheConnector_INCLUDED
  10. #define ApacheConnector_ApacheConnector_INCLUDED
  11. #include <string>
  12. struct request_rec;
  13. class ApacheServerRequest;
  14. class ApacheRequestRec
  15. /// This class wraps an Apache request_rec.
  16. {
  17. public:
  18. ApacheRequestRec(request_rec* _pRec);
  19. /// Creates the ApacheRequestRec;
  20. bool haveRequestBody();
  21. /// Returns true if the request contains a body.
  22. int readRequest(char* buffer, int length);
  23. /// Read up to length bytes from request body into buffer.
  24. /// Returns the number of bytes read, 0 if eof or -1 if an error occured.
  25. void writeResponse(const char* buffer, int length);
  26. /// Writes the given characters as response to the given request_rec.
  27. void addHeader(const std::string& key, const std::string& value);
  28. /// Adds the given key / value pair to the outgoing headers of the
  29. /// http response.
  30. void setContentType(const std::string& mediaType);
  31. /// Sets the response content type.
  32. void redirect(const std::string& uri, int status);
  33. /// Redirects the response to the given uri.
  34. void sendErrorResponse(int status);
  35. /// Sends an error response with the given HTTP status code.
  36. int sendFile(const std::string& path, unsigned int fileSize, const std::string& mediaType);
  37. /// Sends the file given by fileName as response.
  38. void copyHeaders(ApacheServerRequest& request);
  39. /// Copies the request uri and header fields from the Apache request
  40. /// to the ApacheServerRequest.
  41. bool secure();
  42. /// Returns true if the request is using a secure
  43. /// connection. Returns false if no secure connection
  44. /// is used, or if it is not known whether a secure
  45. /// connection is used.
  46. void setStatus(int status);
  47. /// Set specific HTTP status code for the request.
  48. private:
  49. request_rec* _pRec;
  50. };
  51. class ApacheConnector
  52. /// This class provides static methods wrapping the
  53. /// Apache API.
  54. {
  55. public:
  56. enum LogLevel
  57. {
  58. PRIO_FATAL = 1, /// A fatal error. The application will most likely terminate. This is the highest priority.
  59. PRIO_CRITICAL, /// A critical error. The application might not be able to continue running successfully.
  60. PRIO_ERROR, /// An error. An operation did not complete successfully, but the application as a whole is not affected.
  61. PRIO_WARNING, /// A warning. An operation completed with an unexpected result.
  62. PRIO_NOTICE, /// A notice, which is an information with just a higher priority.
  63. PRIO_INFORMATION, /// An informational message, usually denoting the successful completion of an operation.
  64. PRIO_DEBUG, /// A debugging message.
  65. PRIO_TRACE /// A tracing message. This is the lowest priority.
  66. };
  67. static void log(const char* file, int line, int level, int status, const char* text);
  68. /// Log the given message.
  69. };
  70. #endif // ApacheConnector_ApacheConnector_INCLUDED