示例#1
0
文件: readdir.c 项目: janBest/seafile
static int readdir_user(SeafileSession *seaf, const char *user,
                        void *buf, fuse_fill_dir_t filler, off_t offset,
                        struct fuse_file_info *info)
{
    SearpcClient *client;
    CcnetEmailUser *emailuser;
    GList *list = NULL, *p;
    GString *name;

    client = ccnet_create_pooled_rpc_client (seaf->client_pool,
                                             NULL,
                                             "ccnet-threaded-rpcserver");
    if (!client) {
        seaf_warning ("Failed to alloc rpc client.\n");
        return -ENOMEM;
    }

    emailuser = get_user_from_ccnet (client, user);
    if (!emailuser) {
        ccnet_rpc_client_free (client);
        return -ENOENT;
    }
    g_object_unref (emailuser);
    ccnet_rpc_client_free (client);

    list = seaf_repo_manager_get_repos_by_owner (seaf->repo_mgr, user);
    if (!list)
        return 0;

    for (p = list; p; p = p->next) {
        SeafRepo *repo = (SeafRepo *)p->data;

        /* Don't list virtual repos. */
        if (seaf_repo_manager_is_virtual_repo(seaf->repo_mgr, repo->id)) {
            seaf_repo_unref (repo);
            continue;
        }
		
		//skip the encrypted repo
		if(repo -> encrypted)
			continue;
		
        char *clean_repo_name = replace_slash (repo->name);

        name = g_string_new ("");
        g_string_printf (name, "%s_%s", repo->id, clean_repo_name);
        filler(buf, name->str, NULL, 0);
        g_string_free (name, TRUE);
        g_free (clean_repo_name);

        seaf_repo_unref (repo);
    }

    g_list_free (list);

