1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2018 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Author: Pierrick Charron <pierrick@php.net>                          |
16   +----------------------------------------------------------------------+
17 */
18 
19 /* $Id$ */
20 
21 #ifndef _STOMP_H_
22 #define _STOMP_H_
23 
24 #include "php_network.h"
25 
26 #if HAVE_STOMP_SSL
27 #include <openssl/ssl.h>
28 #endif
29 
30 #define STOMP_BUFSIZE 4096
31 
32 #define INIT_STOMP_FRAME(f) \
33 	f = (stomp_frame_t *) emalloc(sizeof(stomp_frame_t)); \
34 	f->command = NULL; f->body = NULL; \
35 	ALLOC_HASHTABLE(f->headers); \
36 	zend_hash_init(f->headers, 0, NULL, ZVAL_PTR_DTOR, 0);
37 
38 typedef struct _stomp_options {
39 	long connect_timeout_sec;
40 	long connect_timeout_usec;
41 	long read_timeout_sec;
42 	long read_timeout_usec;
43 #if HAVE_STOMP_SSL
44 	int use_ssl;
45 #endif
46 } stomp_options_t;
47 
48 typedef struct _stomp_frame {
49 	char *command;
50 	int command_length;
51 	HashTable *headers;
52 	char *body;
53 	int body_length;
54 } stomp_frame_t;
55 
56 typedef struct _stomp_frame_stack {
57 	stomp_frame_t *frame;
58 	struct _stomp_frame_stack *next;
59 } stomp_frame_stack_t;
60 
61 typedef struct _stomp {
62 	php_socket_t fd;
63 	php_sockaddr_storage localaddr;
64 	stomp_options_t options;
65 	char *host;
66 	unsigned short port;
67 	int status;
68 	char *error;
69 	int errnum;
70 	char *error_details;
71 	char *session;
72 #if HAVE_STOMP_SSL
73 	SSL *ssl_handle;
74 #endif
75 	stomp_frame_stack_t *frame_stack;
76 	struct {
77 		size_t size;
78 		char buf[STOMP_BUFSIZE];
79 		char *pos;
80 	} read_buffer;
81 } stomp_t;
82 
83 stomp_t *stomp_init();
84 int stomp_connect(stomp_t *stomp, const char *host, unsigned short port TSRMLS_DC);
85 void stomp_close(stomp_t *stomp);
86 int stomp_send(stomp_t *connection, stomp_frame_t *frame TSRMLS_DC);
87 stomp_frame_t *stomp_read_frame_ex(stomp_t *connection, int use_stack);
88 int stomp_valid_receipt(stomp_t *connection, stomp_frame_t *frame);
89 int stomp_select_ex(stomp_t *connection, const long int sec, const long int usec);
90 void stomp_set_error(stomp_t *stomp, const char *error, int errnum, const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0);
91 void stomp_free_frame(stomp_frame_t *frame);
92 
93 #define stomp_select(s) stomp_select_ex(s, s->options.read_timeout_sec, s->options.read_timeout_usec)
94 #define stomp_read_frame(c) stomp_read_frame_ex(c, 1)
95 #endif /* _STOMP_H_ */
96 
97 /*
98  * Local variables:
99  * tab-width: 4
100  * c-basic-offset: 4
101  * End:
102  * vim600: noet sw=4 ts=4 fdm=marker
103  * vim<600: noet sw=4 ts=4
104  */
105