PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/server/src/connectors/apache/apache-modules/mod_jaxer1.3/mod_jaxer_message.h

https://github.com/absynce/Jaxer
C Header | 150 lines | 24 code | 27 blank | 99 comment | 0 complexity | 913519860dc6b6236043d11c29200ad1 MD5 | raw file
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. * vim: set sw=4 ts=4 et: */
  3. /* ***** BEGIN LICENSE BLOCK *****
  4. * Version: GPL 3
  5. *
  6. * This program is Copyright (C) 2007-2008 Aptana, Inc. All Rights Reserved
  7. * This program is licensed under the GNU General Public license, version 3 (GPL).
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  12. * NONINFRINGEMENT. Redistribution, except as permitted by the GPL,
  13. * is prohibited.
  14. *
  15. * You can redistribute and/or modify this program under the terms of the GPL,
  16. * as published by the Free Software Foundation. You should
  17. * have received a copy of the GNU General Public License, Version 3 along
  18. * with this program; if not, write to the Free Software Foundation, Inc., 51
  19. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Aptana provides a special exception to allow redistribution of this file
  22. * with certain other code and certain additional terms
  23. * pursuant to Section 7 of the GPL. You may view the exception and these
  24. * terms on the web at http://www.aptana.com/legal/gpl/.
  25. *
  26. * You may view the GPL, and Aptana's exception and additional terms in the file
  27. * titled license-jaxer.html in the main distribution folder of this program.
  28. *
  29. * Any modifications to this file must keep this entire header intact.
  30. *
  31. * ***** END LICENSE BLOCK ***** */
  32. #ifndef __MOD_JAXER_MESSAGE__H
  33. #define __MOD_JAXER_MESSAGE__H
  34. #include "apr_user.h"
  35. #include "mod_jaxer_protocol.h"
  36. /*
  37. * Help functions to manipulate a buffer that follow the Jaxer protocol.
  38. * The first bytes of the buffer contains the Jaxer_Header.
  39. * Most functions takes a point to the buffer and a point to an offset. The offset
  40. * will be updated upon return.
  41. */
  42. /*
  43. * Set the block type to msgtype, set *pos to the end of the Jaxer_Header for appending
  44. */
  45. void jxr_msg_init(unsigned char* buf, apr_size_t *pos, char msgtype);
  46. /**
  47. * For a packet to be sent to the web server, finish the process of
  48. * accumulating data and write the length of the data payload into
  49. * the header.
  50. */
  51. void jxr_msg_end(unsigned char* buf, apr_size_t *pos);
  52. void jxr_msg_reset_pos(apr_size_t *pos);
  53. /**
  54. * Add a short integer (2 bytes) to the message.
  55. */
  56. void jxr_msg_append_int16(unsigned char* buf, apr_size_t *pos, int val);
  57. /**
  58. * Append a byte (1 byte) to the message.
  59. */
  60. void jxr_msg_append_byte(unsigned char* buf, apr_size_t *pos, int val);
  61. /**
  62. * Append an int (4 bytes) to the message.
  63. */
  64. void jxr_msg_append_int32(unsigned char* buf, apr_size_t *pos, int val);
  65. /**
  66. * Write a String out at the current write position. Strings are
  67. * encoded with the length in two bytes first, then the string.
  68. * There is no NULL terminating the string.
  69. */
  70. void jxr_msg_append_string(unsigned char* buf, apr_size_t *pos, unsigned char* str);
  71. /**
  72. * Copy a chunk of bytes into the packet, starting at the current
  73. * write position. The chunk of bytes is encoded with the length
  74. * in two bytes first, then the data itself.
  75. *
  76. * @param b The array from which to copy bytes.
  77. * @param off The offset into the array at which to start copying
  78. * @param numBytes The number of bytes to copy.
  79. */
  80. void jxr_msg_append_bytes(unsigned char* buf, apr_size_t *pos, unsigned char* b, apr_size_t off, apr_size_t numBytes);
  81. /**
  82. * Read an integer from packet, and advance the read position past
  83. * it. Integers are encoded as two unsigned bytes with the
  84. * high-order byte first.
  85. */
  86. int jxr_msg_get_int16(unsigned char* buf, apr_size_t *pos);
  87. /**
  88. * Like read, except do not advance *pos
  89. */
  90. int jxr_msg_peek_int16(unsigned char* buf, apr_size_t pos);
  91. char jxr_msg_get_byte(unsigned char* buf, apr_size_t *pos);
  92. char jxr_msg_peek_byte(unsigned char* buf, apr_size_t *pos);
  93. /**
  94. * Read string from the buffer, and terminate the string with NULL.
  95. * return the string length.
  96. */
  97. apr_size_t jxr_msg_get_string(unsigned char* buf, apr_size_t *pos, unsigned char* dest);
  98. /**
  99. * Copy a chunk of bytes from the packet into an array.
  100. *
  101. * @return The number of bytes copied.
  102. */
  103. apr_size_t jxr_msg_get_bytes(unsigned char* buf, apr_size_t *pos, unsigned char* dest);
  104. /**
  105. * Read a 32 bits integer from packet. Integers are encoded as four unsigned bytes with the
  106. * high-order byte first.
  107. */
  108. int jxr_msg_get_int32(unsigned char* buf, apr_size_t *pos);
  109. /**
  110. * return the constantr size of the Jaxer_Header
  111. */
  112. apr_size_t jxr_msg_get_header_length();
  113. /**
  114. * return the length of the message (after the header), and set *pos to the end of
  115. * the header
  116. */
  117. apr_size_t jxr_msg_get_length(unsigned char*buf, apr_size_t *pos);
  118. /**
  119. * return the message type.
  120. */
  121. char jxr_msg_get_type(unsigned char* buf);
  122. int jxr_init_header(char type, apr_size_t contentLength, Jaxer_Header * header);
  123. #endif //__MOD_JAXER_MESSAGE__H