commit - 970deec6ebb6e26c60a439116b8ae0154e922901
commit + 4190a5c21660e75386f0618b23e5ccbda6715f19
blob - 8994b31b60a1decd709b17b7d6a215ae5cd22b47
blob + 50b0687a47865fff2c519e12abf68e7c9392bcba
--- phos/phos.h
+++ phos/phos.h
int phos_parse_absolute_uri(const char*, struct phos_uri*);
int phos_resolve_uri_from_str(const struct phos_uri*, const char *, struct phos_uri*);
void phos_uri_drop_empty_segments(struct phos_uri*);
+int phos_uri_set_query(struct phos_uri*, const char*);
int phos_serialize_uri(const struct phos_uri*, char*, size_t);
#ifdef __cplusplus
blob - 6e25302ebedfa13aaf01feea9e83d4fa0bb28a2e
blob + 0f5f0c9763421d041c10944ebb7e11565feedadf
--- phos/phos_uri.c
+++ phos/phos_uri.c
#include <ctype.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char *sub_ip_literal(const char*);
static const char *sub_host_dummy(const char*);
static const char *sub_pchar(const char*);
+
static const char *sub_segment(const char*);
static const char *sub_segment_nz(const char*);
static const char *sub_segment_nz_nc(const char*);
if (*i == '/' && *(i+1) == '/') {
memmove(i, i+1, strlen(i)); /* move also the \0 */
i--;
+ }
+ }
+}
+
+int
+phos_uri_set_query(struct phos_uri *uri, const char *query)
+{
+ char *out;
+ int t;
+ size_t len;
+
+ len = sizeof(uri->query);
+ out = uri->query;
+ memset(uri->query, 0, len);
+
+ for (; *query != '\0' && len > 0; ++query) {
+ if (*query == '/' ||
+ *query == '?' ||
+ *query == ':' ||
+ *query == '@' ||
+ unreserved(*query) ||
+ sub_delims(*query)) {
+ *out++ = *query;
+ len--;
+ } else {
+ if (len <= 4)
+ break;
+ len -= 3;
+ *out++ = '%';
+ t = *query;
+ sprintf(out, "%02X", t);
+ out += 2;
}
}
+
+ return *query == '\0';
}
int