/* Copyright 2006 Paul Querna. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "proton.h" #include "apr_strings.h" #include "private/etl_util.h" #include "private/error_convert.h" #include const etl_variable_t* pwt_variable_get(etl_hash_t *env, const char *key) { char *keyc = strdup(key); char *state; char *p; const etl_variable_t *var = NULL; p = apr_strtok(keyc, ".", &state); if (!p) { return NULL; } var = (etl_variable_t*) etl_hash_get(env, p); if (!var) { return NULL; } while (var) { p = apr_strtok(NULL, ".", &state); if (!p) { var = NULL; break; } var = etl_variable_hash_get(var, p); if (!var) { break; } if (*state == '\0') { /* found the ending variable. yay. */ break; } } free(keyc); return var; } const char* pwt_variable_get_str(etl_hash_t* env, const char* key, const char* defaultv) { const etl_variable_t* var = pwt_variable_get(env, key); if (var) { if (etl_variable_type(var) == ETL_VARIABLE_STRING) { return etl_variable_content_str(var); } } return defaultv; } static pwt_error_t* pwt_hash_set_str(etl_hash_t* env, const char* key, const char* data) { etl_variable_t* var = etl_variable_make_str(data); etl_hash_set(env, key, var); return PWT_SUCCESS; } pwt_error_t* pwt_variable_set_str(etl_hash_t *env, const char *key, const char *data) { return pwt_hash_set_str(env, key, data); } pwt_error_t* pwt_ddl_parse_file(etl_hash_t **data, etl_resolver_t *resolver, const char *filename) { etl_error_t *etl_error; etl_stream_t *stream; etl_error = etl_resolver_resolve(&stream, resolver, filename); if (etl_error) { PWT_E_ERR(etl_error); } etl_error = etl_ddl_parse(data, resolver, stream); if (etl_error) { PWT_E_ERR(etl_error); } return PWT_SUCCESS; }