TC_TEST_END



/*************************************************************************/

static int test_registry_all(void)
{
    int errors = 0;
    factory = tc_new_module_factory(".", TC_STATS);
    if (!factory) {
        tc_log_error(__FILE__,
                     "cannot create the module factory (all test aborted)");
        errors = 1;
    } else {

        TC_RUN_TEST(create_destroy);
        TC_RUN_TEST(lookup_existent1);
        TC_RUN_TEST(lookup_inexistent1);

        tc_del_module_factory(factory);
    }
    return errors;
}
int main(int argc, char *argv[])
{
    /* needed by filter modules */
    TCVHandle tcv_handle = tcv_init();
    CmdLet cmdlet = cmdlet_usage;
    int ch, ret, status, i = 0;

    CmdLetData cdata = {
        .modpath = MOD_PATH,
        .factory = NULL,
        .modsnum = 0,
    };

    ac_init(AC_ALL);
    tc_set_config_dir(NULL);
    libtc_init(&argc, &argv);

    filter[0].id = 0; /* to make gcc happy */
    for (i = 0; i < MAX_MODS; i++) {
        modrequest_init(&cdata.mods[i]);
    }

    while (1) {
        ch = getopt(argc, argv, "LCd:?vhm:");
        if (ch == -1) {
            break;
        }

        switch (ch) {
          case 'L':
            cmdlet = cmdlet_list;
            break;
          case 'C':
            cmdlet = cmdlet_check;
            break;
          case 'd':
            if (optarg[0] == '-') {
                cmdlet_usage(&cdata, argc, argv);
                return STATUS_BAD_PARAM;
            }
            verbose = atoi(optarg);
            break;
          case 'm':
            cdata.modpath = optarg;
            break;
          case 'v':
            version();
            return STATUS_OK;
          case '?': /* fallthrough */
          case 'h': /* fallthrough */
          default:
            cmdlet_usage(&cdata, argc, argv);
            return STATUS_OK;
        }
    }

    /* XXX: watch out here */
    argc -= optind;
    argv += optind;

    /* 
     * we can't distinguish from OMS and NMS modules at glance, so try
     * first using new module system
     */
    cdata.factory = tc_new_module_factory(cdata.modpath, verbose);

    status = cmdlet(&cdata, argc, argv);

    ret = tc_del_module_factory(cdata.factory); /* XXX: unchecked */
    tcv_free(tcv_handle);
    return status;
}
Example #3
0
int main(int argc, char *argv[])
{
    int ch;
    const char *filename = NULL;
    const char *modpath = MOD_PATH;
#ifdef ENABLE_EXPERIMENTAL    
    const char *modtype = "filter";
    const char *modarg = ""; /* nothing */
    const char *modcfg = ""; /* nothing */
#endif
    const char *socketfile = NULL;
    char options[OPTS_SIZE] = { '\0', };
    int print_mod = 0;
    int connect_socket = 0;
    int ret = 0;
    int status = STATUS_NO_MODULE;

    /* needed by filter modules */
    TCVHandle tcv_handle = tcv_init();
#ifdef ENABLE_EXPERIMENTAL
    TCFactory factory = NULL;
    TCModule module = NULL;
#endif

    vframe_list_t ptr;

    memset(&ptr, 0, sizeof(ptr));

    ac_init(AC_ALL);
    tc_config_set_dir(NULL);

    if (argc == 1) {
        usage();
        return STATUS_BAD_PARAM;
    }

    libtc_init(&argc, &argv);

    while (1) {
#ifdef ENABLE_EXPERIMENTAL
        ch = getopt(argc, argv, "C:d:i:?vhpm:M:s:t:");
#else /* !ENABLE_EXPERIMENTAL */
        ch = getopt(argc, argv, "d:i:?vhps:");
#endif
        if (ch == -1) {
            break;
        }

        switch (ch) {
          case 'd':
            if (optarg[0] == '-') {
                usage();
                return STATUS_BAD_PARAM;
            }
            verbose = atoi(optarg);
            break;
          case 'i':
            if (optarg[0] == '-') {
                usage();
                return STATUS_BAD_PARAM;
            }
            filename = optarg;
            break;
#ifdef ENABLE_EXPERIMENTAL
          case 'C':
            modcfg = optarg;
            break;
          case 'm':
            modpath = optarg;
            break;
          case 'M':
            modarg = optarg;
            break;
          case 't':
            if (!optarg) {
                usage();
                return STATUS_BAD_PARAM;
            }
            if (!strcmp(optarg, "filter")
             || !strcmp(optarg, "encode")
             || !strcmp(optarg, "multiplex")) {
                modtype = optarg;
            } else {
                modtype = NULL;
            }
            break;
#endif
          case 's':
            if (optarg[0] == '-') {
                usage();
                return STATUS_BAD_PARAM;
            }
            connect_socket = 1;
            socketfile = optarg;
            break;
          case 'p':
            print_mod = 1;
            break;
          case 'v':
            version();
            return STATUS_OK;
          case '?': /* fallthrough */
          case 'h': /* fallthrough */
          default:
            usage();
            return STATUS_OK;
        }
    }

    if (print_mod) {
        printf("%s\n", modpath);
        return STATUS_OK;
    }

    if (connect_socket) {
        do_connect_socket(socketfile);
        return STATUS_OK;
    }

    if (!filename) {
        usage();
        return STATUS_BAD_PARAM;
    }

#ifdef ENABLE_EXPERIMENTAL
    if (!modtype || !strcmp(modtype, "import")) {
        tc_log_error(EXE, "Unknown module type (not in filter, encode, multiplex)");
        return STATUS_BAD_PARAM;
    }

    if (strlen(modcfg) > 0 && strlen(modarg) > 0) {
        tc_log_error(EXE, "Cannot configure and inspect module on the same time");
        return STATUS_BAD_PARAM;
    }

    /* 
     * we can't distinguish from OMS and NMS modules at glance, so try
     * first using new module system
     */
    factory = tc_new_module_factory(modpath, TC_MAX(verbose - 4, 0));
    module = tc_new_module(factory, modtype, filename, TC_NONE);

    if (module != NULL) {
        const char *answer = NULL;

        if (verbose >= TC_DEBUG) {
            tc_log_info(EXE, "using new module system");
        }
        if (strlen(modcfg) > 0) {
            int ret = tc_module_configure(module, modcfg, tc_get_vob());
            if (ret == TC_OK) {
                status = STATUS_OK;
            } else {
                status = STATUS_MODULE_FAILED;
                tc_log_error(EXE, "configure returned error");
            }
            tc_module_stop(module);
        } else {
            if (verbose >= TC_INFO) {
                /* overview and options */
                tc_module_inspect(module, "help", &answer);
                puts(answer);
                /* module capabilities */
                tc_module_show_info(module, verbose);
            }
            if (strlen(modarg) > 0) {
                tc_log_info(EXE, "informations about '%s' for "
                                 "module:", modarg);
                tc_module_inspect(module, modarg, &answer);
                puts(answer);
            }
            status = STATUS_OK;
        }
        tc_del_module(factory, module);
    } else if (!strcmp(modtype, "filter")) 
#endif /* ENABLE_EXPERIMENTAL */
    {
        char namebuf[NAME_LEN];
#ifdef ENABLE_EXPERIMENTAL
        /* compatibility support only for filters */
        if (verbose >= TC_DEBUG) {
            tc_log_info(EXE, "using old module system");
        }
#endif
        /* ok, fallback to old module system */
        strlcpy(namebuf, filename, NAME_LEN);
        filter[0].name = namebuf;
    
        ret = load_plugin(modpath, 0, verbose);
        if (ret != 0) {
            tc_log_error(__FILE__, "unable to load filter `%s' (path=%s)",
                                   filter[0].name, modpath);
            status = STATUS_NO_MODULE;
        } else {
            strlcpy(options, "help", OPTS_SIZE);
            ptr.tag = TC_FILTER_INIT;
            if ((ret = filter[0].entry(&ptr, options)) != 0) {
                status = STATUS_MODULE_ERROR;
            } else {
                memset(options, 0, OPTS_SIZE);
                ptr.tag = TC_FILTER_GET_CONFIG;
                ret = filter[0].entry(&ptr, options);

                if (ret == 0) {
                    if (verbose >= TC_INFO) {
                        fputs("START\n", stdout);
                        fputs(options, stdout);
                        fputs("END\n", stdout);
                    }
                    status = STATUS_OK;
                }
            }
        }
   }

#ifdef ENABLE_EXPERIMENTAL
   ret = tc_del_module_factory(factory);
#endif
   tcv_free(tcv_handle);
   return status;
}
Example #4
0
int main(int argc, char *argv[])
{
    int ch;
    const char *filename = NULL;
    const char *modpath = tc_module_default_path();
    const char *regpath = tc_module_registry_default_path();
    const char *modtype = "filter";
    const char *modarg = ""; /* nothing */
    const char *modcfg = ""; /* nothing */
    const char *socketfile = NULL;
    const char *fmtname = NULL;
    int print_mod = 0;
    int connect_socket = 0;
    int ret = 0;
    int status = STATUS_NO_MODULE;

    /* needed by filter modules */
    TCVHandle tcv_handle = tcv_init();
    TCRegistry registry = NULL;
    TCFactory factory = NULL;
    TCModule module = NULL;

    ac_init(AC_ALL);
    tc_ext_init();

    if (argc == 1) {
        usage();
        return STATUS_BAD_PARAM;
    }

    libtc_init(&argc, &argv);

    while (1) {
        ch = getopt(argc, argv, "C:F:d:i:?vhpm:M:r:s:t:");
        if (ch == -1) {
            break;
        }

        switch (ch) {
          case 'd':
            if (optarg[0] == '-') {
                usage();
                return STATUS_BAD_PARAM;
            }
            verbose = atoi(optarg);
            break;
          case 'i':
            if (optarg[0] == '-') {
                usage();
                return STATUS_BAD_PARAM;
            }
            filename = optarg;
            break;
          case 'C':
            modcfg = optarg;
            break;
          case 'F':
            fmtname = optarg;
            break;
          case 'm':
            modpath = optarg;
            break;
          case 'M':
            modarg = optarg;
            break;
          case 'r':
            regpath = optarg;
            break;
          case 't':
            if (!optarg) {
                usage();
                return STATUS_BAD_PARAM;
            }
            if (!strcmp(optarg, "filter")
             || !strcmp(optarg, "encode")
             || !strcmp(optarg, "multiplex")) {
                modtype = optarg;
            } else {
                modtype = NULL;
            }
            break;
          case 's':
            if (optarg[0] == '-') {
                usage();
                return STATUS_BAD_PARAM;
            }
            connect_socket = 1;
            socketfile = optarg;
            break;
          case 'p':
            print_mod = 1;
            break;
          case 'v':
            version();
            return STATUS_OK;
          case '?': /* fallthrough */
          case 'h': /* fallthrough */
          default:
            usage();
            return STATUS_OK;
        }
    }

    if (print_mod) {
        printf("%s\n", modpath);
        return STATUS_OK;
    }

    if (connect_socket) {
        do_connect_socket(socketfile);
        return STATUS_OK;
    }

    if (!filename && !fmtname) {
        usage();
        return STATUS_BAD_PARAM;
    }

    if (!modtype || !strcmp(modtype, "import")) {
        tc_log_error(EXE, "Unknown module type (not in filter, encode, multiplex)");
        return STATUS_BAD_PARAM;
    }

    if (strlen(modcfg) > 0 && strlen(modarg) > 0) {
        tc_log_error(EXE, "Cannot configure and inspect module on the same time");
        return STATUS_BAD_PARAM;
    }

    /* 
     * we can't distinguish from OMS and NMS modules at glance, so try
     * first using new module system
     */
    factory = tc_new_module_factory(modpath, TC_MAX(verbose - 4, 0)); /* FIXME */
    registry = tc_new_module_registry(factory, regpath, TC_MAX(verbose - 4, 0)); /* FIXME */

    if (fmtname) {
        TCCodecID codec = tc_codec_from_string(fmtname);
        TCFormatID format = tc_format_from_string(fmtname);
        if (codec == TC_CODEC_ERROR && format == TC_FORMAT_ERROR) {
            tc_log_error(EXE, "unrecognized format `%s'", fmtname);
        } else {
            const char *modnames = tc_get_module_name_for_format(registry,
                                                                 modtype,
                                                                 fmtname);
            if (modnames) {
                puts(modnames);
            }
        }
    } else {
        module = tc_new_module(factory, modtype, filename, TC_NONE);

        if (module != NULL) {
            status = query_new_module(module, modcfg, modarg);
            tc_del_module(factory, module);
        } else if (!strcmp(modtype, "filter")) {
            status = query_old_module(filename, modpath);
        }
    }

    ret = tc_del_module_registry(registry);
    ret = tc_del_module_factory(factory);
    tcv_free(tcv_handle);
    return status;
}