1 /*-------------------------------------------------------------------------
2 * C-Pluff, a plug-in framework for C
3 * Copyright 2007 Johannes Lehtinen
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *-----------------------------------------------------------------------*/
29 typedef struct plugin_data_t plugin_data_t;
31 struct plugin_data_t {
36 static void *create(cp_context_t *ctx) {
39 if ((data = malloc(sizeof(plugin_data_t))) != NULL) {
46 static int start(void *d) {
47 plugin_data_t *data = d;
48 cp_extension_t **exts;
50 exts = cp_get_extensions_info(data->ctx, "symuser.strings", NULL, NULL);
51 if (exts != NULL && exts[0] != NULL) {
54 symname = cp_lookup_cfg_value(exts[0]->configuration, "@string-symbol");
55 if (symname != NULL) {
56 data->str = cp_resolve_symbol(data->ctx, exts[0]->plugin->identifier, symname, NULL);
57 if (data->str == NULL) {
58 cp_log(data->ctx, CP_LOG_ERROR, "Could not resolve symbol specified by extension.");
61 cp_log(data->ctx, CP_LOG_ERROR, "No string-symbol attribute present in extension.");
64 cp_log(data->ctx, CP_LOG_ERROR, "No extensions available.");
67 cp_release_info(data->ctx, exts);
69 if (data->str == NULL) {
70 return CP_ERR_RUNTIME;
72 return cp_define_symbol(data->ctx, "used_string", (void *) data->str);
75 static void stop(void *d) {
76 plugin_data_t *data = d;
78 // Check that the provided string is still available
79 if (data->str != NULL) {
80 if (strcmp(data->str, "Provided string")) {
81 fputs("Provided string is not available in symuser stop function.\n", stderr);
84 cp_release_symbol(data->ctx, data->str);
88 static void destroy(void *d) {
92 CP_EXPORT cp_plugin_runtime_t su_runtime = {