コード例 #1
0
ファイル: locks.c プロジェクト: foswiki/WebDAVContrib
/* Get a lock, store pointer in global 'getlock'. */
static int getlock(enum ne_lock_scope scope, int depth)
{
    memset(&reslock, 0, sizeof(reslock));

    ne_fill_server_uri(i_session, &reslock.uri);
    reslock.uri.path = res;
    reslock.depth = depth;
    reslock.scope = scope;
    reslock.type = ne_locktype_write;
    reslock.timeout = 3600;
    reslock.owner = ne_strdup("litmus test suite");

    /* leave gotlock as NULL if the LOCK fails. */
    gotlock = NULL;

    ONMREQ("LOCK", res, ne_lock(i_session, &reslock));
    
    if (scope != reslock.scope) {
        t_context("requested lockscope not satisfied!  got %s, wanted %s",
                  scope == ne_lockscope_exclusive ? "exclusive" : "shared",
                  reslock.scope == ne_lockscope_exclusive ? 
                  "exclusive" : "shared");
        ne_unlock(i_session, &reslock);
        return FAIL;
    }    

    /* Take a copy of the lock. */
    gotlock = ne_lock_copy(&reslock);
    ne_lockstore_add(store, gotlock);

    return OK;
}
コード例 #2
0
ファイル: locks.c プロジェクト: foswiki/WebDAVContrib
static int notowner_lock(void)
{
    struct ne_lock dummy;

    PRECOND(gotlock);

    memcpy(&dummy, &reslock, sizeof(reslock));
    dummy.token = ne_strdup("opaquelocktoken:foobar");
    dummy.scope = ne_lockscope_exclusive;
    dummy.owner = ne_strdup("notowner lock");

    ONN("UNLOCK with bogus lock token",
	ne_unlock(i_session2, &dummy) != NE_ERROR);

    /* 2518 doesn't really say what status code that UNLOCK should
     * fail with. mod_dav gives a 400 as the locktoken is bogus.  */
    
    ONN("LOCK on locked resource",
	ne_lock(i_session2, &dummy) != NE_ERROR);
    
    if (dummy.token)  
        ne_free(dummy.token);

    if (STATUS2(423))
	t_warning("LOCK failed with %d not 423", GETSTATUS2);

    return OK;
}
コード例 #3
0
ファイル: locks.c プロジェクト: tolsen/limeberry
static int lock_collection(void)
{
    struct ne_lock dummy;
    char *tmp,*tmp2;
    
    CALL(getlock(ne_lockscope_exclusive, NE_DEPTH_INFINITE));
    
    PRECOND(gotlock);

    memcpy(&dummy, &reslock, sizeof(reslock));
    dummy.token = NULL;
    dummy.uri.path = collZ;
    dummy.owner = ne_strdup("litmus: owner lock");
    dummy.depth = NE_DEPTH_INFINITE;
    dummy.type = ne_locktype_write;
    dummy.scope = ne_lockscope_exclusive;
    
    ONNREQ2("LOCK on second collection for further tests", 
	    ne_lock(i_session, &dummy));
    gotlock = ne_lock_copy(&dummy);
    ne_lockstore_add(store, gotlock);

    /* Testing creation of directories under a collection */ 
    ONV(ne_mkcol(i_session, collX),
        ("MKCOL %s: %s", collX, ne_get_error(i_session)));
    ONV(ne_mkcol(i_session, collY),
        ("MKCOL %s: %s", collY, ne_get_error(i_session)));

    upload_foo("lockcoll/collX/temp");
    tmp = ne_concat(collY,"copy-temp",NULL);	
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, res3,tmp),
	("collection COPY `%s' to `%s': %s", res2, tmp,
	 ne_get_error(i_session)));
    free(tmp);
    
    tmp2=ne_concat(collZ,"testing",NULL);
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, res3,tmp2),
	("collection COPY `%s' to `%s': %s", res2, tmp2,
	 ne_get_error(i_session)));

    ne_free(res3);	
    res3 = ne_concat(i_path,"not-existing",NULL);

 
    /* change res to point to a normal resource for subsequent
     * {not_,}owner_modify tests */
    res = ne_concat(coll, "lockme.txt", NULL);
    return upload_foo("lockcoll/lockme.txt");
}
コード例 #4
0
ファイル: locks.c プロジェクト: foswiki/WebDAVContrib
/* take out another shared lock on the resource. */
static int double_sharedlock(void)
{
    struct ne_lock dummy;

    PRECOND(gotlock);

    memcpy(&dummy, &reslock, sizeof(reslock));
    dummy.token = NULL;
    dummy.owner = ne_strdup("litmus: notowner_sharedlock");
    dummy.scope = ne_lockscope_shared;

    ONNREQ2("shared LOCK on locked resource", 
	    ne_lock(i_session2, &dummy));
    
    ONNREQ2("unlock of second shared lock",
	    ne_unlock(i_session2, &dummy));

    return OK;
}
コード例 #5
0
ファイル: locks.c プロジェクト: tolsen/limeberry
/* Get a lock, store pointer in global 'getlock'. */
static int getlock(enum ne_lock_scope scope, int depth)
{
    memset(&reslock, 0, sizeof(reslock));

    ne_fill_server_uri(i_session, &reslock.uri);
    reslock.uri.path = res;
    reslock.depth = depth;
    reslock.scope = scope;
    reslock.type = ne_locktype_write;
    reslock.timeout = 3600;
    reslock.owner = ne_strdup("litmus test suite");

    /* leave gotlock as NULL if the LOCK fails. */
    gotlock = NULL;

    ONMREQ("LOCK", res, ne_lock(i_session, &reslock));
    
    /* Take a copy of the lock. */
    gotlock = ne_lock_copy(&reslock);
    ne_lockstore_add(store, gotlock);

    return OK;
}
コード例 #6
0
ファイル: edit.c プロジェクト: WigWagCo/cadaver
/* TODO: does this work under cygwin? mkstemp() may or may not open
   the file using O_BINARY, and then we *do* upload it using O_BINARY,
   so maybe this will screw things up. Maybe we should fcntl it and
   set O_BINARY, if that is allowed under cygwin? */
