~ubuntu-branches/ubuntu/oneiric/jabberd2/oneiric-security

« back to all changes in this revision

Viewing changes to contrib/patch-flash-v2

  • Committer: Bazaar Package Importer
  • Author(s): Nicolai Spohrer
  • Date: 2008-08-12 16:13:43 UTC
  • mfrom: (1.1.3 upstream) (0.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20080812161343-6trz3r97dtevxd17
Tags: 2.2.1-1ubuntu1
* Merge with Debian unstable (LP: #257130), remaining changes:
  - debian/control:
    + Modify Maintainer field as per spec
    + Depend on libdb4.6-dev instead of libdb4.4-dev
    + Added Conflicts and Replaces: ..., jabber for jabberd2
  - debian/rules: Added libtoolize call (jabberd2 ships with
     an older ltmain.sh version that conflicts with the
     current libtool version)
  - debian/init: create /var/run/jabber directory with correct
     permissions
* Dropped changes:
  - Debian already depends on libpq-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
@@ -20,6 +20,65 @@
 
5
 
 
6
 #include "c2s.h"
 
7
 
 
8
+/*
 
9
+ * M.Bootsma, LogicaCMG Hoofddorp, Netherlands
 
10
+ * October 2004
 
11
+ *
 
12
+ * Added a patch for flash:stream support
 
13
+ *
 
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.
 
20
+ *
 
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
 
24
+ * header.
 
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
 
29
+ *
 
30
+ * The whole flash patch can be switched off by undefining CP2005_FLASH_PATCH
 
31
+ * in config.h(.in)
 
32
+ */
 
33
+
 
34
+#ifdef CP2005_FLASH_PATCH
 
35
+
 
36
+#define FLASH_BUFFER_SIZE 256
 
37
+
 
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' />";
 
40
+
 
41
+static void ExtractValue(char *pMessage, char *pVariable, char *pValue) { 
 
42
+    int iLen; 
 
43
+    char *p;
 
44
+    char *pEnd;
 
45
+
 
46
+    /*
 
47
+     * extract the value of an attribute from a XML message
 
48
+     * eg: <.... id='1234567890' ....> returns 1234567890
 
49
+     */
 
50
+
 
51
+    p = strstr(pMessage, pVariable);
 
52
+    if (p != NULL) {
 
53
+        p += (strlen(pVariable) + 1);
 
54
+        /* find end of value, search for closing ' or " */
 
55
+        pEnd = strchr(p, p [-1]);
 
56
+        iLen = pEnd - p;
 
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);
 
61
+        }
 
62
+    }
 
63
+}
 
64
+#endif
 
65
+
 
66
+
 
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;
 
70
@@ -28,6 +93,12 @@
 
71
     nad_t nad;
 
72
     char root[9];
 
73
 
 
74
+#ifdef CP2005_FLASH_PATCH
 
75
+    char *p, *pEnd;
 
76
+    char caHost[FLASH_BUFFER_SIZE];
 
77
+    char caID[FLASH_BUFFER_SIZE];
 
78
+#endif
 
79
+
 
80
     switch(e) {
 
81
         case event_WANT_READ:
 
82
             log_debug(ZONE, "want read");
 
83
@@ -94,14 +165,74 @@
 
84
                 return -1;
 
85
             }
 
86
 
 
87
-            log_debug(ZONE, "read %d bytes", len);
 
88
-
 
89
             buf->len = len;
 
90
 
 
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
 
96
+             */
 
97
+
 
98
+            pEnd = &buf->data[len];
 
99
+
 
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;
 
106
+
 
107
+                    /* extract destination host */
 
108
+                    ExtractValue(buf->data, "to=", caHost);
 
109
+
 
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);
 
114
+
 
115
+                    log_debug(ZONE, "++++ Converted to\n%.*s", buf->len, buf->data);
 
116
+                }
 
117
+            }
 
118
+
 
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++)
 
123
+                    if (*p == '\0')
 
124
+                        *p = ' ';
 
125
+#endif
 
126
+            log_debug(ZONE, "read %d bytes", len);
 
127
+
 
128
             return len;
 
129
 
 
130
         case event_WRITE:
 
131
             log_debug(ZONE, "writing to %d", sess->fd->fd);
 
132
+
 
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);
 
139
+
 
140
+                    /* extract id from id="123456567778765" or id='45454545454' */
 
141
+                    ExtractValue(buf->data, "from=", caHost);
 
142
+                    ExtractValue(buf->data, "id=", caID);
 
143
+
 
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);
 
148
+
 
149
+                    log_debug(ZONE, "++++ Converted to %s", buf->data);
 
150
+                }
 
151
+
 
152
+                /* add a 0 to flash packets */
 
153
+                buf->data[buf->len] = '\0';
 
154
+                buf->len++;
 
155
+            }
 
156
+#endif
 
157
 
 
158
             len = send(sess->fd->fd, buf->data, buf->len, 0);
 
159
             if(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
 
163
@@ -62,6 +62,10 @@
 
164
     int                 bound;
 
165
     int                 active;
 
166
 
 
167
+#ifdef CP2005_FLASH_PATCH
 
168
+    int                 flash_client;
 
169
+#endif
 
170
+
 
171
     nad_t               result;
 
172
 
 
173
     int                 sasl_authd;     /* 1 = they did a sasl auth */