36#define CGI_QUERY_MAX 1000000
46 method = getenv(
"REQUEST_METHOD");
47 if (method && !strcmp(method,
"GET"))
return true;
59 method = getenv(
"REQUEST_METHOD");
60 if (method && !strcmp(method,
"POST"))
return true;
76 query_size = atoi(getenv(
"CONTENT_LENGTH"));
78 query = malloc(
sizeof(
char) * query_size + 1);
83 s = fread(query, query_size, 1, stdin);
89 query[query_size] =
'\0';
92 else query = getenv(
"QUERY_STRING");
106 digit = (what[0] >=
'A' ? ((what[0] & 0xdf) -
'A') + 10 : (what[0] -
'0'));
108 digit += (what[1] >=
'A' ? ((what[1] & 0xdf) -
'A') + 10 : (what[1] -
'0'));
121 for (x = 0, y = 0; url[y]; ++x, ++y) {
122 if ((url[x] = url[y]) ==
'%') {
139 for (x=0 ; str[x] ; x++)
140 if (str[x] ==
'+') str[x] =
' ';
150 for (x=0 ; str[x] ; x++)
151 if (str[x] ==
'\n' || str[x] ==
'\r')
182 if (query[i] ==
'&') {
190 }
else if (query[i] ==
'=') {
199 string[0] = query[i];
212 "QUERY_STRING contains forbidden characters",
"request");
217 if (
check_regexp(
string,
"[A-Za-zà-ÿ0-9.\\=;,():/\\*_ \\-]")
218 || (
buffer_cmp(key,
"filter") &&
check_regexp(
string,
"[A-Za-zà-ÿ0-9.#\\,():/_<> %\"\'=\\*!\\-]|\\[|\\]")))
225 "QUERY_STRING contains forbidden characters",
"request");
261 content = xmlNodeGetContent(n);
286 content = xmlNodeGetContent(att->children);
302 xmlNodePtr elemt, node;
315 if (elemt->type != XML_ELEMENT_NODE) elemt = elemt->next;
318 for ( ; elemt ; elemt = elemt->next) {
319 if (elemt->type == XML_ELEMENT_NODE) {
320 node = elemt->children;
321 if (node->type != XML_ELEMENT_NODE) node = node->next;
324 content = xmlNodeGetContent(node);
331 if (node->type != XML_ELEMENT_NODE) node = node->next;
334 content = xmlNodeGetContent(node);
340 if (elemt->next && elemt->next->type == XML_ELEMENT_NODE)
390 content = xmlNodeGetContent(n);
410 ns = xmlGetNsList(n->doc, n);
412 for (i = 0 ; ns[i] ; i++)
413 xmlNewNs(n, ns[i]->href, ns[i]->prefix);
415 buf = xmlBufferCreate();
416 xmlNodeDump(buf, n->doc, n, 0, 0);
428 if (n->ns && n->ns->href
429 && (!strcmp(
"http://www.opengis.net/wfs", (
char *) n->ns->href)
430 || !strcmp(
"http://www.opengis.net/ogc", (
char *) n->ns->href)))
return true;
439 buffer *key, *val, *operations, *prop, *filter, *
typename;
440 bool prop_need_comma, typ_need_comma;
444 bool lock_error, unknown_error;
445 xmlNodePtr node, n = NULL;
450 prop_need_comma = typ_need_comma =
false;
451 lock_error = unknown_error =
false;
453 xmldoc = xmlParseMemory(query, strlen(query));
455 if (!xmldoc || !(n = xmlDocGetRootElement(xmldoc))) {
476 if (n->ns && n->ns->href) {
483 for (att = n->properties ; att ; att = att->next)
486 for (n = n->children; n; n = n->next) {
487 if (n->type != XML_ELEMENT_NODE)
continue;
490 for (att = n->properties ; att ; att = att->next) {
493 if (!strcmp((
char *) att->name,
"typeName")) {
496 typ_need_comma =
true;
500 if (n->nsDef && n->nsDef->href &&
array_is_value(o_ns, (
char *) n->nsDef->href)) {
501 buffer_shift(
typename, strlen((
char *) n->nsDef->prefix));
511 typ_need_comma =
true;
512 }
else if (
is_node_ns_wfs(n) && !strcmp((
char *) n->name,
"LockID")) lock_error =
true;
515 && ( !strcmp((
char *) n->name,
"Insert")
516 || !strcmp((
char *) n->name,
"Delete")
517 || !strcmp((
char *) n->name,
"Update"))) {
523 else if (
is_node_ns_wfs(n) && !strcmp((
char *) n->name,
"Query")) {
528 for (node = n->children; node; node = node->next) {
530 if (node->type != XML_ELEMENT_NODE)
continue;
532 if (
is_node_ns_wfs(node) && !strcmp((
char *) node->name,
"PropertyName")) {
535 prop_need_comma =
true;
536 }
else if (
is_node_ns_wfs(node) && !strcmp((
char *) node->name,
"Filter")) {
539 }
else if (
is_node_ns_wfs(node) && !strcmp((
char *) node->name,
"SortBy")) {
553 prop_need_comma =
false;
558 }
else unknown_error =
true;
562 if (operations->
use) {
584 if (typename->use) arr =
cgi_add_buffer(arr,
typename,
"typename");
static array * cgi_add_node(array *arr, xmlNodePtr n)
array * cgi_parse_xml(ows *o, char *query)
array * cgi_parse_kvp(ows *o, char *query)
static void cgi_unescape_url(char *url)
char * cgi_getback_query(ows *o)
buffer * cgi_add_xml_into_buffer(buffer *element, xmlNodePtr n)
static array * cgi_add_sortby(array *arr, xmlNodePtr n)
static void cgi_remove_crlf(char *str)
static bool is_node_ns_wfs(xmlNodePtr n)
static array * cgi_add_att(array *arr, xmlAttr *att)
static buffer * cgi_add_into_buffer(buffer *b, xmlNodePtr n, bool need_comma)
static array * cgi_add_buffer(array *arr, buffer *b, char *name)
static char cgi_hexatochar(char *what)
static void cgi_plustospace(char *str)
void buffer_add(buffer *buf, char c)
void buffer_copy(buffer *dest, const buffer *src)
bool array_is_value(const array *a, const char *value)
bool buffer_cmp(const buffer *buf, const char *str)
buffer * array_get_key(const array *a, const char *value)
void buffer_add_str(buffer *buf, const char *str)
bool buffer_case_cmp(const buffer *buf, const char *str)
array * ows_layer_list_namespaces(ows_layer_list *ll)
void ows_error(ows *o, enum ows_error_code code, char *message, char *locator)
void array_free(array *a)
void buffer_add_head_str(buffer *buf, char *str)
buffer * buffer_from_str(const char *str)
void buffer_free(buffer *buf)
void buffer_shift(buffer *buf, size_t len)
void buffer_pop(buffer *buf, size_t len)
void array_add(array *a, buffer *key, buffer *value)
bool check_regexp(const char *str_request, const char *str_regex)
@ OWS_ERROR_MISSING_PARAMETER_VALUE
@ OWS_ERROR_INVALID_PARAMETER_VALUE
char * buf
size to next realloc