comparison src/helper.cpp @ 23:65b6c64992dd

If the descriptor is one of a recognised set, actually call it. This is a much more useful check against wrongly-built plugins or plugins with unavailable dependencies than just looking up the symbol
author Chris Cannam
date Wed, 16 Nov 2016 16:12:18 +0000
parents 7eff522b23ae
children 1eefc20919cd
comparison
equal deleted inserted replaced
22:386de1be6226 23:65b6c64992dd
137 string e = DLERROR(); 137 string e = DLERROR();
138 if (e == "") return "(unknown error)"; 138 if (e == "") return "(unknown error)";
139 else return e; 139 else return e;
140 } 140 }
141 141
142 string checkLADSPAStyleDescriptorFn(void *f)
143 {
144 typedef const void *(*DFn)(unsigned long);
145 DFn fn = DFn(f);
146 unsigned long index = 0;
147 while (fn(index)) ++index;
148 if (index == 0) return "Library contains no plugins";
149 // else cerr << "Library contains " << index << " plugin(s)" << endl;
150 return "";
151 }
152
153 string checkVampDescriptorFn(void *f)
154 {
155 typedef const void *(*DFn)(unsigned int, unsigned int);
156 DFn fn = DFn(f);
157 unsigned int index = 0;
158 while (fn(1, index)) ++index;
159 if (index == 0) return "Library contains no plugins";
160 // else cerr << "Library contains " << index << " plugin(s)" << endl;
161 return "";
162 }
163
142 string check(string soname, string descriptor) 164 string check(string soname, string descriptor)
143 { 165 {
144 void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL); 166 void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL);
145 if (!handle) { 167 if (!handle) {
146 return "Unable to open plugin library: " + error(); 168 return "Unable to open plugin library: " + error();
150 if (!fn) { 172 if (!fn) {
151 return "Failed to find plugin descriptor " + descriptor + 173 return "Failed to find plugin descriptor " + descriptor +
152 " in library: " + error(); 174 " in library: " + error();
153 } 175 }
154 176
177 if (descriptor == "ladspa_descriptor") {
178 return checkLADSPAStyleDescriptorFn(fn);
179 } else if (descriptor == "dssi_descriptor") {
180 return checkLADSPAStyleDescriptorFn(fn);
181 } else if (descriptor == "vampGetPluginDescriptor") {
182 return checkVampDescriptorFn(fn);
183 } else {
184 cerr << "Note: no descriptor logic known for descriptor function \""
185 << descriptor << "\"; not actually calling it" << endl;
186 }
187
155 return ""; 188 return "";
156 } 189 }
157 190
158 int main(int argc, char **argv) 191 int main(int argc, char **argv)
159 { 192 {