2 * This file is part of Resource Organizer.
4 * Copyright (C) 2014 Nikita Zlobin <nick87720z@gmail.com>
6 * Resource Organizer is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Resource Organizer is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Resource Organizer. If not, see
18 * <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
31 #include <search-so.h>
33 static ResourceType rtype
= {
38 static ResourceHandlerFunc res_handler
;
41 describeLadspaPluginLibrary (const char * fileName
)
45 if (strcmp (fileName
+ strlen (fileName
) - strlen (".so"), ".so") != 0) return;
47 // FIXME: Strange leaks in dlopen(), need valgrind self-check
48 dl_Handle
= dlopen (fileName
, RTLD_NOW
| RTLD_LOCAL
);
50 fprintf (stderr
, "dlerror: %s\n", dlerror());
54 /* This is a file and the file is a shared library! */
55 LADSPA_Descriptor_Function descFunc
;
58 descFunc
= (LADSPA_Descriptor_Function
) dlsym (dl_Handle
, "ladspa_descriptor");
59 if (dlerror() == NULL
&& descFunc
) {
60 const LADSPA_Descriptor
* plugDesc
;
63 Resource res
= { .type
= & rtype
,
64 .file
= (char *)fileName
,
66 size_t base_size
= strlen (":/") + strlen (res
.type
->label
) + strlen (fileName
) + 1;
68 // FIXME: Strange leaks in descFunc(), need valgrind self-check
69 for( ; (plugDesc
= descFunc (lIndex
)) != NULL
; lIndex
++ )
71 size_t l_size
, old_size
= 0;
72 char * url
= NULL
, * url_label
;
74 l_size
= strlen (plugDesc
->Label
);
75 if (l_size
> old_size
)
76 url
= realloc (url
, base_size
+ l_size
);
80 url_label
= (res
.url
= url
) + base_size
- 1;
81 sprintf (url
, "%s:%s/", res
.type
->label
, fileName
);
83 sprintf (url_label
, "%s", plugDesc
->Label
);
85 res
.name
= (char *)plugDesc
->Name
;
86 res
.author
= (char *)plugDesc
->Maker
;
94 void ladspaPathIterate (void)
96 pathIterate ("LADSPA_PATH", describeLadspaPluginLibrary
);
99 void ladspaResourceHandler (ResourceHandlerFunc cb_func
)
101 res_handler
= cb_func
;