aboutsummaryrefslogtreecommitdiffstats
path: root/Audio-Common/filescan-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'Audio-Common/filescan-utils.c')
-rw-r--r--Audio-Common/filescan-utils.c124
1 files changed, 0 insertions, 124 deletions
diff --git a/Audio-Common/filescan-utils.c b/Audio-Common/filescan-utils.c
deleted file mode 100644
index 4a5613f..0000000
--- a/Audio-Common/filescan-utils.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Fulup Ar Foll <fulup@iot.bzh>
- *
- * 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.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include <sys/prctl.h>
-#include <dirent.h>
-
-#include "audio-common.h"
-
-
-
-// List Avaliable Configuration Files
-PUBLIC json_object* ScanForConfig (const char* searchPath, CtlScanDirModeT mode, const char *pre, const char *ext) {
- json_object *responseJ;
- char *dirPath;
- char* dirList= strdup(searchPath);
- size_t extLen=0;
-
- void ScanDir (char *searchPath) {
- DIR *dirHandle;
- struct dirent *dirEnt;
- dirHandle = opendir (searchPath);
- if (!dirHandle) {
- AFB_DEBUG ("CONFIG-SCANNING dir=%s not readable", searchPath);
- return;
- }
-
- //AFB_NOTICE ("CONFIG-SCANNING:ctl_listconfig scanning: %s", searchPath);
- while ((dirEnt = readdir(dirHandle)) != NULL) {
-
- // recursively search embedded directories ignoring any directory starting by '.' or '_'
- if (dirEnt->d_type == DT_DIR && mode == CTL_SCAN_RECURSIVE) {
- char newpath[CONTROL_MAXPATH_LEN];
- if (dirEnt->d_name[0]=='.' || dirEnt->d_name[0]=='_') continue;
-
- strncpy(newpath, searchPath, sizeof(newpath));
- strncat(newpath, "/", sizeof(newpath));
- strncat(newpath, dirEnt->d_name, sizeof(newpath));
- ScanDir(newpath);
- continue;
- }
-
- // Unknown type is accepted to support dump filesystems
- if (dirEnt->d_type == DT_REG || dirEnt->d_type == DT_UNKNOWN) {
-
- // check prefix and extention
- size_t extIdx=strlen(dirEnt->d_name)-extLen;
- if (extIdx <= 0) continue;
- if (pre && !strcasestr (dirEnt->d_name, pre)) continue;
- if (ext && strcasecmp (ext, &dirEnt->d_name[extIdx])) continue;
-
- struct json_object *pathJ = json_object_new_object();
- json_object_object_add(pathJ, "fullpath", json_object_new_string(searchPath));
- json_object_object_add(pathJ, "filename", json_object_new_string(dirEnt->d_name));
- json_object_array_add(responseJ, pathJ);
- }
- }
- closedir(dirHandle);
- }
-
- if (ext) extLen=strlen(ext);
- responseJ = json_object_new_array();
-
- // loop recursively on dir
- for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
- ScanDir (dirPath);
- }
-
- free (dirList);
- return (responseJ);
-}
-
-PUBLIC const char *GetMidleName(const char*name) {
- char *fullname = strdup(name);
-
- for (int idx = 0; fullname[idx] != '\0'; idx++) {
- int start;
- if (fullname[idx] == '-') {
- start = idx + 1;
- for (int jdx = start; ; jdx++) {
- if (fullname[jdx] == '-' || fullname[jdx] == '.' || fullname[jdx] == '\0') {
- fullname[jdx] = '\0';
- return &fullname[start];
- break;
- }
- }
- break;
- }
- }
- return "";
-}
-
-PUBLIC const char *GetBinderName() {
- char psName[17];
- static char *binderName=NULL;
-
- if (binderName) return binderName;
-
- binderName= getenv("AFB_BINDER_NAME");
- if (!binderName) {
- // retrieve binder name from process name afb-name-trailer
- prctl(PR_GET_NAME, psName,NULL,NULL,NULL);
- binderName=(char*)GetMidleName(psName);
- }
-
- return binderName;
-} \ No newline at end of file
cm"> * * 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, something express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Reference: * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values */ #ifndef _CTL_CONFIG_INCLUDE_ #define _CTL_CONFIG_INCLUDE_ #ifdef __cplusplus extern "C" { #endif #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include "ctl-plugin.h" #include <filescan-utils.h> #include <wrap-json.h> #ifdef CONTROL_SUPPORT_LUA #include "ctl-lua.h" #endif #ifndef CONTROL_MAXPATH_LEN #define CONTROL_MAXPATH_LEN 255 #endif #ifndef CONTROL_CONFIG_PRE #define CONTROL_CONFIG_PRE "onload" #endif #ifndef CTL_PLUGIN_EXT #define CTL_PLUGIN_EXT ".ctlso" #define CTL_SCRIPT_EXT ".lua" #endif #define LUA_ACTION_PREFIX "lua://" #define API_ACTION_PREFIX "api://" #define PLUGIN_ACTION_PREFIX "plugin://" typedef struct ConfigSectionS { const char *key; const char *uid; const char *info; const char *prefix; int (*loadCB)(AFB_ApiT apihandle, struct ConfigSectionS *section, json_object *sectionJ); void *handle; CtlActionT *actions; } CtlSectionT; typedef struct { const char *api; const char *uid; const char *info; const char *version; const char *author; const char *date; const char *prefix; json_object *configJ; json_object *requireJ; CtlSectionT *sections; void *external; } CtlConfigT; // This should not be global as application may want to define their own sections typedef enum { CTL_SECTION_PLUGIN, CTL_SECTION_ONLOAD, CTL_SECTION_CONTROL, CTL_SECTION_EVENT, CTL_SECTION_HAL, CTL_SECTION_ENDTAG, } SectionEnumT; // ctl-action.c extern int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi); extern CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi); extern void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ); extern int ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ); extern int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *, int exportApi); extern int ActionLabelToIndex(CtlActionT* actions, const char* actionLabel); // ctl-config.c extern int CtlConfigMagicNew(); extern json_object* CtlConfigScan(const char *dirList, const char *prefix) ; extern char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ); extern char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) ; extern void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ); extern int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) ; extern CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) ; extern CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) ; extern int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections); #define CtlLoadMetaData(api, filepath) CtlLoadMetaDataUsingPrefix(api, filepath, NULL) // ctl-event.c extern int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ); extern void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ); extern void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ); // ctl-control.c extern int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); // ctl-onload.c extern int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); // ctl-plugin.c extern int PluginConfig(AFB_ApiT UNUSED_ARG(apiHandle), CtlSectionT *section, json_object *pluginsJ); extern int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ); #ifdef __cplusplus } #endif #endif /* _CTL_CONFIG_INCLUDE_ */