oversip 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/AUTHORS.txt +11 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +16 -0
  4. data/Rakefile +55 -0
  5. data/bin/oversip +182 -0
  6. data/ext/common/c_util.h +74 -0
  7. data/ext/common/ruby_c_util.h +88 -0
  8. data/ext/sip_parser/common_headers.h +209 -0
  9. data/ext/sip_parser/ext_help.h +18 -0
  10. data/ext/sip_parser/extconf.rb +3 -0
  11. data/ext/sip_parser/sip_parser.c +29649 -0
  12. data/ext/sip_parser/sip_parser.h +227 -0
  13. data/ext/sip_parser/sip_parser_ruby.c +1292 -0
  14. data/ext/stud/extconf.rb +27 -0
  15. data/ext/stud/stud.tar.gz +0 -0
  16. data/ext/stun/ext_help.h +16 -0
  17. data/ext/stun/extconf.rb +3 -0
  18. data/ext/stun/stun_ruby.c +391 -0
  19. data/ext/utils/ext_help.h +14 -0
  20. data/ext/utils/extconf.rb +3 -0
  21. data/ext/utils/haproxy_protocol.c +6163 -0
  22. data/ext/utils/haproxy_protocol.h +27 -0
  23. data/ext/utils/ip_utils.c +5952 -0
  24. data/ext/utils/ip_utils.h +61 -0
  25. data/ext/utils/outbound_utils.c +3227 -0
  26. data/ext/utils/outbound_utils.h +27 -0
  27. data/ext/utils/utils_ruby.c +384 -0
  28. data/ext/utils/utils_ruby.h +75 -0
  29. data/ext/websocket_framing_utils/ext_help.h +18 -0
  30. data/ext/websocket_framing_utils/extconf.rb +3 -0
  31. data/ext/websocket_framing_utils/ws_framing_utils.h +46 -0
  32. data/ext/websocket_framing_utils/ws_framing_utils_ruby.c +135 -0
  33. data/ext/websocket_http_parser/ext_help.h +18 -0
  34. data/ext/websocket_http_parser/extconf.rb +3 -0
  35. data/ext/websocket_http_parser/ws_http_parser.c +2598 -0
  36. data/ext/websocket_http_parser/ws_http_parser.h +86 -0
  37. data/ext/websocket_http_parser/ws_http_parser_ruby.c +630 -0
  38. data/lib/oversip/config.rb +541 -0
  39. data/lib/oversip/config_validators.rb +126 -0
  40. data/lib/oversip/errors.rb +7 -0
  41. data/lib/oversip/fiber_pool.rb +56 -0
  42. data/lib/oversip/launcher.rb +507 -0
  43. data/lib/oversip/logger.rb +170 -0
  44. data/lib/oversip/master_process.rb +67 -0
  45. data/lib/oversip/posix_mq.rb +121 -0
  46. data/lib/oversip/proxies_config.rb +169 -0
  47. data/lib/oversip/ruby_ext/eventmachine.rb +38 -0
  48. data/lib/oversip/sip/client_transaction.rb +587 -0
  49. data/lib/oversip/sip/constants.rb +87 -0
  50. data/lib/oversip/sip/grammar/name_addr.rb +27 -0
  51. data/lib/oversip/sip/grammar/uri.rb +116 -0
  52. data/lib/oversip/sip/launcher.rb +180 -0
  53. data/lib/oversip/sip/listeners/ipv4_tcp_client.rb +21 -0
  54. data/lib/oversip/sip/listeners/ipv4_tcp_server.rb +21 -0
  55. data/lib/oversip/sip/listeners/ipv4_tls_client.rb +21 -0
  56. data/lib/oversip/sip/listeners/ipv4_tls_server.rb +21 -0
  57. data/lib/oversip/sip/listeners/ipv4_tls_tunnel_server.rb +21 -0
  58. data/lib/oversip/sip/listeners/ipv4_udp_server.rb +20 -0
  59. data/lib/oversip/sip/listeners/ipv6_tcp_client.rb +21 -0
  60. data/lib/oversip/sip/listeners/ipv6_tcp_server.rb +21 -0
  61. data/lib/oversip/sip/listeners/ipv6_tls_client.rb +21 -0
  62. data/lib/oversip/sip/listeners/ipv6_tls_server.rb +21 -0
  63. data/lib/oversip/sip/listeners/ipv6_tls_tunnel_server.rb +21 -0
  64. data/lib/oversip/sip/listeners/ipv6_udp_server.rb +20 -0
  65. data/lib/oversip/sip/listeners/reactor.rb +39 -0
  66. data/lib/oversip/sip/listeners/tcp_client.rb +73 -0
  67. data/lib/oversip/sip/listeners/tcp_reactor.rb +185 -0
  68. data/lib/oversip/sip/listeners/tcp_server.rb +71 -0
  69. data/lib/oversip/sip/listeners/tls_client.rb +117 -0
  70. data/lib/oversip/sip/listeners/tls_server.rb +70 -0
  71. data/lib/oversip/sip/listeners/tls_tunnel_reactor.rb +113 -0
  72. data/lib/oversip/sip/listeners/tls_tunnel_server.rb +61 -0
  73. data/lib/oversip/sip/listeners/udp_reactor.rb +213 -0
  74. data/lib/oversip/sip/listeners.rb +28 -0
  75. data/lib/oversip/sip/logic.rb +14 -0
  76. data/lib/oversip/sip/message.rb +168 -0
  77. data/lib/oversip/sip/message_processor.rb +202 -0
  78. data/lib/oversip/sip/modules/core.rb +200 -0
  79. data/lib/oversip/sip/modules/registrar_without_path.rb +75 -0
  80. data/lib/oversip/sip/modules/user_assertion.rb +123 -0
  81. data/lib/oversip/sip/proxy.rb +460 -0
  82. data/lib/oversip/sip/request.rb +128 -0
  83. data/lib/oversip/sip/response.rb +30 -0
  84. data/lib/oversip/sip/rfc3263.rb +646 -0
  85. data/lib/oversip/sip/server_transaction.rb +295 -0
  86. data/lib/oversip/sip/sip.rb +74 -0
  87. data/lib/oversip/sip/tags.rb +39 -0
  88. data/lib/oversip/sip/timers.rb +55 -0
  89. data/lib/oversip/sip/transport_manager.rb +129 -0
  90. data/lib/oversip/syslogger_process.rb +119 -0
  91. data/lib/oversip/tls.rb +179 -0
  92. data/lib/oversip/utils.rb +25 -0
  93. data/lib/oversip/version.rb +23 -0
  94. data/lib/oversip/websocket/constants.rb +56 -0
  95. data/lib/oversip/websocket/default_policy.rb +19 -0
  96. data/lib/oversip/websocket/http_request.rb +63 -0
  97. data/lib/oversip/websocket/launcher.rb +207 -0
  98. data/lib/oversip/websocket/listeners/ipv4_tcp_server.rb +15 -0
  99. data/lib/oversip/websocket/listeners/ipv4_tls_server.rb +15 -0
  100. data/lib/oversip/websocket/listeners/ipv4_tls_tunnel_server.rb +15 -0
  101. data/lib/oversip/websocket/listeners/ipv6_tcp_server.rb +15 -0
  102. data/lib/oversip/websocket/listeners/ipv6_tls_server.rb +15 -0
  103. data/lib/oversip/websocket/listeners/ipv6_tls_tunnel_server.rb +15 -0
  104. data/lib/oversip/websocket/listeners/tcp_server.rb +265 -0
  105. data/lib/oversip/websocket/listeners/tls_server.rb +69 -0
  106. data/lib/oversip/websocket/listeners/tls_tunnel_server.rb +100 -0
  107. data/lib/oversip/websocket/listeners.rb +12 -0
  108. data/lib/oversip/websocket/ws_app.rb +75 -0
  109. data/lib/oversip/websocket/ws_apps/ipv4_ws_sip_app.rb +21 -0
  110. data/lib/oversip/websocket/ws_apps/ipv4_wss_sip_app.rb +21 -0
  111. data/lib/oversip/websocket/ws_apps/ipv6_ws_sip_app.rb +21 -0
  112. data/lib/oversip/websocket/ws_apps/ipv6_wss_sip_app.rb +22 -0
  113. data/lib/oversip/websocket/ws_apps/ws_autobahn_app.rb +23 -0
  114. data/lib/oversip/websocket/ws_apps/ws_sip_app.rb +156 -0
  115. data/lib/oversip/websocket/ws_apps.rb +9 -0
  116. data/lib/oversip/websocket/ws_framing.rb +597 -0
  117. data/lib/oversip.rb +59 -0
  118. data/test/oversip_test_helper.rb +20 -0
  119. data/test/test_http_parser.rb +73 -0
  120. data/test/test_sip_parser.rb +139 -0
  121. metadata +256 -0
