Example #1
0
static int l_sipmemcache_get(lua_State *L)
{
  struct sipmemcache *o;
  const char *key;
  size_t keylen;
  void *blah;
  size_t retlen;

  o = luaL_checkudata(L, 1, "siplua.memcache");
  key = luaL_checklstring(L, 2, &keylen);
  if (o->finalized || !o->mc)
    {
      lua_pushnil(L);
    }
  else
    {
      blah = mc_aget2(o->mc, (char *)key, keylen, &retlen);
      if (retlen && blah)
	{
	  lua_pushlstring(L, blah, retlen);
	  free(blah);
	}
      else
	lua_pushnil(L);
    }
  return 1;
}
Example #2
0
static int memcachefs_open(const char *path, struct fuse_file_info *fi)
{
    handle_t *handle;
    char *key;
    size_t keylen;
    void *val;
    size_t vallen;

    if(opt.verbose){
        fprintf(stderr, "%s(\"%s\")\n", __func__, path);
    }

    handle = handle_get(pool);
    if(!handle){
        return -EMFILE;
    }
    fi->fh = handle->index;

    key = (char *)path + 1;
    keylen = strlen(key);
    val = mc_aget2(handle->mc, key, keylen, &vallen);
    if(!val){
        return -EIO;
    }
    memcpy(handle->buf, val, vallen);
    handle->buf_len = vallen;

    return 0;
}
Example #3
0
static int memcachefs_getattr(const char *path, struct stat *stbuf)
{
    handle_t *handle;
    char *key;
    size_t keylen;
    void *val;
    size_t vallen;

    if(opt.verbose){
        fprintf(stderr, "%s(\"%s\")\n", __func__, path);
    }
    memset(stbuf, 0, sizeof(struct stat));

    if(!strcmp(path, "/")){
        stbuf->st_ino = 1;
        stbuf->st_mode = S_IFDIR | 0755;
        // stbuf->st_mode = S_IFDIR;
        stbuf->st_uid = fuse_get_context()->uid;
        stbuf->st_gid = fuse_get_context()->gid;
        stbuf->st_nlink = 1;
        stbuf->st_atime = 0;
        stbuf->st_mtime = 0;
        stbuf->st_size = 0;
        return 0;
	}

    handle = handle_get(pool);
    if(!handle){
        return -EMFILE;
    }

    key = (char *)path + 1;
    keylen = strlen(key);
    val = (char*)mc_aget2(handle->mc, key, keylen, &vallen);
    handle_release(pool, handle->index);
    if(!val){
        return -ENOENT;
    }

	// get file attrs
	char *attrs = get_attrvalue(key);
	if (attrs != NULL) {
	    stbuf->st_mode = S_IFDIR | 0666;
	} else {
    	stbuf->st_mode = S_IFREG | 0666;
	}
	// printf("SAIDA: %s\n", attrs);

    // stbuf->st_mode = S_IFREG | 0666;
    // stbuf->st_mode = S_IFDIR | 0666;
    stbuf->st_uid = fuse_get_context()->uid;
    stbuf->st_gid = fuse_get_context()->gid;
    stbuf->st_nlink = 1;
    stbuf->st_size = vallen;
    free(val);
	free(attrs);
    return 0;
}
Example #4
0
/* read attrs value */
char* get_attrvalue(char *key) {
	size_t attr_len;
    handle_t *handle = handle_get(pool);
	char *attr_key = get_attrkey(key);

	printf("SAIDA: %s\n", attr_key);

    char *attr_value = (char*)mc_aget2(
		handle->mc, 
		attr_key, 
		strlen(attr_key), 
		&attr_len
	);
    handle_release(pool, handle->index);
	free(attr_key);

	printf("SAIDA: %s\n", attr_value);
	
	return attr_value;
}
Example #5
0
static int memcachefs_rename(const char *from, const char *to)
{
    int ret;
    handle_t *handle;
    char *key;
    size_t keylen;
    void *val;
    size_t vallen;

    if(opt.verbose){
        fprintf(stderr, "%s(%s -> %s)\n", __func__, from, to);
    }
    handle = handle_get(pool);

    key = (char *)from + 1;
    keylen = strlen(key);
    val = (char*)mc_aget2(handle->mc, key, keylen, &vallen);
    if(!val){
        handle_release(pool, handle->index);
        return -ENOENT;
    }

    key = (char *)to + 1;
    keylen = strlen(key);
    ret = mc_set(handle->mc, key, keylen, val, vallen, 0, 0);
    if(ret){
        handle_release(pool, handle->index);
        return -EIO;
    }

    key = (char *)from + 1;
    keylen = strlen(key);
    ret = mc_delete(handle->mc, key, keylen, 0);
    if(ret){
        handle_release(pool, handle->index);
        return -EIO;
    }

    free(val);
    return 0;
}