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