2001-01-07 04:51:31 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstreamer-register.c: Plugin subsystem for loading elements, types, and libs
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2000-12-31 22:15:28 +00:00
|
|
|
#include <stdlib.h>
|
2000-08-28 20:20:55 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2001-01-07 04:51:31 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2001-01-07 05:30:07 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#define GLOBAL_REGISTRY_DIR GST_CONFIG_DIR
|
|
|
|
#define GLOBAL_REGISTRY_FILE GLOBAL_REGISTRY_DIR"/reg.xml"
|
|
|
|
#define GLOBAL_REGISTRY_FILE_TMP GLOBAL_REGISTRY_DIR"/.reg.xml.tmp"
|
2001-01-07 04:51:31 +00:00
|
|
|
|
2000-12-17 04:54:57 +00:00
|
|
|
extern gboolean _gst_plugin_spew;
|
|
|
|
|
2001-01-07 04:51:31 +00:00
|
|
|
static void error_perm() {
|
|
|
|
g_print("\n(%s)\n"
|
|
|
|
"Do you have the appropriate permissions?\n"
|
|
|
|
"You may need to be root to run this command.\n\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usage(const char *progname) {
|
|
|
|
g_print("usage: %s\n", progname);
|
|
|
|
g_print("Builds the plugin registry for gstreamer.\n");
|
|
|
|
g_print("This command will usually require superuser privileges.\n\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_file(const char * filename) {
|
|
|
|
struct stat statbuf;
|
|
|
|
if(stat(filename, &statbuf)) return 0;
|
|
|
|
return S_ISREG(statbuf.st_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_dir(const char * filename) {
|
|
|
|
struct stat statbuf;
|
|
|
|
if(stat(filename, &statbuf)) return 0;
|
|
|
|
return S_ISDIR(statbuf.st_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_file(const char * nameold, const char * namenew) {
|
|
|
|
if (!is_file(nameold)) {
|
|
|
|
g_print("Temporary `%s' is not a file", nameold);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
if (is_dir(namenew)) {
|
|
|
|
g_print("Destination path `%s' is a directory\n", namenew);
|
|
|
|
g_print("Please remove, or reconfigure GStreamer\n\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (rename(nameold, namenew)) {
|
|
|
|
g_print("Cannot move `%s' to `%s'", nameold, namenew);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int make_dir(const char * dirname) {
|
|
|
|
mode_t mode = 0766;
|
|
|
|
return !mkdir(dirname, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_dir(const char * dirname) {
|
|
|
|
if (!is_dir(dirname)) {
|
|
|
|
if (!make_dir(dirname)) {
|
|
|
|
g_print("Cannot create GStreamer registry directory `%s'",
|
|
|
|
dirname);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-28 20:20:55 +00:00
|
|
|
int main(int argc,char *argv[])
|
|
|
|
{
|
2001-01-07 04:51:31 +00:00
|
|
|
xmlDocPtr doc;
|
|
|
|
|
2001-01-07 07:01:37 +00:00
|
|
|
// Init gst
|
|
|
|
_gst_plugin_spew = TRUE;
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
|
|
|
// Check args
|
2001-01-07 04:51:31 +00:00
|
|
|
if (argc != 1) usage(argv[0]);
|
|
|
|
|
|
|
|
// Check that directory for config exists
|
2001-01-07 05:30:07 +00:00
|
|
|
check_dir(GLOBAL_REGISTRY_DIR);
|
2001-01-07 04:51:31 +00:00
|
|
|
|
|
|
|
// Read the plugins
|
|
|
|
doc = xmlNewDoc("1.0");
|
|
|
|
doc->root = xmlNewDocNode(doc, NULL, "GST-PluginRegistry", NULL);
|
|
|
|
gst_plugin_save_thyself(doc->root);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2001-01-07 04:51:31 +00:00
|
|
|
// Save the registry to a tmp file.
|
2001-01-07 05:54:10 +00:00
|
|
|
if (xmlSaveFile(GLOBAL_REGISTRY_FILE_TMP, doc) <= 0) {
|
2001-01-07 04:51:31 +00:00
|
|
|
g_print("Cannot save new registry `%s'",
|
|
|
|
GLOBAL_REGISTRY_FILE_TMP);
|
|
|
|
error_perm();
|
|
|
|
}
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2001-01-07 04:51:31 +00:00
|
|
|
// Make the tmp file live.
|
|
|
|
move_file(GLOBAL_REGISTRY_FILE_TMP, GLOBAL_REGISTRY_FILE);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2001-01-07 04:51:31 +00:00
|
|
|
return(0);
|
2000-08-28 20:20:55 +00:00
|
|
|
}
|
|
|
|
|