[PATCH] q-value calculation for 'Accept:'ed content-types produces wrong values

Kai Tetzlaff <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
I've been using the WAP GW with a mobile which appends q-values to it's 
'Accept:' headers in its WSP Connect meassage. I noticed that Kannel's 
decoded q-value differs from the one the mobile sends. So far, this 
would be a minor problem but in some cases, if the decoded q-value is 
above 1000, Kannel stops to extract further Accept headers. This may 
then lead to HTTP/WSP '406 Not acceptable' being forwarded to the mobile 
(instead of the real HTTP response) beacuse Kannel does not have the 
correct list of acceptable content-types.

I already filed a bug (#198) in Kannel/Mantis but it looks like this 
list is the better place ...

I've attached a patch against wsp_headers.c which solves this issue (and 
another one which is closely related).

Cheers,
Kai

Index: wap/wsp_headers.c
===================================================================
RCS file: /home/cvs/gateway/wap/wsp_headers.c,v
retrieving revision 1.22
diff -u -p -d -r1.22 wsp_headers.c
--- wap/wsp_headers.c   11 Feb 2005 15:59:18 -0000      1.22
+++ wap/wsp_headers.c   3 Mar 2005 22:21:21 -0000
@@ -251,8 +251,9 @@ static Octstr *convert_q_value(int q)
      }

      /* Three decimal quality factors shall be multiplied with 1000
-     * and incremented by 100. */
-    if (q > 100 && q <= 1000) {
+     * and incremented by 100. I.e. the values to be converted range from
+     * 101 (.001 * 1000 + 100) to 1099 (.999 * 1000 + 100). */
+    if (q > 100 && q < 1100) {
          q = q - 100;
          result = octstr_create("0.");
          octstr_append_char(result, (q / 100) + '0');
@@ -270,6 +271,9 @@ static Octstr *convert_q_value(int q)
  static Octstr *unpack_q_value(ParseContext *context)
  {
      int c, c2;
+
+    /* better use the existing parse_get_uintvar(..) to extract the
+     * encoded uintvar? */

      c = parse_get_char(context);
      if (c < 0)
@@ -279,7 +283,7 @@ static Octstr *unpack_q_value(ParseConte
          c2 = parse_get_char(context);
          if (c2 < 0 || (c2 & 0x80))
              return NULL;
-        c = ((c & 0x7f) << 8) + c2;
+        c = ((c & 0x7f) << 7) + c2;
      }

      return convert_q_value(c);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.