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-08-28 20:20:55 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2001-01-07 16:14:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.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
|
|
|
|
2001-01-17 01:59:57 +00:00
|
|
|
#define REGISTRY_DIR_PERMS (S_ISGID | \
|
|
|
|
S_IRUSR | S_IWUSR | S_IXUSR | \
|
|
|
|
S_IRGRP | S_IXGRP | \
|
|
|
|
S_IROTH | S_IXOTH)
|
|
|
|
#define REGISTRY_TMPFILE_PERMS (S_IRUSR | S_IWUSR)
|
|
|
|
#define REGISTRY_FILE_PERMS (S_IRUSR | S_IWUSR | \
|
|
|
|
S_IRGRP | S_IWGRP | \
|
|
|
|
S_IROTH | S_IWOTH)
|
|
|
|
|
|
|
|
|
2000-12-17 04:54:57 +00:00
|
|
|
extern gboolean _gst_plugin_spew;
|
2001-01-07 15:20:49 +00:00
|
|
|
extern gboolean _gst_warn_old_registry;
|
2000-12-17 04:54:57 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-01-17 01:59:57 +00:00
|
|
|
static void set_filemode(const char * filename, mode_t mode) {
|
|
|
|
if(chmod(filename, mode)) {
|
|
|
|
g_print("Cannot set file permissions on `%s' to %o", filename, mode);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_filemode(const char * filename, mode_t * mode) {
|
|
|
|
struct stat statbuf;
|
|
|
|
if(stat(filename, &statbuf)) return 0;
|
|
|
|
*mode = statbuf.st_mode & ~ S_IFMT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_file(const char * nameold,
|
|
|
|
const char * namenew,
|
|
|
|
mode_t * newmode) {
|
2001-01-07 04:51:31 +00:00
|
|
|
if (!is_file(nameold)) {
|
|
|
|
g_print("Temporary `%s' is not a file", nameold);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
if (is_dir(namenew)) {
|
2001-01-17 01:59:57 +00:00
|
|
|
g_print("Destination path `%s' for registry file is a directory\n", namenew);
|
2001-01-07 04:51:31 +00:00
|
|
|
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();
|
|
|
|
}
|
2001-01-17 01:59:57 +00:00
|
|
|
// set mode again, to make this public
|
|
|
|
set_filemode(namenew, *newmode);
|
2001-01-07 04:51:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-17 01:59:57 +00:00
|
|
|
static void make_dir(const char * dirname) {
|
|
|
|
mode_t mode = REGISTRY_DIR_PERMS;
|
|
|
|
if(mkdir(dirname, mode)) {
|
|
|
|
g_print("Cannot create GStreamer registry directory `%s'", dirname);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(chmod(dirname, mode)) {
|
|
|
|
g_print("Cannot set permissions on GStreamer registry directory `%s' to %o", dirname, mode);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2001-01-07 04:51:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-07 16:14:35 +00:00
|
|
|
static void check_dir(const char * dirname) {
|
2001-01-07 04:51:31 +00:00
|
|
|
if (!is_dir(dirname)) {
|
2001-01-17 01:59:57 +00:00
|
|
|
make_dir(dirname);
|
2001-01-07 04:51:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-17 01:59:57 +00:00
|
|
|
static void save_registry(const char *destfile,
|
|
|
|
xmlDocPtr * doc) {
|
|
|
|
mode_t tmpmode = REGISTRY_TMPFILE_PERMS;
|
2001-01-07 16:14:35 +00:00
|
|
|
#if 0
|
|
|
|
FILE *fp;
|
2001-01-17 01:59:57 +00:00
|
|
|
int fd;
|
2001-01-07 16:14:35 +00:00
|
|
|
|
2001-01-17 01:59:57 +00:00
|
|
|
fd = open(destfile, O_CREAT | O_TRUNC | O_WRONLY, tmpmode);
|
|
|
|
if (fd == -1) {
|
2001-01-07 16:14:35 +00:00
|
|
|
g_print("Cannot open `%s' to save new registry to.", destfile);
|
|
|
|
error_perm();
|
|
|
|
}
|
2001-01-17 01:59:57 +00:00
|
|
|
fp = fdopen (fd, "wb");
|
|
|
|
if (!fp) {
|
|
|
|
g_print("Cannot fopen `%s' to save new registry to.", destfile);
|
|
|
|
error_perm();
|
|
|
|
}
|
|
|
|
// set mode to make this private
|
|
|
|
set_filemode(destfile, tmpmode);
|
2001-01-07 16:14:35 +00:00
|
|
|
|
|
|
|
// FIXME: no way to check success of xmlDocDump, which is why
|
|
|
|
// this piece of code is ifdefed out.
|
2001-01-17 01:59:57 +00:00
|
|
|
// The version of libxml currently (Jan 2001) in their CVS tree fixes
|
|
|
|
// this problem.
|
2001-01-07 16:48:32 +00:00
|
|
|
xmlDocDump(fp, *doc);
|
2001-01-07 16:14:35 +00:00
|
|
|
|
|
|
|
if (!fclose(fp)) {
|
|
|
|
g_print("Cannot close `%s' having saved new registry.", destfile);
|
|
|
|
error_perm();
|
|
|
|
}
|
2001-01-17 01:59:57 +00:00
|
|
|
|
2001-01-07 16:14:35 +00:00
|
|
|
#else
|
2001-01-07 16:48:32 +00:00
|
|
|
if (xmlSaveFile(destfile, *doc) <= 0) {
|
2001-01-07 16:14:35 +00:00
|
|
|
g_print("Cannot save new registry to `%s'", destfile);
|
|
|
|
error_perm();
|
|
|
|
}
|
2001-01-17 01:59:57 +00:00
|
|
|
set_filemode(destfile, tmpmode);
|
2001-01-07 16:14:35 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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-17 01:59:57 +00:00
|
|
|
// Mode of the file we're saving the repository to;
|
|
|
|
mode_t newmode;
|
|
|
|
|
|
|
|
// Get mode of old repository, or a default.
|
|
|
|
if (!get_filemode(GLOBAL_REGISTRY_FILE, &newmode)) {
|
|
|
|
mode_t theumask = umask(0);
|
|
|
|
umask(theumask);
|
|
|
|
newmode = REGISTRY_FILE_PERMS & ~ theumask;
|
|
|
|
}
|
|
|
|
|
2001-01-09 20:45:20 +00:00
|
|
|
// remove the old registry file first
|
2001-01-17 01:59:57 +00:00
|
|
|
// If this fails, we simply ignore it since we'll overwrite it later
|
|
|
|
// anyway.
|
2001-01-09 20:45:20 +00:00
|
|
|
unlink(GLOBAL_REGISTRY_FILE);
|
|
|
|
|
2001-01-07 07:01:37 +00:00
|
|
|
// Init gst
|
|
|
|
_gst_plugin_spew = TRUE;
|
2001-01-07 15:20:49 +00:00
|
|
|
_gst_warn_old_registry = FALSE;
|
2001-01-09 04:39:35 +00:00
|
|
|
gst_info_enable_category(GST_CAT_PLUGIN_LOADING);
|
2001-01-09 20:45:20 +00:00
|
|
|
gst_init(&argc,&argv);
|
2001-01-07 07:01:37 +00:00
|
|
|
|
|
|
|
// 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");
|
2001-01-18 11:16:53 +00:00
|
|
|
doc->xmlRootNode = xmlNewDocNode(doc, NULL, "GST-PluginRegistry", NULL);
|
|
|
|
gst_plugin_save_thyself(doc->xmlRootNode);
|
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 16:48:32 +00:00
|
|
|
save_registry(GLOBAL_REGISTRY_FILE_TMP, &doc);
|
2000-08-28 20:20:55 +00:00
|
|
|
|
2001-01-07 04:51:31 +00:00
|
|
|
// Make the tmp file live.
|
2001-01-17 01:59:57 +00:00
|
|
|
move_file(GLOBAL_REGISTRY_FILE_TMP, GLOBAL_REGISTRY_FILE, &newmode);
|
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
|
|
|
}
|
|
|
|
|