update Mon May 31 06:37:01 PDT 2010
[pkgsrc.git] / security / lasso / patches / patch-cb
1 $NetBSD: patch-cb,v 1.3 2009/12/01 08:49:46 manu Exp $
2 --- lasso/xml/tools.c.orig      2009-11-30 18:38:05.000000000 +0100
3 +++ lasso/xml/tools.c   2009-11-30 18:39:45.000000000 +0100
4 @@ -1492,2 +1492,70 @@
5         return result;
6  }
7 +
8 +
9 +/**
10 + * lasso_url_add_parameters:
11 + * @url: the original URL
12 + * @free: whether to free the URL parameter
13 + * @...: pairs of strings, key, value, followed by NULL
14 + *
15 + * Iterate over all pairs of key,value, and concatenate them to @url encoded as "&key=value", where
16 + * key and value are url-encoded.
17 + * If free is true and at least one pair was given, url is freed. If url is NULL, the first
18 + * ampersand is omitted.
19 + *
20 + * Return value: a newly allocated string, or url.
21 + */
22 +char*
23 +lasso_url_add_parameters(char *url,
24 +               gboolean free, ...)
25 +{
26 +       char *old_url = url, *new_url;
27 +       xmlChar *encoded_key, *encoded_value;
28 +       int rc = 0;
29 +       va_list ap;
30 +
31 +       va_start(ap, free);
32 +
33 +       while (1) {
34 +               char *key;
35 +               char *value;
36 +
37 +               key = va_arg(ap, char*);
38 +               if (! key) {
39 +                       break;
40 +               }
41 +               encoded_key = xmlURIEscapeStr((xmlChar*)key, NULL);
42 +               goto_cleanup_if_fail_with_rc(encoded_key, 0);
43 +
44 +               value = va_arg(ap, char*);
45 +               if (! value) {
46 +                       message(G_LOG_LEVEL_CRITICAL, "lasso_url_add_parameter: key without a value !!");
47 +                       break;
48 +               }
49 +               encoded_value = xmlURIEscapeStr((xmlChar*)value, NULL);
50 +               goto_cleanup_if_fail_with_rc(encoded_value, 0);
51 +
52 +               if (old_url) {
53 +                       new_url = g_strdup_printf("%s&%s=%s", old_url, (char*)encoded_key, (char*)encoded_value);
54 +               } else {
55 +                       new_url = g_strdup_printf("%s=%s", (char*)encoded_key, (char*)encoded_value);
56 +               }
57 +               if (old_url != url) {
58 +                       lasso_release_string(old_url);
59 +               }
60 +               old_url = new_url;
61 +
62 +               lasso_release_xml_string(encoded_key);
63 +               lasso_release_xml_string(encoded_value);
64 +       }
65 +cleanup:
66 +       va_end(ap);
67 +       if (free && new_url != url) {
68 +               lasso_release(url);
69 +       }
70 +       lasso_release_xml_string(encoded_key);
71 +
72 +       return new_url;
73 +}
74 +