#include <fcntl.h>
#include <glite/jp/types.h>
+#include <glite/jp/known_attr.h>
#include "file_plugin.h"
#include "builtin_plugins.h"
#include "backend.h"
+#define ALLOC_CHUNK 3
+
+
typedef struct _sb_handle {
void *bhandle;
TAR *t;
static int sandbox_close(void *,void *);
static int sandbox_attr(void *,void *,const char *,glite_jp_attrval_t **);
+
+int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
+{
+ data->fpctx = ctx;
+ global_data.ctx = ctx;
+
+ data->uris = calloc(2,sizeof *data->uris);
+ data->uris[0] = strdup(GLITE_JP_FILETYPE_ISB);
+
+ data->classes = calloc(2,sizeof *data->classes);
+ data->classes[0] = strdup("sandbox");
+
+ data->ops.open = sandbox_open;
+ data->ops.close = sandbox_close;
+ data->ops.attr = sandbox_attr;
+
+ printf("sandbox_plugin: URI: \"%s\"\n",GLITE_JP_FILETYPE_ISB);
+
+ return 0;
+}
+
+
+/**
+* Wrappers for tar_open
+*/
static int my_open(const char *pathname, int flags, ...) {
// Do not open file, it is opened in ftp_backend
// returned fd does not matter, read/write/close does ftp_backend
return 0;
}
-// wrapper around glite_jppsbe_pread
-static ssize_t my_read(int fd, void *buf, size_t count)
-{
+static ssize_t my_read(int fd, void *buf, size_t count) {
+ // wrapper around glite_jppsbe_pread
size_t r;
-
if (glite_jppsbe_pread(global_data.ctx,global_data.bhandle,buf,count,global_data.offset,&r)) {
errno = global_data.ctx->error->code;
return -1;
return r;
}
-
static ssize_t my_write(int fd, const void *buf, size_t count) {
- // XXX: wrapper around glite_jppsbe_pwrite
+ // wrapper around glite_jppsbe_pwrite
+ // just stub, not needed here&now
}
-int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
-{
- data->fpctx = ctx;
- global_data.ctx = ctx;
-
- data->uris = calloc(2,sizeof *data->uris);
- data->uris[0] = strdup(GLITE_JP_FILETYPE_ISB);
-
- data->classes = calloc(2,sizeof *data->classes);
- data->classes[0] = strdup("sandbox");
-
- data->ops.open = sandbox_open;
- data->ops.close = sandbox_close;
- data->ops.attr = sandbox_attr;
-
- printf("sandbox_plugin: URI: \"%s\"\n",GLITE_JP_FILETYPE_ISB);
- return 0;
-}
static int sandbox_open(void *fpctx,void *bhandle,const char *uri,void **handle)
{
if (tar_open(&h->t, NULL /* not needed, opened in ftp_backend */, h->tt, O_RDONLY, 0, TAR_GNU) == -1)
printf("tar_open()\n"); //XXX: use glite_jp_stack_error
-// tar_fdopen(&t, ((fhandle)handle)->fd, char *pathname, tartype_t *type, int oflags, int mode, int options);
-
-
*handle = h;
return 0;
}
+
static int sandbox_close(void *fpctx,void *handle)
{
int i;
glite_jp_error_t err;
glite_jp_context_t ctx = fpctx;
glite_jp_attrval_t *out = NULL;
- int i,nout = 0;
+ int i,nout = 0, count = 0;
sb_handle *h = handle;
+
+ printf("sandbox_attr() called\n");
+
memset(&err,0,sizeof err);
err.source = __FUNCTION__;
glite_jp_clear_error(ctx);
+ *attrval = NULL;
while ((i = th_read(h->t)) == 0)
{
printf("-- %s\n", th_get_pathname(h->t));
+ if ( !(count % ALLOC_CHUNK) ) {
+ *attrval = realloc(*attrval, (count + ALLOC_CHUNK + 1) * sizeof(**attrval) );
+ memset( (*attrval) + count, 0, (ALLOC_CHUNK + 1) * sizeof(**attrval));
+ }
+ (*attrval)[count].name = strdup(GLITE_JP_ATTR_ISB_FILENAME);
+ (*attrval)[count].value = strdup(th_get_pathname(h->t));
+ (*attrval)[count].origin = GLITE_JP_ATTR_ORIG_FILE;
+ (*attrval)[count].timestamp = th_get_mtime(h->t);
+
+ count++;
+
if (TH_ISREG(h->t) && tar_skip_regfile(h->t) != 0)
{
err.code = EIO;
}
}
- printf("sandbox_attr() called\n");
+ return glite_jp_stack_error(ctx,&err);
}