void execute_edit(const char *remote)
{
    char *real_remote;
    unsigned int can_lock; /* can we LOCK it? */
    struct ne_lock *lock = NULL;
    char fname[PATH_MAX] = "/tmp/cadaver-edit-XXXXXX";
    const char *pnt;
    int fd;
    int is_checkout, is_checkin;
    
    real_remote = resolve_path(session.uri.path, remote, false);

    /* Don't let them edit a collection, since PUT to a collection is
     * bogus. Really we want to be able to fetch a "DefaultDocument"
     * property, and edit on that instead: IIS does expose such a
     * property. Would be a nice hack to add the support to mod_dav
     * too. */
    if (getrestype(real_remote) == resr_collection) {
	printf(_("You cannot edit a collection resource (%s).\n"),
	       real_remote);
	goto edit_bail;
    }

    can_lock = is_lockable(real_remote);

    /* Give the local temp file the same extension as the remote path,
     * so the editor can have a stab at the content-type. */
    pnt = strrchr(real_remote, '.');
    if (pnt != NULL && strchr(pnt, '/') == NULL) {
	strncat(fname, pnt, PATH_MAX);
	fname[PATH_MAX-1] = '\0';
    }

    fd = cad_mkstemp(fname);
    if (fd == -1) {
	printf(_("Could not create temporary file %s:\n%s\n"), fname,
	       strerror(errno));
	goto edit_bail;
    }

    /* Sanity check on the file perms. */
#ifdef HAVE_FCHMOD
    if (fchmod(fd, 0600) == -1) {
#else
    if (chmod(fname, 0600) == -1) {
#endif
	printf(_("Could not set file permissions for %s:\n%s\n"), fname,
	       strerror(errno));
	goto edit_bail;
    }
   
    if (can_lock) {
	lock = ne_lock_create();
	ne_fill_server_uri(session.sess, &lock->uri);
	lock->uri.path = ne_strdup(real_remote);
	lock->owner = getowner();
	out_start("Locking", remote);
	if (out_handle(ne_lock(session.sess, lock))) {
	    ne_lockstore_add(session.locks, lock);
	} else {
	    ne_lock_destroy(lock);
	    goto edit_close;
	}
    } else {
	/* TODO: HEAD and get the Etag/modtime */
    }

    /* Return 1: Checkin, 2: Checkout, 0: otherwise */
    is_checkin = is_vcr(real_remote);
    if (is_checkin==1) {
    	execute_checkout(real_remote);
    }
    
    output(o_download, _("Downloading `%s' to %s"), real_remote, fname);

    /* Don't puke if get fails -- perhaps we are creating a new one? */
    out_result(ne_get(session.sess, real_remote, fd));
    
    if (close(fd)) {
	output(o_finish, _("Error writing to temporary file: %s\n"), 
	       strerror(errno));
    } 
    else if (!run_editor(fname)) {
	int upload_okay = 0;

	fd = open(fname, O_RDONLY | OPEN_BINARY_FLAGS);
	if (fd < 0) {
	    output(o_finish, 
		   _("Could not re-open temporary file: %s\n"),
		   strerror(errno));
	} else {
	    do {
		output(o_upload, _("Uploading changes to `%s'"), real_remote);
		/* FIXME: conditional PUT using fetched Etag/modtime if
		 * !can_lock */
		if (out_handle(ne_put(session.sess, real_remote, fd))) {
		    upload_okay = 1;
		} else {
		    /* TODO: offer to save locally instead */
		    printf(_("Try uploading again (y/n)? "));
		    if (!yesno()) {
			upload_okay = 1;
		    }
		}
	    } while (!upload_okay);
	    close(fd);
	}
    }
    
    if (unlink(fname)) {
	printf(_("Could not delete temporary file %s:\n%s\n"), fname,
	       strerror(errno));
    }	       

    /* Return 1: Checkin, 2: Checkout, 0: otherwise */
    is_checkout = is_vcr(real_remote);
    if (is_checkout==2) {
    	execute_checkin(real_remote);
    }
    
    /* UNLOCK it again whether we succeed or failed in our mission */
    if (can_lock) {
	output(o_start, "Unlocking `%s':", remote);
	out_result(ne_unlock(session.sess, lock));
	ne_lockstore_remove(session.locks, lock);
	ne_lock_destroy(lock);
    }

    goto edit_bail;
edit_close:
    close(fd);
edit_bail:
    free(real_remote);
    return;
}