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

« back to all changes in this revision

Viewing changes to contrib/patch-flash-v3rc1

  • 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
 
--- /home/wolpert/src/jabberd-2.0cvs/c2s/c2s.c  2005-01-07 07:39:20.000000000 -0700
2
 
+++ c2s/c2s.c   2005-02-10 10:48:51.835153956 -0700
3
 
@@ -20,6 +20,65 @@
4
 
 
5
 
 #include "c2s.h"
6
 
 
7
 
+/*
8
 
+ * M.Bootsma, LogicaCMG Hoofddorp, Netherlands
9
 
+ * October 2004
10
 
+ *
11
 
+ * Added a patch for flash:stream support
12
 
+ *
13
 
+ * Flash is not 100% compatible with the XML stream standard:
14
 
+ * 1. it terminates every XML message with a '\0'
15
 
+ * 2. it terminates the stream header with a /
16
 
+ *    (this would close the stream)
17
 
+ * 3. it starts the stream with a flash:stream header instead of
18
 
+ *    a stream:stream header.
19
 
+ *
20
 
+ * The patch checks the first message of a starting session stream
21
 
+ * for any '\0'. If found it flags the session as a Flash session
22
 
+ * and replases the complete header with a Jabber compatible
23
 
+ * header.
24
 
+ * After that every incoming message is filtered and '\0' is 
25
 
+ * replaced with ' '.
26
 
+ * For every outgoing message, a '\0' is appended and the response
27
 
+ * of the header is replaced for a flash friendly version
28
 
+ *
29
 
+ * The whole flash patch can be switched off by undefining CP2005_FLASH_PATCH
30
 
+ * in config.h(.in)
31
 
+ */
32
 
+
33
 
+#ifdef CP2005_FLASH_PATCH
34
 
+
35
 
+#define FLASH_BUFFER_SIZE 256
36
 
+
37
 
+static const char caStreamHeader [] = "<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='%s' >";
38
 
+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' />";
39
 
+
40
 
+static void ExtractValue(char *pMessage, char *pVariable, char *pValue) { 
41
 
+    int iLen; 
42
 
+    char *p;
43
 
+    char *pEnd;
44
 
+
45
 
+    /*
46
 
+     * extract the value of an attribute from a XML message
47
 
+     * eg: <.... id='1234567890' ....> returns 1234567890
48
 
+     */
49
 
+
50
 
+    p = strstr(pMessage, pVariable);
51
 
+    if (p != NULL) {
52
 
+        p += (strlen(pVariable) + 1);
53
 
+        /* find end of value, search for closing ' or " */
54
 
+        pEnd = strchr(p, p [-1]);
55
 
+        iLen = pEnd - p;
56
 
+        if (iLen < FLASH_BUFFER_SIZE) {
57
 
+            memcpy(pValue, p, iLen);
58
 
+            pValue[iLen] = '\0';
59
 
+            log_debug(ZONE, "++++ Extracted Var %s: [%s]\n", pVariable, pValue);
60
 
+        }
61
 
+    }
62
 
+}
63
 
+#endif
64
 
+
65
 
