| 49 | static comdb2_queue_consumer_t *queue_consumer_handlers[CONSUMER_TYPE_LAST]; |
| 50 | |
| 51 | static int install_plugin_int(comdb2_plugin_t *new_plugin) |
| 52 | { |
| 53 | int i; |
| 54 | assert(new_plugin); |
| 55 | |
| 56 | for (i = 0; gbl_plugins[i]; ++i) { |
| 57 | /* Do not allow similar plugins with same version. */ |
| 58 | if ((strcmp(gbl_plugins[i]->name, new_plugin->name) == 0) && |
| 59 | gbl_plugins[i]->version == new_plugin->version) { |
| 60 | logmsg(LOGMSG_ERROR, "Plugin %s:%d already installed " |
| 61 | "overriding..\n", |
| 62 | new_plugin->name, new_plugin->version); |
| 63 | return 1; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (i >= MAXPLUGINS) { |
| 68 | logmsg(LOGMSG_ERROR, "Maximum number of plugins already installed. " |
| 69 | "Ignoring further requests to install " |
| 70 | "plugin(s).\n"); |
| 71 | return 1; |
| 72 | } |
| 73 | |
| 74 | /* TODO: Check plugin version */ |
| 75 | if (new_plugin->type >= COMDB2_PLUGIN_LAST) { |
| 76 | logmsg(LOGMSG_ERROR, "Invalid plugin type for %s.\n", new_plugin->name); |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | Initialize the plugin and add it to the global list of installed plugins. |
| 82 | */ |
| 83 | if (new_plugin->init_cb && new_plugin->init_cb(NULL)) { |
| 84 | logmsg(LOGMSG_ERROR, "Plugin initialization failed (%s).", |
| 85 | new_plugin->name); |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | switch (new_plugin->type) { |
| 90 | case COMDB2_PLUGIN_APPSOCK: { |
| 91 | comdb2_appsock_t *appsock; |
| 92 | appsock = (comdb2_appsock_t *)new_plugin->data; |
| 93 | |
| 94 | /* |
| 95 | Check whether a similar appsock handler has already been |
| 96 | added to the hash. |
| 97 | */ |
| 98 | if (hash_find_readonly(gbl_appsock_hash, &appsock->name)) { |
| 99 | logmsg(LOGMSG_FATAL, "duplicate appsock handler found\n"); |
| 100 | return 1; |
| 101 | } |
| 102 | hash_add(gbl_appsock_hash, appsock); |
| 103 | break; |
| 104 | } |
| 105 | case COMDB2_PLUGIN_OPCODE: { |
| 106 | comdb2_opcode_t *opcode; |
| 107 | opcode = (comdb2_opcode_t *)new_plugin->data; |
| 108 |
no test coverage detected