Changeset 5427:543c052527b2 in roaraudio for libroar/plugincontainer.c
- Timestamp:
- 03/20/12 03:40:15 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/plugincontainer.c
r5425 r5427 35 35 36 36 #include "libroar.h" 37 38 #ifdef ROAR_HAVE_H_DIRENT39 #include <dirent.h>40 #endif41 37 42 38 #define MAX_PLUGINS 64 … … 144 140 145 141 // plugin loading and unloading: 146 #ifdef ROAR_HAVE_H_DIRENT147 // pvn = prefix, host vendor, host name148 static struct roar_dl_lhandle * _load_from_path_pvn(const char * name,149 struct roar_dl_librarypara * para,150 const char * prefix,151 const char * hostvendor,152 const char * hostname) {153 struct roar_dl_lhandle * ret = NULL;154 int i, j;155 char path[1024];156 const char * path_format[] = {"%s/%s/%s", "%s/%s/universal", "%s/universal/universal"};157 DIR * dir;158 struct dirent * dirent;159 char file[1024];160 const char * file_format[] = {"%s/%s/%s", "%s/%s/%s" ROAR_SHARED_SUFFIX, "%s/%s/lib%s" ROAR_SHARED_SUFFIX};161 // cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para);162 //#vars: $PREFIX_PLUGINS, $hostvendor, $hostname, $name163 //#search order: $PREFIX_PLUGINS/{$hostvendor/{$hostname,universal},universal/universal}/*/{,lib}$name.so164 165 for (i = 0; i < 3; i++) {166 snprintf(path, sizeof(path), path_format[i], prefix, hostvendor, hostname);167 dir = opendir(path);168 if ( dir == NULL )169 continue;170 171 while ((dirent = readdir(dir)) != NULL) {172 if ( !strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..") )173 continue;174 175 for (j = 0; j < 3; j++) {176 snprintf(file, sizeof(file), file_format[j], path, dirent->d_name, name);177 ret = roar_dl_open(file, ROAR_DL_FLAG_DEFAULTS, 1, para);178 if ( ret != NULL ) {179 closedir(dir);180 return ret;181 }182 }183 }184 185 closedir(dir);186 }187 188 return NULL;189 }190 191 static struct roar_dl_lhandle * _load_from_path(const char * name, struct roar_dl_librarypara * para) {192 struct roar_dl_lhandle * ret = NULL;193 char * host = NULL;194 char * hostvendor_buffer = NULL;195 char * hostvendor = NULL;196 char * hostname = NULL;197 char * c, * d;198 199 if ( para->appname != NULL && para->appname[0] != 0 ) {200 host = roar_mm_strdup(para->appname);201 202 // if we are out of memory we will likely not pass the rest, so just return in error.203 if ( host == NULL )204 return NULL;205 206 hostname = host;207 c = strstr(host, "<");208 if ( c != NULL ) {209 while (c[-1] == ' ') c--;210 *c = 0;211 c++;212 while (*c == ' ' || *c == '<') c++;213 if ( *c ) {214 d = strstr(c, ">");215 if ( d != NULL )216 *d = 0;217 218 d = strstr(c, "/");219 if ( d != NULL ) {220 *d = '-';221 hostvendor = c;222 } else {223 hostvendor_buffer = roar_mm_malloc(roar_mm_strlen(c) + 1 /* tailing \0 */ + 6 /* "unreg-" */);224 225 // see above226 if ( hostvendor_buffer == NULL ) {227 roar_mm_free(host);228 return NULL;229 }230 231 strcpy(hostvendor_buffer, "unreg-");232 strcat(hostvendor_buffer, c);233 hostvendor = hostvendor_buffer;234 }235 }236 }237 }238 239 if ( hostvendor == NULL )240 hostvendor = "universal";241 242 if ( hostname == NULL )243 hostname = "universal";244 245 ret = _load_from_path_pvn(name, para, ROAR_PREFIX_PLUGINS, hostvendor, hostname);246 247 if ( host != NULL )248 roar_mm_free(host);249 if ( hostvendor_buffer != NULL )250 roar_mm_free(hostvendor_buffer);251 return ret;252 }253 #endif254 255 142 int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para) { 256 143 ssize_t idx = -1; … … 285 172 } 286 173 287 if ( strstr(name, "/") != NULL ) { 288 cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para); 289 } else { 290 #ifdef ROAR_HAVE_H_DIRENT 291 cont->handle[idx] = _load_from_path(name, para); 292 #else 293 roar_err_set(ROAR_ERROR_NOSYS); 294 return -1; 295 #endif 296 } 297 174 cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_PLUGIN, 1, para); 298 175 if ( cont->handle[idx] == NULL ) 299 176 return -1;
Note: See TracChangeset
for help on using the changeset viewer.