    return 0;
}
void win_start_event_channel(char *evt_log, char future, char *query)
{
	wchar_t		*wchannel = NULL;
	wchar_t		*wquery = NULL;
	os_channel  	*channel = NULL;
	DWORD		flags = EvtSubscribeToFutureEvents;
	EVT_HANDLE 	bookmark = NULL;
	EVT_HANDLE	result = NULL;

	if ((channel = calloc(1, sizeof(os_channel))) == NULL)
	{
		log2file(
			"%s: ERROR: Could not calloc() memory for channel to start reading (%s) which returned [(%d)-(%s)]",
			ARGV0,
			evt_log,
			errno,
			strerror(errno)
		);

		goto error;
	}

	channel->evt_log = evt_log;

	/* Convert evt_log to windows string */
	if ((wchannel = convert_unix_string(channel->evt_log)) == NULL)
	{
		log2file(
			"%s: ERROR: Could not convert_unix_string() evt_log for (%s) which returned [(%d)-(%s)]",
			ARGV0,
			channel->evt_log,
			errno,
			strerror(errno)
		);

		goto error;
	}

	/* Convert query to windows string */
	if (query)
	{
		if ((wquery = convert_unix_string(query)) == NULL)
		{
			log2file(
				"%s: ERROR: Could not convert_unix_string() query for (%s) which returned [(%d)-(%s)]",
				ARGV0,
				channel->evt_log,
				errno,
				strerror(errno)
			);

			goto error;
		}
	}

	channel->bookmark_enabled = !future;

	if (channel->bookmark_enabled)
	{
		/* Create bookmark file name */
		snprintf(
			channel->bookmark_filename,
			sizeof(channel->bookmark_filename),
			"%s/%s",
			BOOKMARKS_DIR,
			channel->evt_log
		);

		replace_slash(channel->bookmark_filename);

		/* Try to read existing bookmark */
		if ((bookmark = read_bookmark(channel)) != NULL)
		{
			flags = EvtSubscribeStartAfterBookmark;
		}
	}

	result = EvtSubscribe(
		NULL,
		NULL,
		wchannel,
		wquery,
		bookmark,
		channel,
		(EVT_SUBSCRIBE_CALLBACK)event_channel_callback,
		flags
	);

	if (result == NULL && flags == EvtSubscribeStartAfterBookmark)
	{
		result = EvtSubscribe(
			NULL,
			NULL,
			wchannel,
			wquery,
			NULL,
			channel,
			(EVT_SUBSCRIBE_CALLBACK)event_channel_callback,
			EvtSubscribeToFutureEvents
		);
	}

	if (result == NULL)
	{
		log2file(
			"%s: ERROR: Could not EvtSubscribe() for (%s) which returned (%lu)",
			ARGV0,
			channel->evt_log,
			GetLastError()
		);

		goto error;
	}

	free(wchannel);
	free(wquery);

	return;

error:
	free(wchannel);
	free(wquery);
	free(channel);

	return;
}
示例#3
0
文件: mms_mmbox.c 项目: frese/mbuni
List *mms_mmbox_search(char *mmbox_root, char *user,
		       List *state, List *flag_cmds, int start, int limit, 
		       List *msgrefs)
{
     int tmpfd = -1;
     FILE *fp = NULL;
     char linbuf[1024];

     Octstr *home = user_mmbox_dir(mmbox_root,user);
     List *flags = NULL;
     List *dflist = NULL;

     int ifd = -1;
     int ct;
     
     ifd = open_mmbox_index(octstr_get_cstr(home),1);
     
     if (ifd < 0) 
	  goto done;

     if ((tmpfd = dup(ifd)) < 0 || 
	 (fp = fdopen(tmpfd, "r")) == NULL) {
	  error(0, "mmbox.search_index: %s Failed to dup descriptor for index "
		"file, fp = %p: error = %s\n", octstr_get_cstr(home), 
		fp, strerror(errno));	  
	  goto done;
     }

     flags = make_mm_flags(NULL, flag_cmds);
     
     ct = 1;
     dflist = gwlist_create();
     while (fgets(linbuf, sizeof linbuf, fp) != NULL) {
	  char idx[128], xstate[32];
	  List *xflags = NULL;
	  int i, size;

	  int match = (!state && (!msgrefs || gwlist_len(msgrefs) == 0) && (!xflags || gwlist_len(xflags) == 0));
	  
	  sscanf(linbuf, "%s %s %d%n", idx, xstate, &size, &i);
	  
	  /* search: by id list if given, by  states if given, by flags if given */
	  if (!match && state && gwlist_search(state, xstate, 
				   (gwlist_item_matches_t *)_x_octstr_str_compare) != NULL) 
	       match = 1;
	  
	  /* For the rest we only match if nothing else matched. Save time */
	  replace_slash(idx);
	  if (!match && msgrefs &&  	       
	      gwlist_search(msgrefs, idx, 
			  (gwlist_item_matches_t *)_x_octstr_str_compare) != NULL)
	       match = 1;
	  
	  if (!match &&
	      flag_cmds  &&
	       ((xflags = parse_string_list(linbuf + i)) != NULL && 
		gwlist_search(xflags, flags, (gwlist_item_matches_t *)string_in_list) != NULL))
	       match = 1;

	  if (match && ct >= start && gwlist_len(dflist) <= limit) {
		    Octstr *x = octstr_create(idx);
		    /* octstr_replace(x, octstr_imm("/"), octstr_imm("-")); */
		    gwlist_append(dflist, x);	       
	  }
	  ct++;
	  if (xflags)
	       gwlist_destroy(xflags, (gwlist_item_destructor_t *)octstr_destroy);     	  
     }     

 done:
     if (fp) 
	  unlock_and_fclose(fp);
     else if (tmpfd)
	  unlock_and_close(tmpfd);
     
     if (ifd > 0)
	  unlock_and_close(ifd);

     if (flags)
	  gwlist_destroy(flags, (gwlist_item_destructor_t *)octstr_destroy);     

     if (home) 
	  octstr_destroy(home);

     return dflist;
}
/* Update the log position of a bookmark */
int update_bookmark(EVT_HANDLE evt, os_channel *channel)
{
	DWORD size = 0;
	DWORD count = 0;
	wchar_t *buffer = NULL;
	int result = 0;
	EVT_HANDLE bookmark = NULL;
	FILE *fp = NULL;
	char tmp_file[OS_MAXSTR];

	/* Create bookmark temporary file name */
	snprintf(
		tmp_file,
		sizeof(tmp_file),
		"%s/%s-XXXXXX",
		TMP_DIR,
		channel->evt_log
	);

	replace_slash(tmp_file);

	if ((bookmark = EvtCreateBookmark(NULL)) == NULL)
	{
		log2file(
			"%s: ERROR: Could not EvtCreateBookmark() bookmark (%s) for (%s) which returned (%lu)",
			ARGV0,
			channel->bookmark_filename,
			channel->evt_log,
			GetLastError()
		);

		return(0);
	}

	if (!EvtUpdateBookmark(bookmark, evt))
	{
		log2file(
			"%s: ERROR: Could not EvtUpdateBookmark() bookmark (%s) for (%s) which returned (%lu)",
			ARGV0,
			channel->bookmark_filename,
			channel->evt_log,
			GetLastError()
		);

		return(0);
	}

	/* Make initial call to determine buffer size */
	result = EvtRender(NULL, bookmark, EvtRenderBookmark, 0, NULL, &size, &count);

	if (result != FALSE || GetLastError() != ERROR_INSUFFICIENT_BUFFER)
	{
		log2file(
			"%s: ERROR: Could not EvtRender() to get buffer size to update bookmark (%s) for (%s) which returned (%lu)",
			ARGV0,
			channel->bookmark_filename,
			channel->evt_log,
			GetLastError()
		);

		return(0);
	}

	if ((buffer = calloc(size, 1)) == NULL)
	{
		log2file(
			"%s: ERROR: Could not calloc() memory to save bookmark (%s) for (%s) which returned [(%d)-(%s)]",
			ARGV0,
			channel->bookmark_filename,
			channel->evt_log,
			errno,
			strerror(errno)
		);

		return(0);
	}

	if (!EvtRender(NULL, bookmark, EvtRenderBookmark, size, buffer, &size, &count))
	{
		log2file(
			"%s: ERROR: Could not EvtRender() bookmark (%s) for (%s) which returned (%lu)",
			ARGV0,
			channel->bookmark_filename,
			channel->evt_log,
			GetLastError()
		);

		return(0);
	}

	if (mkstemp_ex(tmp_file))
	{
		log2file(
			"%s: ERROR: Could not mkstemp_ex() temporary bookmark (%s) for (%s)",
			ARGV0,
			tmp_file,
			channel->evt_log
		);

		return(0);
	}

	if ((fp = fopen(tmp_file, "w")) == NULL)
	{
		log2file(
			"%s: ERROR: Could not fopen() temporary bookmark (%s) for (%s) which returned [(%d)-(%s)]",
			ARGV0,
			tmp_file,
			channel->evt_log,
			errno,
			strerror(errno)
		);

		goto error;
	}

	if ((fwrite(buffer, 1, size, fp)) < size)
	{
		log2file(
			"%s: ERROR: Could not fwrite() to temporary bookmark (%s) for (%s) which returned [(%d)-(%s)]",
			ARGV0,
			tmp_file,
			channel->evt_log,
			errno,
			strerror(errno)
		);

		goto error;
	}

	fclose(fp);

	if (rename_ex(tmp_file, channel->bookmark_filename))
	{
		log2file(
			"%s: ERROR: Could not rename_ex() temporary bookmark (%s) to (%s) for (%s)",
			ARGV0,
			tmp_file,
			channel->bookmark_filename,
			channel->evt_log
		);

		goto error;
	}

	/* success */
	return(1);

error:
	if (fp)
		fclose(fp);

	if (unlink(tmp_file))
	{
		log2file(DELETE_ERROR, ARGV0, tmp_file, errno, strerror(errno));
	}

	return(0);
}