@@ -0,0 +1,227 @@
1
+ #ifndef sip_parser_h
2
+ #define sip_parser_h
3
+
4
+
5
+ #include <ruby.h>
6
+ #include <sys/types.h>
7
+
8
+
9
+ enum data_type {
10
+ sip_request = 1,
11
+ sip_response,
12
+ outbound_keepalive
13
+ };
14
+
15
+ enum method {
16
+ method_INVITE = 1,
17
+ method_ACK,
18
+ method_CANCEL,
19
+ method_PRACK,
20
+ method_BYE,
21
+ method_REFER,
22
+ method_INFO,
23
+ method_UPDATE,
24
+ method_OPTIONS,
25
+ method_REGISTER,
26
+ method_MESSAGE,
27
+ method_SUBSCRIBE,
28
+ method_NOTIFY,
29
+ method_PUBLISH,
30
+ method_PULL,
31
+ method_PUSH,
32
+ method_STORE,
33
+ method_unknown
34
+ };
35
+
36
+ enum component {
37
+ component_ruri = 1,
38
+ component_from,
39
+ component_to,
40
+ component_route,
41
+ component_route_uri,
42
+ component_contact
43
+ };
44
+
45
+ enum uri_owner {
46
+ uri_owner_ruri = 1,
47
+ uri_owner_from,
48
+ uri_owner_to,
49
+ uri_owner_route,
50
+ uri_owner_contact
51
+ };
52
+
53
+ enum uri_scheme {
54
+ uri_scheme_sip = 1,
55
+ uri_scheme_sips,
56
+ uri_scheme_tel,
57
+ uri_scheme_unknown
58
+ };
59
+
60
+ enum uri_param_name {
61
+ uri_param_transport = 1,
62
+ uri_param_lr,
63
+ uri_param_ob,
64
+ uri_param_ovid,
65
+ uri_tel_phone_context
66
+ };
67
+
68
+ enum host_type {
69
+ host_type_domain = 1,
70
+ host_type_ipv4,
71
+ host_type_ipv6
72
+ };
73
+
74
+ enum header_field {
75
+ header_field_any = 0,
76
+ header_field_via,
77
+ header_field_from,
78
+ header_field_to,
79
+ header_field_route,
80
+ header_field_supported,
81
+ header_field_require,
82
+ header_field_proxy_require,
83
+ header_field_contact
84
+ };
85
+
86
+ enum transport {
87
+ transport_udp = 1,
88
+ transport_tcp,
89
+ transport_tls,
90
+ transport_sctp,
91
+ transport_ws,
92
+ transport_wss,
93
+ transport_unknown
94
+ };
95
+
96
+ typedef void (*data_type_cb)(void *parser, enum data_type value);
97
+ typedef void (*msg_method_cb)(VALUE parsed, const char *at, size_t length, enum method method);
98
+ typedef void (*msg_element_cb)(VALUE parsed, const char *at, size_t length);
99
+ typedef void (*msg_has_param_cb)(VALUE parsed);
100
+ typedef void (*header_core_value_cb)(VALUE parsed, enum header_field header_field, const char *at, size_t length);
101
+ typedef void (*header_param_cb)(VALUE parsed, enum header_field header_field, const char *key, size_t key_len, const char *value, size_t value_len);
102
+ typedef void (*header_cb)(VALUE parsed, const char *hdr_field, size_t hdr_field_len, const char *hdr_value, size_t hdr_value_len, enum header_field hdr_field_name);
103
+ typedef void (*uri_element_cb)(VALUE parsed, enum uri_owner owner, const char *at, size_t length, enum uri_scheme);
104
+ typedef void (*uri_element2_cb)(VALUE parsed, enum uri_owner owner, const char *at, size_t length, int type);
105
+ typedef void (*uri_param_cb)(VALUE parsed, enum uri_owner owner, const char *key, size_t key_len, const char *value, size_t value_len);
106
+ typedef void (*uri_known_param_cb)(VALUE parsed, enum uri_owner owner, enum uri_param_name, const char *at, size_t length, int uri_param_value);
107
+ typedef void (*uri_has_param_cb)(VALUE parsed, enum uri_owner, enum uri_param_name);
108
+ typedef void (*option_tag_cb)(VALUE parsed, enum header_field, const char *at, size_t length);
109
+ typedef void (*init_component_cb)(VALUE parsed, enum component);
110
+
111
+
112
+ typedef struct struct_message {
113
+ msg_method_cb method;
114
+ msg_element_cb sip_version;
115
+ msg_element_cb status_code;
116
+ msg_element_cb reason_phrase;
117
+ msg_element_cb via_sent_by_host;
118
+ msg_element_cb via_sent_by_port;
119
+ msg_element_cb via_branch;
120
+ msg_element_cb via_branch_rfc3261;
121
+ msg_element_cb via_received;
122
+ msg_has_param_cb via_has_rport;
123
+ msg_has_param_cb via_has_alias;
124
+ msg_element_cb call_id;
125
+ msg_element_cb cseq_number;
126
+ msg_element_cb max_forwards;
127
+ msg_element_cb content_length;
128
+ msg_element_cb from_tag;
129
+ msg_element_cb to_tag;
130
+ msg_element_cb contact_params;
131
+ /* Header value without header params. */
132
+ header_core_value_cb header_core_value;
133
+ header_param_cb header_param;
134
+ option_tag_cb option_tag;
135
+ init_component_cb init_component;
136
+ } struct_message;
137
+
138
+ typedef struct struct_uri {
139
+ uri_element_cb full;
140
+ uri_element_cb scheme;
141
+ uri_element_cb user;
142
+ uri_element2_cb host;
143
+ uri_element_cb port;
144
+ uri_param_cb param;
145
+ uri_known_param_cb known_param;
146
+ uri_has_param_cb has_param;
147
+ uri_element_cb headers;
148
+ uri_element_cb display_name;
149
+ } struct_uri;
150
+
151
+ typedef struct sip_message_parser {
152
+ /* Parser stuf. */
153
+ int cs;
154
+ size_t nread;
155
+ char * error_start;
156
+ size_t error_len;
157
+ int error_pos;
158
+
159
+ size_t mark;
160
+ size_t hdr_field_start;
161
+ size_t hdr_field_len;
162
+ size_t hdr_value_start;
163
+ size_t hdr_value_len;
164
+ enum header_field hdr_field_name;
165
+ size_t uri_start;
166
+ /* URI parameters. */
167
+ size_t uri_param_key_start;
168
+ size_t uri_param_key_len;
169
+ size_t uri_param_value_start;
170
+ size_t uri_param_value_len;
171
+ /* Header parameters. */
172
+ size_t header_param_key_start;
173
+ size_t header_param_key_len;
174
+ size_t header_param_value_start;
175
+ size_t header_param_value_len;
176
+
177
+ /* Method which set parser->parsed as OverSIP::SIP::Request, OverSIP::SIP::Response or
178
+ * :outbound_keepalive. */
179
+ data_type_cb data_type;
180
+ /* Message method. */
181
+ enum method method;
182
+ /* Method already set. */
183
+ size_t method_set;
184
+ /* Just take top most Via data. */
185
+ size_t num_via;
186
+ /* Don't allow duplicate headers (From, To, Call-ID, CSeq, Max-Forwards and Content-Length). */
187
+ size_t num_from;
188
+ size_t num_to;
189
+ size_t num_call_id;
190
+ size_t num_cseq;
191
+ size_t num_max_forwards;
192
+ size_t num_content_length;
193
+ size_t num_contact;
194
+ int contact_is_valid;
195
+ /* If a previous Route was found then don't re-initialize the ruby @route array. */
196
+ size_t route_found;
197
+ /* Set it before parsing a desired URI. */
198
+ size_t do_uri;
199
+ /* The header (or request line) the URI belongs to. */
200
+ enum uri_owner uri_owner;
201
+ /* URI scheme type. */
202
+ enum uri_scheme uri_scheme;
203
+ /* URI display name is quoted. */
204
+ size_t uri_display_name_quoted;
205
+
206
+ header_cb header;
207
+ struct_message message;
208
+ struct_uri uri;
209
+
210
+ /* Can be set to OverSIP::SIP::Request, OverSIP::SIP::Response or :outbound_keepalive or nil. */
211
+ VALUE parsed;
212
+
213
+ /* A pointer to the Ruby OverSIP::SIP::MessageParser instance (required by data_type() in
214
+ * sip_parser_ruby.c). */
215
+ VALUE ruby_sip_parser;
216
+ } sip_message_parser;
217
+
218
+
219
+ int sip_message_parser_init(sip_message_parser *parser);
220
+ int sip_message_parser_finish(sip_message_parser *parser);
221
+ size_t sip_message_parser_execute(sip_message_parser *parser, const char *buffer, size_t len, size_t off);
222
+ int sip_message_parser_has_error(sip_message_parser *parser);
223
+ int sip_message_parser_is_finished(sip_message_parser *parser);
224
+ #define sip_message_parser_nread(parser) (parser)->nread
225
+
226
+
227
+ #endif