int test () { int test; #if defined(CASE_BLIND_FILESYSTEM) test = (pattern && apr_fnmatch (pattern, dirent ->name, APR_FNM_NOESCAPE | APR_FNM_PERIOD | APR_FNM_CASE_BLIND)!= APR_SUCCESS); #endif #if !defined(CASE_BLIND_FILESYSTEM) test = (pattern && apr_fnmatch (pattern, dirent ->name, APR_FNM_NOESCAPE | APR_FNM_PERIOD)!= APR_SUCCESS); #endif if ((test)){ return NULL; } }
/* For one auto-props config entry (NAME, VALUE), if the filename pattern NAME matches BATON->filename case insensitively then add the properties listed in VALUE into BATON->properties. BATON must point to an auto_props_baton_t. */ static svn_boolean_t auto_props_enumerator(const char *name, const char *value, void *baton, apr_pool_t *pool) { int i; auto_props_baton_t *autoprops = baton; apr_array_header_t *props; /* nothing to do here without a value */ if (*value == 0) return TRUE; /* check if filename matches and return if it doesn't */ if (apr_fnmatch(name, autoprops->filename, APR_FNM_CASE_BLIND) == APR_FNM_NOMATCH) return TRUE; split_props(&props, value, autoprops->pool); for (i = 0; i < props->nelts; i++) { size_t len; const char *this_value; char *property = APR_ARRAY_IDX(props, i, char *); char *equal_sign = strchr(property, '='); if (equal_sign) { *equal_sign = '\0'; equal_sign++; trim_string(&equal_sign); unquote_string(&equal_sign); this_value = equal_sign; } else { this_value = ""; } trim_string(&property); len = strlen(property); if (len > 0) { svn_string_t *propval = apr_palloc(autoprops->pool, sizeof(*propval)); propval->data = this_value; propval->len = strlen(this_value); apr_hash_set(autoprops->properties, property, len, propval); if (strcmp(property, SVN_PROP_MIME_TYPE) == 0) autoprops->mimetype = this_value; else if (strcmp(property, SVN_PROP_EXECUTABLE) == 0) autoprops->have_executable = TRUE; } } return TRUE; }
/* For one auto-props config entry (NAME, VALUE), if the filename pattern NAME matches BATON->filename case insensitively then add the properties listed in VALUE into BATON->properties. BATON must point to an auto_props_baton_t. */ static svn_boolean_t auto_props_enumerator(const char *name, const char *value, void *baton, apr_pool_t *pool) { auto_props_baton_t *autoprops = baton; char *property; char *last_token; /* nothing to do here without a value */ if (strlen(value) == 0) return TRUE; /* check if filename matches and return if it doesn't */ if (apr_fnmatch(name, autoprops->filename, APR_FNM_CASE_BLIND) == APR_FNM_NOMATCH) return TRUE; /* parse the value (we dup it first to effectively lose the 'const', and to avoid messing up the original value) */ property = apr_pstrdup(autoprops->pool, value); property = apr_strtok(property, ";", &last_token); while (property) { int len; const char *this_value; char *equal_sign = strchr(property, '='); if (equal_sign) { *equal_sign = '\0'; equal_sign++; trim_string(&equal_sign); this_value = equal_sign; } else { this_value = ""; } trim_string(&property); len = strlen(property); if (len > 0) { svn_string_t *propval = svn_string_create(this_value, autoprops->pool); apr_hash_set(autoprops->properties, property, len, propval); if (strcmp(property, SVN_PROP_MIME_TYPE) == 0) autoprops->mimetype = this_value; else if (strcmp(property, SVN_PROP_EXECUTABLE) == 0) autoprops->have_executable = TRUE; } property = apr_strtok(NULL, ";", &last_token); } return TRUE; }
int test(){ if (pattern && (apr_fnmatch(pattern, dirent->name, APR_FNM_NOESCAPE | APR_FNM_PERIOD #ifdef CASE_BLIND_FILESYSTEM | APR_FNM_CASE_BLIND #endif ) != APR_SUCCESS)) { return (NULL); } }
svn_boolean_t svn_cstring_match_glob_list(const char *str, apr_array_header_t *list) { int i; for (i = 0; i < list->nelts; i++) { const char *this_pattern = APR_ARRAY_IDX(list, i, char *); if (apr_fnmatch(this_pattern, str, 0) == APR_SUCCESS) return TRUE; } return FALSE; }
/* Find all files matching the specified pattern */ APR_DECLARE(apr_status_t) apr_match_glob(const char *pattern, apr_array_header_t **result, apr_pool_t *p) { apr_dir_t *dir; apr_finfo_t finfo; apr_status_t rv; char *path; /* XXX So, this is kind of bogus. Basically, I need to strip any leading * directories off the pattern, but there is no portable way to do that. * So, for now we just find the last occurance of '/' and if that doesn't * return anything, then we look for '\'. This means that we could * screw up on unix if the pattern is something like "foo\.*" That '\' * isn't a directory delimiter, it is a part of the filename. To fix this, * we really need apr_filepath_basename, which will be coming as soon as * I get to it. rbb */ char *idx = strrchr(pattern, '/'); if (idx == NULL) { idx = strrchr(pattern, '\\'); } if (idx == NULL) { path = "."; } else { path = apr_pstrndup(p, pattern, idx - pattern); pattern = idx + 1; } *result = apr_array_make(p, 0, sizeof(char *)); rv = apr_dir_open(&dir, path, p); if (rv != APR_SUCCESS) { return rv; } while (apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) { if (apr_fnmatch(pattern, finfo.name, 0) == APR_SUCCESS) { *(const char **)apr_array_push(*result) = apr_pstrdup(p, finfo.name); } } apr_dir_close(dir); return APR_SUCCESS; }
bool UmcFramework::LoadScenarios() { apr_dir_t* pDir; apr_finfo_t finfo; apr_status_t rv; const char* pDirPath; pDirPath = apt_dir_layout_path_compose(m_pDirLayout,APT_LAYOUT_CONF_DIR,"umc-scenarios",m_pPool); if(!pDirPath) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Compose Config File Path"); return false; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Enter Directory [%s]",pDirPath); rv = apr_dir_open(&pDir,pDirPath,m_pPool); if(rv != APR_SUCCESS) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Directory %s",pDirPath); return false; } while(apr_dir_read(&finfo,APR_FINFO_NAME,pDir) == APR_SUCCESS) { if(apr_fnmatch("*.xml",finfo.name,0) == APR_SUCCESS) { char* pFilePath; if(apr_filepath_merge(&pFilePath,pDirPath,finfo.name,APR_FILEPATH_NATIVE,m_pPool) == APR_SUCCESS) { LoadScenario(pFilePath); } } } apr_dir_close(pDir); return true; }
/** Load UniMRCP client */ static apt_bool_t unimrcp_client_load(unimrcp_client_loader_t *loader, const char *dir_path, const char *file_name, apr_pool_t *pool) { apr_xml_doc *doc; const apr_xml_elem *elem; const apr_xml_elem *root; const apr_xml_attr *attr; const char *file_path; const char *version = NULL; const char *subfolder = NULL; if(!dir_path || !file_name) { return FALSE; } if(*dir_path == '\0') { file_path = file_name; } else { file_path = apr_psprintf(pool,"%s/%s",dir_path,file_name); } /* Parse XML document */ doc = unimrcp_client_doc_parse(file_path,pool); if(!doc) { return FALSE; } root = doc->root; /* Match document name */ if(!root || strcasecmp(root->name,"unimrcpclient") != 0) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Document <%s>",root->name); return FALSE; } /* Read attributes */ for(attr = root->attr; attr; attr = attr->next) { if(strcasecmp(attr->name,"version") == 0) { version = attr->value; } else if(strcasecmp(attr->name,"subfolder") == 0) { subfolder = attr->value; } } /* Check version number first */ if(!version) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Version"); return FALSE; } loader->doc = doc; /* Navigate through document */ for(elem = root->first_child; elem; elem = elem->next) { if(strcasecmp(elem->name,"properties") == 0) { unimrcp_client_properties_load(loader,elem); } else if(strcasecmp(elem->name,"components") == 0) { unimrcp_client_components_load(loader,elem); } else if(strcasecmp(elem->name,"settings") == 0) { unimrcp_client_settings_load(loader,elem); } else if(strcasecmp(elem->name,"profiles") == 0) { unimrcp_client_profiles_load(loader,elem); } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name); } } if(subfolder && subfolder != '\0') { apr_dir_t *dir; apr_finfo_t finfo; apr_status_t rv; dir_path = apr_psprintf(pool,"%s/%s",dir_path,subfolder); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Enter Directory [%s]",dir_path); rv = apr_dir_open(&dir,dir_path,pool); if(rv == APR_SUCCESS) { while(apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) { if(apr_fnmatch("*.xml", finfo.name, 0) == APR_SUCCESS) { unimrcp_client_load(loader,dir_path,finfo.name,pool); } } apr_dir_close(dir); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Leave Directory [%s]",dir_path); } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Directory %s",dir_path); } } return TRUE; }
void nx_expr_proc__xm_fileop_file_remove(nx_expr_eval_ctx_t *eval_ctx, nx_module_t *module, nx_expr_arg_list_t *args) { nx_expr_arg_t *arg; nx_value_t file; apr_status_t rv; apr_pool_t *pool = NULL; apr_dir_t *dir; nx_exception_t e; nx_string_t *dirname = NULL; nx_string_t *fname = NULL; char *filename; char *idx; int flags = 0; apr_finfo_t finfo; nx_expr_arg_t *older; nx_value_t olderval; apr_time_t older_time = 0LL; ASSERT(module != NULL); ASSERT(args != NULL); arg = NX_DLIST_FIRST(args); ASSERT(arg != NULL); ASSERT(arg->expr != NULL); nx_expr_evaluate(eval_ctx, &file, arg->expr); if ( file.defined != TRUE ) { throw_msg("'file' is undef"); } try { if ( file.type != NX_VALUE_TYPE_STRING ) { throw_msg("string type required for 'file'"); } older = NX_DLIST_NEXT(arg, link); if ( older != NULL ) { ASSERT(older->expr != NULL); nx_expr_evaluate(eval_ctx, &olderval, older->expr); if ( olderval.type != NX_VALUE_TYPE_DATETIME ) { nx_value_kill(&olderval); throw_msg("datetime type required for 'older'"); } if ( olderval.defined == TRUE ) { older_time = olderval.datetime; } } if ( apr_fnmatch_test(file.string->buf) != 0 ) { // we have wildcards, expand it pool = nx_pool_create_core(); filename = file.string->buf; idx = strrchr(filename, '/'); #ifndef WIN32 flags = APR_FNM_CASE_BLIND; if ( idx == NULL ) { idx = strrchr(filename, '\\'); } #endif if ( idx == NULL ) { dirname = nx_string_create("."NX_DIR_SEPARATOR, -1); } else { dirname = nx_string_create(filename, (int) (idx + 1 - filename)); filename = idx + 1; } CHECKERR_MSG(apr_dir_open(&dir, dirname->buf, pool), "failed to open directory: %s", dirname->buf); fname = nx_string_new(); while ( apr_dir_read(&finfo, APR_FINFO_NAME | APR_FINFO_TYPE | APR_FINFO_CTIME, dir) == APR_SUCCESS ) { if ( finfo.filetype == APR_REG ) { log_debug("checking '%s' against wildcard '%s':", finfo.name, filename); if ( apr_fnmatch(filename, finfo.name, flags) == APR_SUCCESS ) { nx_string_sprintf(fname, "%s%s", dirname->buf, finfo.name); if ( (older_time == 0) || ((older_time != 0) && (finfo.ctime < older_time)) ) { log_debug("'%s' matches wildcard '%s' and is 'older', removing", fname->buf, file.string->buf); log_info("removing file %s", fname->buf); rv = apr_file_remove(fname->buf, NULL); if ( APR_STATUS_IS_ENOENT(rv) ) { } else if ( rv == APR_SUCCESS ) { } else { log_aprerror(rv, "failed to remove file '%s'", fname->buf); } _reopen_logfile(fname->buf); } } } } nx_string_free(fname); apr_pool_destroy(pool); } else { CHECKERR_MSG(apr_file_remove(file.string->buf, NULL), "failed to remove file '%s'", file.string->buf); } } catch(e) { nx_value_kill(&file); if ( pool != NULL ) { apr_pool_destroy(pool); } if ( dirname != NULL ) { nx_string_free(dirname); } log_exception(e); } }
/** Process parsed XML document */ static apt_bool_t unimrcp_client_doc_process(unimrcp_client_loader_t *loader, const char *dir_path, apr_xml_doc *doc, apr_pool_t *pool) { const apr_xml_elem *elem; const apr_xml_elem *root; const apr_xml_attr *attr; const char *version = NULL; const char *subfolder = NULL; if(!doc) { return FALSE; } root = doc->root; /* Match document name */ if(!root || strcasecmp(root->name,"unimrcpclient") != 0) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Document <%s>",root ? root->name : "null"); return FALSE; } /* Read attributes */ for(attr = root->attr; attr; attr = attr->next) { if(strcasecmp(attr->name,"version") == 0) { version = attr->value; } else if(strcasecmp(attr->name,"subfolder") == 0) { subfolder = attr->value; } } /* Check version number first */ if(!version) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Version"); return FALSE; } loader->doc = doc; /* Navigate through document */ for(elem = root->first_child; elem; elem = elem->next) { if(strcasecmp(elem->name,"properties") == 0) { unimrcp_client_properties_load(loader,elem); } else if(strcasecmp(elem->name,"components") == 0) { unimrcp_client_components_load(loader,elem); } else if(strcasecmp(elem->name,"settings") == 0) { unimrcp_client_settings_load(loader,elem); } else if(strcasecmp(elem->name,"profiles") == 0) { unimrcp_client_profiles_load(loader,elem); } else if(strcasecmp(elem->name,"misc") == 0) { unimrcp_client_misc_load(loader,elem); } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name); } } if(subfolder && *subfolder != '\0') { apr_dir_t *dir; apr_finfo_t finfo; apr_status_t rv; char *subdir_path; if (!dir_path) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Attempt to Process Subdirectory when " "Creating from Config String"); return TRUE; } if(apr_filepath_merge(&subdir_path,dir_path,subfolder,APR_FILEPATH_NATIVE,pool) == APR_SUCCESS) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Enter Directory [%s]",subdir_path); rv = apr_dir_open(&dir,subdir_path,pool); if(rv == APR_SUCCESS) { while(apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) { if(apr_fnmatch("*.xml", finfo.name, 0) == APR_SUCCESS) { unimrcp_client_load(loader,subdir_path,finfo.name); } } apr_dir_close(dir); apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Leave Directory [%s]",dir_path); } else { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Directory %s",dir_path); } } } return TRUE; }
int Command_fetch(apr_pool_t *p, const char *url, int fetch_only) { int rc = 0; const char *depends_file = NULL; // create the uri as an apr type // see https://apr.apache.org/docs/apr-util/0.9/structapr__uri__t.html // all you need to know for this program is that: // - port of 0 indicates a default / a port-less url // - path is the url as a string // - scheme is the protocol (e.g. http, ftp, etc). I *think* this allows // us to give plain old file paths if we want to, and then scheme would // be null. The code seems to suggest it, anyway. apr_uri_t info = { .port = 0 }; apr_status_t rv = apr_uri_parse(p, url, &info); check(rv = APR_SUCCESS, "Failed to parse URL: %s", url); // apr_fnmatch is apr's filename expression matcher. It follows roughly // the same rules as filename expansion in bash. The last entry can be // used to set flags that modify the pattern matching. 0 leads to defaults. // -> It returns either APR_SUCCESS or APR_FNM_NOMATCH. if (apr_fnmatch(GIT_PAT, info.path, 0) == APR_SUCCESS) { rc = Shell_exec(GIT_SH, "URL", url, NULL); check(rc == 0, "git failed."); } else if (apr_fnmatch(DEPEND_PAT, info.path, 0) == APR_SUCCESS) { // we want to call Command_depends after downloading. check (!fetch_only, "No point in fetching a DEPENDS file"); // download to depends_file, unless url is a local path. if (info.scheme) { depends_file = DEPENDS_PATH; rc = Shell_exec(CURL_SH, "URL", url, "TARGET", depends_file, NULL); check(rc == 0, "Curl failed."); } else { depends_file = info.path; } // recursively process the devpkg list log_info("Building according to DEPENDS: %s", url); rv = Command_depends(p, depends_file); check(rv == 0, "Failed to process the DEPENDS: %s", url); // return 0 because we don't actually install anything in *this* // command .. although we may have in Command_depends. A return code // of 1 means that we still need to build/install, which is not the // case here. return 0; } else if (apr_fnmatch(TAR_GZ_PAT, info.path, 0) == APR_SUCCESS) { // download if needed if (info.scheme) { rc = Shell_exec(CURL_SH, "URL", url, "TARGET", TAR_GZ_SRC, NULL); check(rc == 0, "Failed to curl source %s", url); } // build. See db.c for a discussion of the apr call. rv = apr_dir_make_recursive( BUILD_DIR, APR_UREAD | APR_UWRITE | APR_UEXECUTE, p ); check(rc == APR_SUCCESS, "Failed to make directory %s", BUILD_DIR); rc = Shell_exec(TAR_SH, "FILE", TAR_GZ_SRC, NULL); check(rc == 0, "Failed to untar %s", TAR_GZ_SRC); } else if (apr_fnmatch(TAR_BZ2_PAT, info.path, 0) == APR_SUCCESS) { /* (note: this is copy-paste code - C kinda encourages this sometimes) * Zed has a small bug in this code: he redefines rc as apr_status_t * and then uses it for the output of Shell_exec. It works, but oops. I * fixed it by using copy-pasted code from the preceding block. */ // download if needed if (info.scheme) { rc = Shell_exec(CURL_SH, "URL", url, "TARGET", TAR_BZ2_SRC, NULL); check(rc == 0, "Failed to curl source %s", url); } // build. See db.c for a discussion of the apr call. rv = apr_dir_make_recursive( BUILD_DIR, APR_UREAD | APR_UWRITE | APR_UEXECUTE, p ); check(rc == APR_SUCCESS, "Failed to make directory %s", BUILD_DIR); rc = Shell_exec(TAR_SH, "FILE", TAR_BZ2_SRC, NULL); check(rc == 0, "Failed to untar %s", TAR_BZ2_SRC); } else { sentinel("Dont know how to handle this type of url: %s", url); } return 1; // indicates an install was actually run... the only // non-error case where we get a different code is DEPEND. error: return -1; } int Command_build( apr_pool_t *p, const char *url, const char *configure_opts, const char *make_opts, const char *install_opts ) { int rc = 0; // check that build dir exists check(access(BUILD_DIR, X_OK | R_OK | W_OK) == 0, "Build directory doesn't exist: %s", BUILD_DIR); // if there's a config script, run it. if (access(CONFIG_SCRIPT, X_OK) == 0) { log_info("Has config script, running it."); rc = Shell_exec(CONFIGURE_SH, "OPTS", configure_opts, NULL); check(rc == 0, "Failed to configure."); } // make rc = Shell_exec(MAKE_SH, "OPTS", make_opts, NULL); check(rc == 0, "Failed to build."); // install. Note that if you pass install options, they have to // include the work "install", since we only add it if there aren't any lol rc = Shell_exec( INSTALL_SH, "TARGET", install_opts? install_opts : "install", NULL ); check(rc == 0, "Failed to install."); // clean up rc = Shell_exec(CLEANUP_SH, NULL); check(rc == 0, "Failed to cleanup after build."); // update the db rc = DB_update(url); check(rc == 0, "Failed to add this package to the database."); return 0; error: return -1; }