static const char *add_index(cmd_parms *cmd, void *dummy, const char *arg) { dir_config_rec *d = dummy; const char *t, *w; int count = 0; if (!d->index_names) { d->index_names = apr_array_make(cmd->pool, 2, sizeof(char *)); } t = arg; while ((w = ap_getword_conf(cmd->pool, &t)) && w[0]) { if (count == 0 && !strcasecmp(w, "disabled")) { /* peek to see if "disabled" is first in a series of arguments */ const char *tt = t; const char *ww = ap_getword_conf(cmd->temp_pool, &tt); if (ww == NULL || !ww[0]) { /* "disabled" is first, and alone */ apr_array_clear(d->index_names); break; } } *(const char **)apr_array_push(d->index_names) = w; count++; } return NULL; }
static void array_clear(abts_case *tc, void *data) { a1 = apr_array_make(p, 2, sizeof(const char *)); APR_ARRAY_PUSH(a1, const char *) = "foo"; APR_ARRAY_PUSH(a1, const char *) = "bar"; apr_array_clear(a1); ABTS_INT_EQUAL(tc, 0, a1->nelts); }
MPF_DECLARE(apt_bool_t) mpf_context_topology_destroy(mpf_context_t *context) { if(context->mpf_objects->nelts) { int i; mpf_object_t *object; for(i=0; i<context->mpf_objects->nelts; i++) { object = APR_ARRAY_IDX(context->mpf_objects,i,mpf_object_t*); mpf_object_destroy(object); } apr_array_clear(context->mpf_objects); }
/* * parse a JSON Web Token */ apr_byte_t apr_jwt_parse(apr_pool_t *pool, const char *s_json, apr_jwt_t **j_jwt, apr_hash_t *private_keys, const char *shared_key) { *j_jwt = apr_pcalloc(pool, sizeof(apr_jwt_t)); apr_jwt_t *jwt = *j_jwt; apr_array_header_t *unpacked = apr_jwt_compact_deserialize(pool, s_json); if (unpacked->nelts < 2) return FALSE; /* parse the header fields */ if (apr_jwt_parse_header(pool, ((const char**) unpacked->elts)[0], &jwt->header) == FALSE) return FALSE; if (apr_jwe_is_encrypted_jwt(pool, &jwt->header)) { char *decrypted = NULL; if ((apr_jwe_decrypt_jwt(pool, &jwt->header, unpacked, private_keys, shared_key, &decrypted) == FALSE) || (decrypted == NULL)) return FALSE; apr_array_clear(unpacked); unpacked = apr_jwt_compact_deserialize(pool, (const char *) decrypted); json_decref(jwt->header.value.json); if (unpacked->nelts < 2) return FALSE; /* parse the nested header fields */ if (apr_jwt_parse_header(pool, ((const char**) unpacked->elts)[0], &jwt->header) == FALSE) return FALSE; } /* concat the base64url-encoded payload to the base64url-encoded header for signature verification purposes */ jwt->message = apr_pstrcat(pool, ((const char**) unpacked->elts)[0], ".", ((const char**) unpacked->elts)[1], NULL); /* parse the payload fields */ if (apr_jwt_parse_payload(pool, ((const char**) unpacked->elts)[1], &jwt->payload) == FALSE) { json_decref(jwt->header.value.json); return FALSE; } if (unpacked->nelts > 2 && strcmp(jwt->header.alg, "none") != 0) { /* remainder is the signature */ if (apr_jwt_parse_signature(pool, ((const char**) unpacked->elts)[2], &jwt->signature) == FALSE) { json_decref(jwt->header.value.json); json_decref(jwt->payload.value.json); return FALSE; } } return TRUE; }
static void *merge_triger_dir_config(apr_pool_t * pool, void *BASE, void *ADD) { int i, j, skip; triger_ctype_t *ctype; triger_conf_t *base = (triger_conf_t *) BASE; triger_conf_t *add = (triger_conf_t *) ADD; if (!base) return add; triger_conf_t *conf = (triger_conf_t *) apr_palloc(pool, sizeof(triger_conf_t)); if (!conf) goto last; conf->inherit = add->inherit; if (conf->inherit) { if (add->enabled == -1 && base->enabled != -1) conf->enabled = base->enabled; else if (add->enabled != -1) conf->enabled = add->enabled; else conf->enabled = add->default_enabled; if (add->ctypes->nelts > 0) { for (i = 0; i < base->ctypes->nelts; i++) { skip = 0; for (j = 0; j < add->ctypes->nelts; j++) { if (!apr_strnatcmp ((((triger_ctype_t *) (add->ctypes-> elts))[j]).data, (((triger_ctype_t *) (base->ctypes-> elts))[i]).data)) { skip = 1; break; } } if (skip) continue; else { ctype = apr_array_push(add->ctypes); ctype->data = (((triger_ctype_t *) (base->ctypes-> elts))[i]).data; } } } else { apr_array_clear(add->ctypes); if (base->ctypes->nelts) { add->ctypes = base->ctypes; } else { add->ctypes = add->default_ctypes; } } conf->ctypes = add->ctypes; if (add->js && base->js) { conf->js = apr_pstrcat(pool, add->js, base->js, NULL); if (!conf->js) goto last; } else if (add->js) conf->js = add->js; else if (base->js) conf->js = base->js; else conf->js = add->default_js; if (add->chk_len == 0 && base->chk_len != 0) conf->chk_len = base->chk_len; else if (add->chk_len != 0 && base->chk_len == 0) conf->chk_len = add->chk_len; else if (add->chk_len != 0 && base->chk_len != 0) conf->chk_len = add->chk_len > base->chk_len ? add->chk_len : base->chk_len; else conf->chk_len = add->default_chk_len; if (add->full_chk == -1 && base->full_chk != -1) conf->full_chk = base->full_chk; else if (add->full_chk != -1) conf->full_chk = add->full_chk; else conf->full_chk = add->default_full_chk; } else { conf->enabled = add->enabled != -1 ? add->enabled : add->default_enabled; conf->js = add->js ? add->js : add->default_js; if (add->ctypes->nelts > 0) conf->ctypes = add->ctypes; else { conf->ctypes = add->default_ctypes; } conf->chk_len = add->chk_len != 0 ? add->chk_len : add->default_chk_len; conf->full_chk = add->full_chk != -1 ? add->full_chk : add->default_full_chk; } last: return (void *) conf; }
/* * parse and (optionally) decrypt a JSON Web Token */ apr_byte_t apr_jwt_parse(apr_pool_t *pool, const char *s_json, apr_jwt_t **j_jwt, apr_hash_t *keys, apr_jwt_error_t *err) { *j_jwt = apr_pcalloc(pool, sizeof(apr_jwt_t)); apr_jwt_t *jwt = *j_jwt; apr_array_header_t *unpacked = NULL; if (apr_jwt_header_parse(pool, s_json, &unpacked, &jwt->header, err) == FALSE) return FALSE; if (unpacked->nelts < 2) { apr_jwt_error(err, "could not successfully deserialize 2 or more elements from JWT header"); return FALSE; } if (apr_jwe_is_encrypted_jwt(pool, &jwt->header)) { char *decrypted = NULL; if ((apr_jwe_decrypt_jwt(pool, &jwt->header, unpacked, keys, &decrypted, err) == FALSE) || (decrypted == NULL)) return FALSE; apr_array_clear(unpacked); unpacked = NULL; json_decref(jwt->header.value.json); if (apr_jwt_header_parse(pool, (const char *) decrypted, &unpacked, &jwt->header, err) == FALSE) return FALSE; if (unpacked->nelts < 2) { apr_jwt_error(err, "could not successfully deserialize 2 or more elements from decrypted JWT header"); return FALSE; } } /* concat the base64url-encoded payload to the base64url-encoded header for signature verification purposes */ jwt->message = apr_pstrcat(pool, ((const char**) unpacked->elts)[0], ".", ((const char**) unpacked->elts)[1], NULL); /* parse the payload fields */ if (apr_jwt_parse_payload(pool, ((const char**) unpacked->elts)[1], &jwt->payload, err) == FALSE) { json_decref(jwt->header.value.json); return FALSE; } if (unpacked->nelts > 2 && strcmp(jwt->header.alg, "none") != 0) { /* remainder is the signature */ if (apr_jwt_parse_signature(pool, ((const char**) unpacked->elts)[2], &jwt->signature) == FALSE) { json_decref(jwt->header.value.json); json_decref(jwt->payload.value.json); apr_jwt_error(err, "could not successfully parse (base64urldecode) JWT signature"); return FALSE; } } return TRUE; }
static int ap_set_byterange(request_rec *r, apr_off_t clength, apr_array_header_t **indexes) { const char *range; const char *if_range; const char *match; const char *ct; char *cur; int num_ranges = 0, unsatisfiable = 0; apr_off_t sum_lengths = 0; indexes_t *idx; int ranges = 1; const char *it; if (r->assbackwards) { return 0; } /* * Check for Range request-header (HTTP/1.1) or Request-Range for * backwards-compatibility with second-draft Luotonen/Franks * byte-ranges (e.g. Netscape Navigator 2-3). * * We support this form, with Request-Range, and (farther down) we * send multipart/x-byteranges instead of multipart/byteranges for * Request-Range based requests to work around a bug in Netscape * Navigator 2-3 and MSIE 3. */ if (!(range = apr_table_get(r->headers_in, "Range"))) { range = apr_table_get(r->headers_in, "Request-Range"); } if (!range || strncasecmp(range, "bytes=", 6) || r->status != HTTP_OK) { return 0; } /* is content already a single range? */ if (apr_table_get(r->headers_out, "Content-Range")) { return 0; } /* is content already a multiple range? */ if ((ct = apr_table_get(r->headers_out, "Content-Type")) && (!strncasecmp(ct, "multipart/byteranges", 20) || !strncasecmp(ct, "multipart/x-byteranges", 22))) { return 0; } /* * Check the If-Range header for Etag or Date. * Note that this check will return false (as required) if either * of the two etags are weak. */ if ((if_range = apr_table_get(r->headers_in, "If-Range"))) { if (if_range[0] == '"') { if (!(match = apr_table_get(r->headers_out, "Etag")) || (strcmp(if_range, match) != 0)) { return 0; } } else if (!(match = apr_table_get(r->headers_out, "Last-Modified")) || (strcmp(if_range, match) != 0)) { return 0; } } range += 6; it = range; while (*it) { if (*it++ == ',') { ranges++; } } it = range; *indexes = apr_array_make(r->pool, ranges, sizeof(indexes_t)); while ((cur = ap_getword(r->pool, &range, ','))) { char *dash; char *errp; apr_off_t number, start, end; if (!*cur) break; /* * Per RFC 2616 14.35.1: If there is at least one syntactically invalid * byte-range-spec, we must ignore the whole header. */ if (!(dash = strchr(cur, '-'))) { return 0; } if (dash == cur) { /* In the form "-5" */ if (apr_strtoff(&number, dash+1, &errp, 10) || *errp) { return 0; } if (number < 1) { return 0; } start = clength - number; end = clength - 1; } else { *dash++ = '\0'; if (apr_strtoff(&number, cur, &errp, 10) || *errp) { return 0; } start = number; if (*dash) { if (apr_strtoff(&number, dash, &errp, 10) || *errp) { return 0; } end = number; if (start > end) { return 0; } } else { /* "5-" */ end = clength - 1; /* * special case: 0- * ignore all other ranges provided * return as a single range: 0- */ if (start == 0) { apr_array_clear(*indexes); idx = (indexes_t *)apr_array_push(*indexes); idx->start = start; idx->end = end; sum_lengths = clength; num_ranges = 1; break; } } } if (start < 0) { start = 0; } if (start >= clength) { unsatisfiable = 1; continue; } if (end >= clength) { end = clength - 1; } idx = (indexes_t *)apr_array_push(*indexes); idx->start = start; idx->end = end; sum_lengths += end - start + 1; /* new set again */ num_ranges++; } if (num_ranges == 0 && unsatisfiable) { /* If all ranges are unsatisfiable, we should return 416 */ return -1; } if (sum_lengths > clength) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Sum of ranges larger than file, ignoring."); return 0; } r->status = HTTP_PARTIAL_CONTENT; r->range = it; return num_ranges; }