Changeset 5427:543c052527b2 in roaraudio


Ignore:
Timestamp:
03/20/12 03:40:15 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

support usage of plugin path also outside plugin containers

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/roardl.h

    r5381 r5427  
    4040 
    4141#define ROAR_DL_FLAG_DEFAULTS          -1 
     42#define ROAR_DL_FLAG_PLUGIN            -2 
    4243#define ROAR_DL_FLAG_NONE               0x0000 
    4344#define ROAR_DL_FLAG_STATIC             0x0001 /* plugins are linked statically -lfoo */ 
    4445#define ROAR_DL_FLAG_LAZY               0x0002 
     46#define ROAR_DL_FLAG_PLUGINPATH         0x0004 /* Use plugin search path */ 
    4547 
    4648#define ROAR_DL_HANDLE_DEFAULT          ((struct roar_dl_lhandle*)(void*)0) 
  • libroar/plugincontainer.c

    r5425 r5427  
    3535 
    3636#include "libroar.h" 
    37  
    38 #ifdef ROAR_HAVE_H_DIRENT 
    39 #include <dirent.h> 
    40 #endif 
    4137 
    4238#define MAX_PLUGINS 64 
     
    144140 
    145141// plugin loading and unloading: 
    146 #ifdef ROAR_HAVE_H_DIRENT 
    147 // pvn = prefix, host vendor, host name 
    148 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, $name 
    163 //#search order: $PREFIX_PLUGINS/{$hostvendor/{$hostname,universal},universal/universal}/*/{,lib}$name.so 
    164  
    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 above 
    226      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 #endif 
    254  
    255142int roar_plugincontainer_load(struct roar_plugincontainer * cont, const char * name, struct roar_dl_librarypara * para) { 
    256143 ssize_t idx = -1; 
     
    285172 } 
    286173 
    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); 
    298175 if ( cont->handle[idx] == NULL ) 
    299176  return -1; 
  • libroar/roardl.c

    r5381 r5427  
    3636#include "libroar.h" 
    3737 
     38#ifdef ROAR_HAVE_H_DIRENT 
     39#include <dirent.h> 
     40#endif 
     41 
    3842#if defined(ROAR_HAVE_LIBDL) && !defined(RTLD_NEXT) 
    3943#define RTLD_NEXT ((void *) -1L) 
     
    191195#endif 
    192196 
     197#ifdef ROAR_HAVE_H_DIRENT 
     198// pvn = prefix, host vendor, host name 
     199static struct roar_dl_lhandle * _load_from_path_pvn(const char * name, 
     200                                                    int flags, int ra_init, 
     201                                                    struct roar_dl_librarypara * para, 
     202                                                    const char * prefix, 
     203                                                    const char * hostvendor, 
     204                                                    const char * hostname) { 
     205 struct roar_dl_lhandle * ret = NULL; 
     206 int i, j; 
     207 char path[1024]; 
     208 const char * path_format[] = {"%s/%s/%s", "%s/%s/universal", "%s/universal/universal"}; 
     209 DIR * dir; 
     210 struct dirent * dirent; 
     211 char file[1024]; 
     212 const char * file_format[] = {"%s/%s/%s", "%s/%s/%s" ROAR_SHARED_SUFFIX, "%s/%s/lib%s" ROAR_SHARED_SUFFIX}; 
     213//  cont->handle[idx] = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, para); 
     214//#vars: $PREFIX_PLUGINS, $hostvendor, $hostname, $name 
     215//#search order: $PREFIX_PLUGINS/{$hostvendor/{$hostname,universal},universal/universal}/*/{,lib}$name.so 
     216 
     217 for (i = 0; i < 3; i++) { 
     218  snprintf(path, sizeof(path), path_format[i], prefix, hostvendor, hostname); 
     219  dir = opendir(path); 
     220  if ( dir == NULL ) 
     221   continue; 
     222 
     223  while ((dirent = readdir(dir)) != NULL) { 
     224   if ( !strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..") ) 
     225    continue; 
     226 
     227   for (j = 0; j < 3; j++) { 
     228    snprintf(file, sizeof(file), file_format[j], path, dirent->d_name, name); 
     229    ret = roar_dl_open(file, flags, ra_init, para); 
     230    if ( ret != NULL ) { 
     231     closedir(dir); 
     232     return ret; 
     233    } 
     234   } 
     235  } 
     236 
     237  closedir(dir); 
     238 } 
     239 
     240 return NULL; 
     241} 
     242 
     243static struct roar_dl_lhandle * _load_from_path(const char * name, int flags, int ra_init, 
     244                                                struct roar_dl_librarypara * para) { 
     245 struct roar_dl_lhandle * ret = NULL; 
     246 char * host = NULL; 
     247 char * hostvendor_buffer = NULL; 
     248 char * hostvendor = NULL; 
     249 char * hostname = NULL; 
     250 char * c, * d; 
     251 
     252 if ( para != NULL && para->appname != NULL && para->appname[0] != 0 ) { 
     253  host = roar_mm_strdup(para->appname); 
     254 
     255  // if we are out of memory we will likely not pass the rest, so just return in error. 
     256  if ( host == NULL ) 
     257   return NULL; 
     258 
     259  hostname = host; 
     260  c = strstr(host, "<"); 
     261  if ( c != NULL ) { 
     262   while (c[-1] == ' ') c--; 
     263   *c = 0; 
     264   c++; 
     265   while (*c == ' ' || *c == '<') c++; 
     266   if ( *c ) { 
     267    d = strstr(c, ">"); 
     268    if ( d != NULL ) 
     269     *d = 0; 
     270 
     271    d = strstr(c, "/"); 
     272    if ( d != NULL ) { 
     273     *d = '-'; 
     274     hostvendor = c; 
     275    } else { 
     276     hostvendor_buffer = roar_mm_malloc(roar_mm_strlen(c) + 1 /* tailing \0 */ + 6 /* "unreg-" */); 
     277 
     278     // see above 
     279     if ( hostvendor_buffer == NULL ) { 
     280      roar_mm_free(host); 
     281      return NULL; 
     282     } 
     283 
     284     strcpy(hostvendor_buffer, "unreg-"); 
     285     strcat(hostvendor_buffer, c); 
     286     hostvendor = hostvendor_buffer; 
     287    } 
     288   } 
     289  } 
     290 } 
     291 
     292 if ( hostvendor == NULL ) 
     293  hostvendor = "universal"; 
     294 
     295 if ( hostname == NULL ) 
     296  hostname = "universal"; 
     297 
     298 ret = _load_from_path_pvn(name, flags, ra_init, para, ROAR_PREFIX_PLUGINS, hostvendor, hostname); 
     299 
     300 if ( host != NULL ) 
     301  roar_mm_free(host); 
     302 if ( hostvendor_buffer != NULL ) 
     303  roar_mm_free(hostvendor_buffer); 
     304 return ret; 
     305} 
     306#endif 
     307 
     308static struct roar_dl_lhandle * _roar_dl_open_pluginpath(const char * filename, int flags, 
     309                                      int ra_init, struct roar_dl_librarypara * para) { 
     310 flags |= ROAR_DL_FLAG_PLUGINPATH; 
     311 flags -= ROAR_DL_FLAG_PLUGINPATH; 
     312 
     313#ifdef ROAR_HAVE_H_DIRENT 
     314 return _load_from_path(filename, flags, ra_init, para); 
     315#else 
     316 // fall back to system open function. 
     317 return roar_dl_open(filename, flags, ra_init, para); 
     318#endif 
     319} 
     320 
    193321struct roar_dl_lhandle * roar_dl_open(const char * filename, int flags, 
    194322                                      int ra_init, struct roar_dl_librarypara * para) { 
     
    203331 int err; 
    204332 
    205  if ( flags == ROAR_DL_FLAG_DEFAULTS ) 
    206   flags = ROAR_DL_FLAG_NONE; 
     333 switch (flags) { 
     334  case ROAR_DL_FLAG_DEFAULTS: flags = ROAR_DL_FLAG_NONE;       break; 
     335  case ROAR_DL_FLAG_PLUGIN:   flags = ROAR_DL_FLAG_PLUGINPATH; break; 
     336 } 
     337 
     338 if ( flags & ROAR_DL_FLAG_PLUGINPATH ) 
     339  return _roar_dl_open_pluginpath(filename, flags, ra_init, para); 
    207340 
    208341#if defined(ROAR_HAVE_LIBDL) 
  • roarclients/roarpluginrunner.c

    r5381 r5427  
    5353 
    5454static int do_run(const char * name) { 
    55  struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_DEFAULTS, 1, g_para); 
     55 struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_PLUGIN, 1, g_para); 
    5656 
    5757 if ( lhandle == NULL ) 
     
    110110 
    111111static int do_explain(const char * name) { 
    112  struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_LAZY, 0, NULL); 
     112 struct roar_dl_lhandle * lhandle = roar_dl_open(name, ROAR_DL_FLAG_LAZY|ROAR_DL_FLAG_PLUGINPATH, 0, g_para); 
    113113 struct roar_dl_libraryinst * (*func)(struct roar_dl_librarypara * para); 
    114114 struct roar_dl_libraryinst * lib; 
  • roard/plugins.c

    r5381 r5427  
    161161 } 
    162162 
    163  next->lhandle = roar_dl_open(filename, ROAR_DL_FLAG_DEFAULTS, 0 /* we delay this until plugins_init() */, para); 
     163 next->lhandle = roar_dl_open(filename, ROAR_DL_FLAG_PLUGIN, 0 /* we delay this until plugins_init() */, para); 
    164164 roar_dl_para_unref(para); 
    165165 
Note: See TracChangeset for help on using the changeset viewer.