+
66
 
 static int _c2s_client_sx_callback(sx_t s, sx_event_t e, void *data, void *arg) {
67
 
     sess_t sess = (sess_t) arg;
68
 
     sx_buf_t buf = (sx_buf_t) data;
69
 
@@ -28,6 +87,12 @@
70
 
     nad_t nad;
71
 
     char root[9];
72
 
 
73
 
+#ifdef CP2005_FLASH_PATCH
74
 
+    char *p, *pEnd;
75
 
+    char caHost[FLASH_BUFFER_SIZE];
76
 
+    char caID[FLASH_BUFFER_SIZE];
77
 
+#endif
78
 
+
79
 
     switch(e) {
80
 
         case event_WANT_READ:
81
 
             log_debug(ZONE, "want read");
82
 
@@ -94,15 +159,74 @@
83
 
                 return -1;
84
 
             }
85
 
 
86
 
-            log_debug(ZONE, "read %d bytes", len);
87
 
-
88
 
             buf->len = len;
89
 
 
90
 
+#ifdef CP2005_FLASH_PATCH
91
 
+            /* check for 0 bytes in the first packet
92
 
+             * if found it must be a flash client
93
 
+             * remove any 0 in the data and
94
 
+             * the / that ends the <?xml... header
95
 
+             */
96
 
+
97
 
+            pEnd = &buf->data[len];
98
 
+
99
 
+            if (sess->s->state == state_NONE) {
100
 
+                /* stream is new, look for flash signature */
101
 
+                if (strstr(buf->data,"flash:stream")){
102
 
+                    log_debug(ZONE, "++++ Flash Stream detected\n%.*s", buf->len, buf->data);
103
 
+                    sess->flash_client = 1;
104
 
+
105
 
+                    /* extract destination host */
106
 
+                    ExtractValue(buf->data, "to=", caHost);
107
 
+
108
 
+                    /* create normal stream:stream header, resize data buffer first */
109
 
+                    _sx_buffer_alloc_margin(buf, 0, sizeof(caStreamHeader) + strlen(caHost) + 8);
110
 
+                    sprintf(buf->data, caStreamHeader, caHost);
111
 
+                    buf->len = strlen(buf->data);
112
 
+
113
 
+                    log_debug(ZONE, "++++ Converted to\n%.*s", buf->len, buf->data);
114
 
+                }
115
 
+            }
116
 
+
117
 
+            /* Check all other messages in the stream to remove \0's etc */
118
 
+            if (sess->flash_client) 
119
 
+                /* remove 0's from flash packets */
120
 
+                for (p = buf->data; p < pEnd; p++)
121
 
+                    if (*p == '\0')
122
 
+                        *p = ' ';
123
 
+#endif
124
 
+            log_debug(ZONE, "read %d bytes", len);
125
 
+
126
 
             return len;
127
 
 
128
 
         case event_WRITE:
129
 
             log_debug(ZONE, "writing to %d", sess->fd);
130
 
 
131
 
+#ifdef CP2005_FLASH_PATCH
132
 
+            if (sess->flash_client) {
133
 
+                /* look for the header <? xml ...*/
134
 
+                if (strncmp(buf->data, "<?xml ", 6) == 0) {
135
 
+                    /* replace normal stream header with flash friendly header */
136
 
+                    log_debug(ZONE, "++++ Found <?xml..., \n%.*s", buf->len, buf->data);
137
 
+
138
 
+                    /* extract id from id="123456567778765" or id='45454545454' */
139
 
+                    ExtractValue(buf->data, "from=", caHost);
140
 
+                    ExtractValue(buf->data, "id=", caID);
141
 
+
142
 
+                    /* create flash:stream header, realloc buffer first */
143
 
+                    _sx_buffer_alloc_margin(buf, 0, sizeof(caFlashHeader) + strlen(caHost) + strlen(caID) + 8);
144
 
+                    sprintf(buf->data, caFlashHeader, caHost, caID);
145
 
+                    buf->len = strlen(buf->data);
146
 
+
147
 
+                    log_debug(ZONE, "++++ Converted to %s", buf->data);
148
 
+                }
149
 
+
150
 
+                /* add a 0 to flash packets */
151
 
+                buf->data[buf->len] = '\0';
152
 
+                buf->len++;
153
 
+            }
154
 
+#endif
155
 
+
156
 
             len = send(sess->fd, buf->data, buf->len, 0);
157
 
             if(len >= 0) {
158
 
                 log_debug(ZONE, "%d bytes written", len);
159
 
--- /home/wolpert/src/jabberd-2.0cvs/c2s/c2s.h  2004-12-07 08:38:02.000000000 -0700
160
 
+++ c2s/c2s.h   2005-01-11 14:57:42.000000000 -0700
161
 
@@ -62,6 +62,10 @@
162
 
     int                 bound;
163
 
     int                 active;
164
 
 
165
 
+#ifdef CP2005_FLASH_PATCH
166
 
+    int                 flash_client;
167
 
+#endif
168
 
+
169
 
     nad_t               result;
170
 
 
171
 
     int                 sasl_authd;     /* 1 = they did a sasl auth */