Browse Source

Simplify the design of the module system

Do not have the module represent themselves with the
gfsec_scheme_module_t structure. Now a module must just take care
of providing the appropriate functions (currently only "get_file")
to perform the task.

The initialization function in scheme-module will assemble the
structures and call any initialization function required.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
a63d0fcde4
  1. 13
      src/scheme-file.c
  2. 10
      src/scheme-file.h
  3. 13
      src/scheme-gio.c
  4. 10
      src/scheme-gio.h
  5. 15
      src/scheme-libmtp.c
  6. 10
      src/scheme-libmtp.h
  7. 32
      src/scheme-module.c
  8. 11
      src/scheme-module.h

13
src/scheme-file.c

@ -21,9 +21,10 @@
#endif
#include "scheme-file.h"
#include "scheme-module.h"
#include "util.h"
static int
int
gfsec_scheme_file_get_file(gfsec_scheme_t scheme,
const char *authority,
const char *path,
@ -41,13 +42,3 @@ gfsec_scheme_file_get_file(gfsec_scheme_t scheme,
else
return GFSEC_SCHEME_STATUS_ERROR;
}
gfsec_scheme_module_t
gfsec_scheme_file_init(void)
{
gfsec_scheme_module_t module;
module.get_file = gfsec_scheme_file_get_file;
return module;
}

10
src/scheme-file.h

@ -19,14 +19,18 @@
#ifndef ICP20160821_SCHEME_FILE_H
#define ICP20160821_SCHEME_FILE_H
#include "scheme-module.h"
#include "schemes.h"
#ifdef __cpluscplus
extern "C" {
#endif
gfsec_scheme_module_t
gfsec_scheme_file_init(void);
int
gfsec_scheme_file_get_file(gfsec_scheme_t,
const char *,
const char *,
unsigned char **,
size_t *);
#ifdef __cplusplus
}

13
src/scheme-gio.c

@ -21,6 +21,7 @@
#endif
#include "scheme-gio.h"
#include "scheme-module.h"
#ifdef HAVE_GIO
@ -180,7 +181,7 @@ get_file_contents(GVolume *volume,
return rc;
}
static int
int
gfsec_scheme_gio_get_file(gfsec_scheme_t scheme,
const char *authority,
const char *path,
@ -212,14 +213,4 @@ gfsec_scheme_gio_get_file(gfsec_scheme_t scheme,
return rc;
}
gfsec_scheme_module_t
gfsec_scheme_gio_init(void)
{
gfsec_scheme_module_t module;
module.get_file = gfsec_scheme_gio_get_file;
return module;
}
#endif /* HAVE_GIO */

10
src/scheme-gio.h

@ -19,14 +19,18 @@
#ifndef ICP20160207_SCHEME_GIO_H
#define ICP20160207_SCHEME_GIO_H
#include "scheme-module.h"
#include "schemes.h"
#ifdef __cpluscplus
extern "C" {
#endif
gfsec_scheme_module_t
gfsec_scheme_gio_init(void);
int
gfsec_scheme_gio_get_file(gfsec_scheme_t,
const char *,
const char *,
unsigned char **,
size_t *);
#ifdef __cplusplus
}

15
src/scheme-libmtp.c

@ -21,6 +21,7 @@
#endif
#include "scheme-libmtp.h"
#include "scheme-module.h"
#ifdef HAVE_LIBMTP
@ -167,7 +168,7 @@ getfile_cb(void *params,
return LIBMTP_HANDLER_RETURN_OK;
}
static int
int
gfsec_scheme_libmtp_get_file(gfsec_scheme_t scheme,
const char *authority,
const char *path,
@ -207,16 +208,4 @@ gfsec_scheme_libmtp_get_file(gfsec_scheme_t scheme,
return rc;
}
gfsec_scheme_module_t
gfsec_scheme_libmtp_init(void)
{
gfsec_scheme_module_t module;
LIBMTP_Init();
module.get_file = gfsec_scheme_libmtp_get_file;
return module;
}
#endif /* HAVE_LIBMTP */

10
src/scheme-libmtp.h

@ -19,14 +19,18 @@
#ifndef ICP20160207_SCHEME_LIBMTP_H
#define ICP20160207_SCHEME_LIBMTP_H
#include "scheme-module.h"
#include "schemes.h"
#ifdef __cpluscplus
extern "C" {
#endif
gfsec_scheme_module_t
gfsec_scheme_libmtp_init(void);
int
gfsec_scheme_libmtp_get_file(gfsec_scheme_t scheme,
const char *,
const char *,
unsigned char **,
size_t *);
#ifdef __cplusplus
}

32
src/scheme-module.c

@ -25,7 +25,21 @@
#include "scheme-libmtp.h"
#include "scheme-gio.h"
static gfsec_scheme_module_t *modules;
#ifdef HAVE_LIBMTP
#include <libmtp.h>
#endif
typedef int (*fn_get_file)(gfsec_scheme_t,
const char *,
const char *,
unsigned char **,
size_t *);
typedef struct module {
fn_get_file get_file;
} module_t;
static module_t *modules;
/**
* Initializes the module system.
@ -35,19 +49,21 @@ static gfsec_scheme_module_t *modules;
void
gfsec_scheme_module_init(void)
{
static gfsec_scheme_module_t mods[4];
gfsec_scheme_module_t dummy = { NULL };
static module_t mods[4];
int n = 0;
mods[n++] = gfsec_scheme_file_init();
mods[n++].get_file = gfsec_scheme_file_get_file;
#ifdef HAVE_LIBMTP
mods[n++] = gfsec_scheme_libmtp_init();
LIBMTP_Init();
mods[n++].get_file = gfsec_scheme_libmtp_get_file;
#endif
#ifdef HAVE_GIO
mods[n++] = gfsec_scheme_gio_init();
mods[n++].get_file = gfsec_scheme_gio_get_file;
#endif
mods[n++] = dummy;
mods[n++].get_file = NULL;
modules = mods;
}
@ -79,7 +95,7 @@ gfsec_scheme_module_get_file(gfsec_scheme_t scheme,
unsigned char **buffer,
size_t *len)
{
gfsec_scheme_module_t *mod = modules;
module_t *mod = modules;
int rc;
while ( mod->get_file != NULL ) {

11
src/scheme-module.h

@ -29,17 +29,6 @@ typedef enum gfsec_scheme_status {
GFSEC_SCHEME_STATUS_ERROR = -2
} gfsec_scheme_status_t;
typedef int (*gfsec_scheme_get_file)(gfsec_scheme_t,
const char *,
const char *,
unsigned char **,
size_t *);
typedef struct gfsec_scheme_module {
gfsec_scheme_get_file get_file;
} gfsec_scheme_module_t;
#ifdef __cplusplus
extern "C" {
#endif

Loading…
Cancel
Save