/* * Parse the plugin definition passed in. * * The definition is in this form: * * mssqlvdi:instance=<instance>:database=<databasename>: */ static bRC parse_plugin_definition(bpContext *ctx, void *value) { int i; bool keep_existing; char *plugin_definition, *bp, *argument, *argument_value; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx || !value) { return bRC_Error; } keep_existing = (p_ctx->plugin_options) ? true : false; /* * Parse the plugin definition. * Make a private copy of the whole string. */ plugin_definition = bstrdup((char *)value); bp = strchr(plugin_definition, ':'); if (!bp) { Jmsg(ctx, M_FATAL, "Illegal plugin definition %s\n", plugin_definition); Dmsg(ctx, dbglvl, "Illegal plugin definition %s\n", plugin_definition); goto bail_out; } /* * Skip the first ':' */ bp++; while (bp) { if (strlen(bp) == 0) { break; } /* * Each argument is in the form: * <argument> = <argument_value> * * So we setup the right pointers here, argument to the beginning * of the argument, argument_value to the beginning of the argument_value. */ argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { Jmsg(ctx, M_FATAL, "Illegal argument %s without value\n", argument); Dmsg(ctx, dbglvl, "Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; /* * See if there are more arguments and setup for the next run. */ bp = strchr(argument_value, ':'); if (bp) { *bp++ = '\0'; } for (i = 0; plugin_arguments[i].name; i++) { if (bstrcasecmp(argument, plugin_arguments[i].name)) { char **str_destination = NULL; bool *bool_destination = NULL; switch (plugin_arguments[i].type) { case argument_instance: str_destination = &p_ctx->instance; break; case argument_database: str_destination = &p_ctx->database; break; case argument_username: str_destination = &p_ctx->username; break; case argument_password: str_destination = &p_ctx->password; break; case argument_norecovery: bool_destination = &p_ctx->DoNoRecovery; break; case argument_replace: bool_destination = &p_ctx->ForceReplace; break; case argument_recover_after_restore: bool_destination = &p_ctx->RecoverAfterRestore; break; case argument_stopbeforemark: str_destination = &p_ctx->stopbeforemark; break; case argument_stopatmark: str_destination = &p_ctx->stopatmark; break; case argument_stopat: str_destination = &p_ctx->stopat; break; default: break; } /* * Keep the first value, ignore any next setting. */ if (str_destination) { if (keep_existing) { set_string_if_null(str_destination, argument_value); } else { set_string(str_destination, argument_value); } } /* * Set any boolean variable. */ if (bool_destination) { *bool_destination = parse_boolean(argument_value); } /* * When we have a match break the loop. */ break; } } /* * Got an invalid keyword ? */ if (!plugin_arguments[i].name) { Jmsg(ctx, M_FATAL, "Illegal argument %s with value %s in plugin definition\n", argument, argument_value); Dmsg(ctx, dbglvl, "Illegal argument %s with value %s in plugin definition\n", argument, argument_value); goto bail_out; } } free(plugin_definition); return bRC_OK; bail_out: free(plugin_definition); return bRC_Error; }
/* * Parse the plugin definition passed in. * * The definition is in this form: * * rados: */ static bRC parse_plugin_definition(bpContext *ctx, void *value) { int i; bool keep_existing; char *plugin_definition, *bp, *argument, *argument_value; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx || !value) { return bRC_Error; } keep_existing = (p_ctx->plugin_options) ? true : false; /* * Parse the plugin definition. * Make a private copy of the whole string. */ plugin_definition = bstrdup((char *)value); bp = strchr(plugin_definition, ':'); if (!bp) { Jmsg(ctx, M_FATAL, "Illegal plugin definition %s\n", plugin_definition); Dmsg(ctx, dbglvl, "Illegal plugin definition %s\n", plugin_definition); goto bail_out; } /* * Skip the first ':' */ bp++; while (bp) { if (strlen(bp) == 0) { break; } /* * Each argument is in the form: * <argument> = <argument_value> * * So we setup the right pointers here, argument to the beginning * of the argument, argument_value to the beginning of the argument_value. */ argument = bp; argument_value = strchr(bp, '='); if (!argument_value) { Jmsg(ctx, M_FATAL, "Illegal argument %s without value\n", argument); Dmsg(ctx, dbglvl, "Illegal argument %s without value\n", argument); goto bail_out; } *argument_value++ = '\0'; /* * See if there are more arguments and setup for the next run. */ bp = argument_value; do { bp = strchr(bp, ':'); if (bp) { if (*(bp - 1) != '\\') { *bp++ = '\0'; break; } else { bp++; } } } while (bp); for (i = 0; plugin_arguments[i].name; i++) { if (bstrcasecmp(argument, plugin_arguments[i].name)) { char **str_destination = NULL; switch (plugin_arguments[i].type) { case argument_conffile: str_destination = &p_ctx->rados_conffile; break; case argument_poolname: str_destination = &p_ctx->rados_poolname; break; #if defined(HAVE_RADOS_NAMESPACES) && defined(LIBRADOS_ALL_NSPACES) case argument_namespace: str_destination = &p_ctx->rados_namespace; break; #endif case argument_snapshotname: str_destination = &p_ctx->rados_snapshotname; break; default: break; } /* * Keep the first value, ignore any next setting. */ if (str_destination) { if (keep_existing) { set_string_if_null(str_destination, argument_value); } else { set_string(str_destination, argument_value); } } /* * When we have a match break the loop. */ break; } } /* * Got an invalid keyword ? */ if (!plugin_arguments[i].name) { Jmsg(ctx, M_FATAL, "Illegal argument %s with value %s in plugin definition\n", argument, argument_value); Dmsg(ctx, dbglvl, "Illegal argument %s with value %s in plugin definition\n", argument, argument_value); goto bail_out; } } free(plugin_definition); return bRC_OK; bail_out: free(plugin_definition); return bRC_Error; }
/* * Parse the plugin definition passed in. * * The definition is in this form: * * bpipe:file=<filepath>:read=<readprogram>:write=<writeprogram> */ static bRC parse_plugin_definition(bpContext *ctx, void *value) { int i, cnt; char *plugin_definition, *bp, *argument, *argument_value; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; bool keep_existing; bool compatible = true; if (!p_ctx || !value) { return bRC_Error; } keep_existing = (p_ctx->plugin_options) ? true : false; /* * Parse the plugin definition. * Make a private copy of the whole string. */ plugin_definition = bstrdup((char *)value); bp = strchr(plugin_definition, ':'); if (!bp) { Jmsg(ctx, M_FATAL, "bpipe-fd: Illegal plugin definition %s\n", plugin_definition); Dmsg(ctx, dbglvl, "bpipe-fd: Illegal plugin definition %s\n", plugin_definition); goto bail_out; } /* * Skip the first ':' */ bp++; /* * See if we are parsing a new plugin definition e.g. one with keywords. */ argument = bp; while (argument) { if (strlen(argument) == 0) { break; } for (i = 0; plugin_arguments[i].name; i++) { if (bstrncasecmp(argument, plugin_arguments[i].name, strlen(plugin_arguments[i].name))) { compatible = false; break; } } if (!plugin_arguments[i].name && !compatible) { /* * Parsing something fishy ? e.g. partly with known keywords. */ Jmsg(ctx, M_FATAL, "bpipe-fd: Found mixing of old and new syntax, please fix your plugin definition\n", plugin_definition); Dmsg(ctx, dbglvl, "bpipe-fd: Found mixing of old and new syntax, please fix your plugin definition\n", plugin_definition); goto bail_out; } argument = strchr(argument, ':'); if (argument) { argument++; } } /* * Start processing the definition, if compatible is left set we are pretending that we are * parsing a plugin definition in the old syntax and hope for the best. */ cnt = 1; while (bp) { if (strlen(bp) == 0) { break; } argument = bp; if (compatible) { char **str_destination = NULL; /* * See if there are more arguments and setup for the next run. */ do { bp = strchr(bp, ':'); if (bp) { if (*(bp - 1) != '\\') { *bp++ = '\0'; break; } else { bp++; } } } while (bp); /* * See which field this is in the argument string. */ switch (cnt) { case 1: str_destination = &p_ctx->fname; break; case 2: str_destination = &p_ctx->reader; break; case 3: str_destination = &p_ctx->writer; break; default: break; } if (str_destination) { if (keep_existing) { /* * Keep the first value, ignore any next setting. */ set_string_if_null(str_destination, argument); } else { /* * Overwrite any existing value. */ set_string(str_destination, argument); } } } else { /* * Each argument is in the form: * <argument> = <argument_value> * * So we setup the right pointers here, argument to the beginning * of the argument, argument_value to the beginning of the argument_value. */ argument_value = strchr(bp, '='); *argument_value++ = '\0'; /* * See if there are more arguments and setup for the next run. */ bp = argument_value; do { bp = strchr(bp, ':'); if (bp) { if (*(bp - 1) != '\\') { *bp++ = '\0'; break; } else { bp++; } } } while (bp); for (i = 0; plugin_arguments[i].name; i++) { if (bstrncasecmp(argument, plugin_arguments[i].name, plugin_arguments[i].cmp_length)) { char **str_destination = NULL; switch (plugin_arguments[i].type) { case argument_file: str_destination = &p_ctx->fname; break; case argument_reader: str_destination = &p_ctx->reader; break; case argument_writer: str_destination = &p_ctx->writer; break; default: break; } if (str_destination) { if (keep_existing) { /* * Keep the first value, ignore any next setting. */ set_string_if_null(str_destination, argument_value); } else { /* * Overwrite any existing value. */ set_string(str_destination, argument_value); } } /* * When we have a match break the loop. */ break; } } /* * Got an invalid keyword ? */ if (!plugin_arguments[i].name) { Jmsg(ctx, M_FATAL, "bpipe-fd: Illegal argument %s with value %s in plugin definition\n", argument, argument_value); Dmsg(ctx, dbglvl, "bpipe-fd: Illegal argument %s with value %s in plugin definition\n", argument, argument_value); goto bail_out; } } cnt++; } free(plugin_definition); return bRC_OK; bail_out: free(plugin_definition); return bRC_Error; }