1
diff -u /usr/local/src/jabberd-2.0s6/c2s/c2s.c c2s/c2s.c
2
--- /usr/local/src/jabberd-2.0s6/c2s/c2s.c Thu Dec 23 19:42:29 2004
3
+++ c2s/c2s.c Thu Dec 23 19:41:20 2004
9
+ * M.Bootsma, LogicaCMG Hoofddorp, Netherlands
12
+ * Added a patch for flash:stream support
14
+ * Flash is not 100% compatible with the XML stream standard:
15
+ * 1. it terminates every XML message with a '\0'
16
+ * 2. it terminates the stream header with a /
17
+ * (this would close the stream)
18
+ * 3. it starts the stream with a flash:stream header instead of
19
+ * a stream:stream header.
21
+ * The patch checks the first message of a starting session stream
22
+ * for any '\0'. If found it flags the session as a Flash session
23
+ * and replases the complete header with a Jabber compatible
25
+ * After that every incoming message is filtered and '\0' is
26
+ * replaced with ' '.
27
+ * For every outgoing message, a '\0' is appended and the response
28
+ * of the header is replaced for a flash friendly version
30
+ * The whole flash patch can be switched off by undefining CP2005_FLASH_PATCH
34
+#ifdef CP2005_FLASH_PATCH
36
+#define FLASH_BUFFER_SIZE 256
38
+static const char caStreamHeader [] = "<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='%s' >";
39
+static const char caFlashHeader [] = "<?xml version='1.0'?><flash:stream xmlns:flash='http://www.jabber.com/streams/flash' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' from='%s' id='%s' />";
41
+static void ExtractValue(char *pMessage, char *pVariable, char *pValue) {
47
+ * extract the value of an attribute from a XML message
48
+ * eg: <.... id='1234567890' ....> returns 1234567890
51
+ p = strstr(pMessage, pVariable);
53
+ p += (strlen(pVariable) + 1);
54
+ /* find end of value, search for closing ' or " */
55
+ pEnd = strchr(p, p [-1]);
57
+ if (iLen < FLASH_BUFFER_SIZE) {
58
+ memcpy(pValue, p, iLen);
59
+ pValue[iLen] = '\0';
60
+ log_debug(ZONE, "++++ Extracted Var %s: [%s]\n", pVariable, pValue);
67
static int _c2s_client_sx_callback(sx_t s, sx_event_t e, void *data, void *arg) {
68
sess_t sess = (sess_t) arg;
69
sx_buf_t buf = (sx_buf_t) data;
74
+#ifdef CP2005_FLASH_PATCH
76
+ char caHost[FLASH_BUFFER_SIZE];
77
+ char caID[FLASH_BUFFER_SIZE];
82
log_debug(ZONE, "want read");
87
- log_debug(ZONE, "read %d bytes", len);
91
+#ifdef CP2005_FLASH_PATCH
92
+ /* check for 0 bytes in the first packet
93
+ * if found it must be a flash client
94
+ * remove any 0 in the data and
95
+ * the / that ends the <?xml... header
98
+ pEnd = &buf->data[len];
100
+ if (sess->s->state == state_NONE) {
101
+ /* stream is new, look for 0 bytes */
102
+ p = memchr(buf->data, '\0', buf->len);
103
+ if ((p != NULL) && (p < pEnd)) {
104
+ log_debug(ZONE, "++++ Flash Stream detected\n%.*s", buf->len, buf->data);
105
+ sess->flash_client = 1;
107
+ /* extract destination host */
108
+ ExtractValue(buf->data, "to=", caHost);
110
+ /* create normal stream:stream header, resize data buffer first */
111
+ _sx_buffer_alloc_margin(buf, 0, sizeof(caStreamHeader) + strlen(caHost) + 8);
112
+ sprintf(buf->data, caStreamHeader, caHost);
113
+ buf->len = strlen(buf->data);
115
+ log_debug(ZONE, "++++ Converted to\n%.*s", buf->len, buf->data);
119
+ /* Check all other messages in the stream to remove \0's etc */
120
+ if (sess->flash_client)
121
+ /* remove 0's from flash packets */
122
+ for (p = buf->data; p < pEnd; p++)
126
+ log_debug(ZONE, "read %d bytes", len);
131
log_debug(ZONE, "writing to %d", sess->fd->fd);
133
+#ifdef CP2005_FLASH_PATCH
134
+ if (sess->flash_client) {
135
+ /* look for the header <? xml ...*/
136
+ if (strncmp(buf->data, "<?xml ", 6) == 0) {
137
+ /* replace normal stream header with flash friendly header */
138
+ log_debug(ZONE, "++++ Found <?xml..., \n%.*s", buf->len, buf->data);
140
+ /* extract id from id="123456567778765" or id='45454545454' */
141
+ ExtractValue(buf->data, "from=", caHost);
142
+ ExtractValue(buf->data, "id=", caID);
144
+ /* create flash:stream header, realloc buffer first */
145
+ _sx_buffer_alloc_margin(buf, 0, sizeof(caFlashHeader) + strlen(caHost) + strlen(caID) + 8);
146
+ sprintf(buf->data, caFlashHeader, caHost, caID);
147
+ buf->len = strlen(buf->data);
149
+ log_debug(ZONE, "++++ Converted to %s", buf->data);
152
+ /* add a 0 to flash packets */
153
+ buf->data[buf->len] = '\0';
158
len = send(sess->fd->fd, buf->data, buf->len, 0);
160
diff -u /usr/local/src/jabberd-2.0s6/c2s/c2s.h c2s/c2s.h
161
--- /usr/local/src/jabberd-2.0s6/c2s/c2s.h Tue Dec 7 18:38:05 2004
162
+++ c2s/c2s.h Thu Dec 23 19:23:47 2004
167
+#ifdef CP2005_FLASH_PATCH
173
int sasl_authd; /* 1 = they did a sasl auth */