示例#1
0
static int move_cleanup(void)
{
    ne_delete(i_session, mdest);
    ne_delete(i_session, mdest2);
    ne_delete(i_session, mnoncoll);
    return OK;
}
示例#2
0
/* check that locks don't follow copies. */
static int copy(void)
{
    char *dest;
    int count = 0;
    
    PRECOND(gotlock);

    dest = ne_concat(res, "-copydest", NULL);

    ne_delete(i_session2, dest);

    ONNREQ2("could not COPY locked resource",
	    ne_copy(i_session2, 1, NE_DEPTH_ZERO, res, dest));
    
    ONNREQ2("LOCK discovery failed",
	    ne_lock_discover(i_session2, dest, count_discover, &count));
    
    ONV(count != 0,
	("found %d locks on copied resource", count));

    ONNREQ2("could not delete copy of locked resource",
	    ne_delete(i_session2, dest));

    free(dest);

    return OK;
}
示例#3
0
static int copy_cleanup(void)
{
    ne_delete(i_session, src);
    ne_delete(i_session, dest);
    ne_delete(i_session, ncoll);
    ne_delete(i_session, coll);
    return OK;
}
示例#4
0
文件: common.c 项目: tolsen/Prestan
int finish(void)
{
    ne_delete(i_session, i_path);
    ne_session_destroy(i_session);
    printf("\n\n");
    return OK;
}
示例#5
0
文件: locks.c 项目: tolsen/limeberry
static int owner_modify(void)
{
    char *tmp;
    ne_propname pname = { "http://webdav.org/neon/litmus/", "random" };
    ne_proppatch_operation pops[] = { 
	{ NULL, ne_propset, "foobar" },
	{ NULL }
    };
    PRECOND(gotlock);

    ONV(ne_put(i_session, res, i_foo_fd),
	("PUT on locked resource failed: %s", ne_get_error(i_session)));
    
    tmp = ne_concat(i_path, "whocares", NULL);
    ONN("COPY of locked resource", 
	ne_copy(i_session, 1, NE_DEPTH_ZERO, res, tmp) == NE_ERROR);
    
   if (STATUS(201))
	t_warning("COPY failed with %d not 201", GETSTATUS);
    
    ONN("DELETE of locked resource by owner", 
	ne_delete(i_session, tmp) == NE_ERROR);

    if (STATUS(204)) 
	t_warning("DELETE of %s failed with %d not 200", tmp, GETSTATUS);
    free(tmp);
    
    ONN("PROPPATCH of locked resource",
	ne_proppatch(i_session, res, pops) == NE_ERROR);
    
    if (STATUS(207))
	t_warning("PROPPATCH failed with %d", GETSTATUS);

    return OK;
}
示例#6
0
static int copy_shallow(void)
{
    char *csrc, *cdest, *res;

    csrc = ne_concat(i_path, "ccsrc/", NULL);
    cdest = ne_concat(i_path, "ccdest/", NULL);

    /* Set up the ccsrc collection with one member */
    ONMREQ("MKCOL", csrc, ne_mkcol(i_session, csrc));
    CALL(upload_foo("ccsrc/foo"));

    /* Clean up to make some fresh copies. */
    ne_delete(i_session, cdest);

    /* Now copy with Depth 0 */
    ONV(ne_copy(i_session, 0, NE_DEPTH_ZERO, csrc, cdest),
	("collection COPY `%s' to `%s': %s", csrc, cdest,
	 ne_get_error(i_session)));

    /* Remove the source, to be paranoid. */
    if (ne_delete(i_session, csrc)) {
	t_warning("Could not delete csrc");
    }

    /* Now make sure the child resource hasn't been copied along with
     * the collection. */
    res = ne_concat(i_path, "foo", NULL);
    ne_delete(i_session, res);
    ONV(STATUS(404), 
        ("DELETE on `%s' should fail with 404: got %d", res, GETSTATUS));
    ne_free(res);

    if (ne_delete(i_session, cdest)) {
	t_warning("Could not clean up cdest");
    }

    return OK;
}
示例#7
0
static int move(void)
{
    char *src2;

    src = ne_concat(i_path, "move", NULL);
    src2 = ne_concat(i_path, "move2", NULL);
    dest = ne_concat(i_path, "movedest", NULL);
    coll = ne_concat(i_path, "movecoll/", NULL);
    ncoll = ne_concat(i_path, "movecoll", NULL);

    /* Upload it twice. */
    CALL(upload_foo("move"));
    CALL(upload_foo("move2"));
    ONMREQ("MKCOL", coll, ne_mkcol(i_session, coll));

    /* Now move it */
    ONM2REQ("MOVE", src, dest, ne_move(i_session, 0, src, dest));

    if (STATUS(201)) {
	t_warning("MOVE to new resource didn't give 201");
    }

    /* Try a move with Overwrite: F to check that fails. */
    ONM2REQ("MOVE on existing resource with Overwrite: F succeeded",
	    src2, dest, 
	    ne_move(i_session, 0, src2, dest) != NE_ERROR);

    if (STATUS(412)) {
	t_warning("MOVE-on-existing should fail with 412");
    }

    ONM2REQ("MOVE onto existing resource with Overwrite: T",
	    src2, dest,
	    ne_move(i_session, 1, src2, dest));

    ONM2REQ("MOVE overwrites collection", coll, dest,
	    ne_move(i_session, 1, dest, coll));
    
    if (STATUS(204)) {
	t_warning("MOVE to existing collection resource didn't give 204");
    }
		  
    if (ne_delete(i_session, ncoll)) {
	t_warning("Could not clean up `%s'", ncoll);
    }

    return OK;
}
示例#8
0
static int notowner_modify(void)
{
    char *tmp;
    ne_propname pname = { "http://webdav.org/neon/litmus/", "random" };
    ne_proppatch_operation pops[] = { 
	{ NULL, ne_propset, "foobar" },
	{ NULL }
    };

    PRECOND(gotlock);

    pops[0].name = &pname;

    ONN("DELETE of locked resource should fail", 
	ne_delete(i_session2, res) != NE_ERROR);

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

    tmp = ne_concat(i_path, "whocares", NULL);
    ONN("MOVE of locked resource should fail", 
	ne_move(i_session2, 0, res, tmp) != NE_ERROR);
    free(tmp);
    
    if (STATUS2(423))
	t_warning("MOVE failed with %d not 423", GETSTATUS2);
    
    ONN("COPY onto locked resource should fail",
	ne_copy(i_session2, 1, NE_DEPTH_ZERO, res2, res) != NE_ERROR);

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

    ONN("PROPPATCH of locked resource should fail",
	ne_proppatch(i_session2, res, pops) != NE_ERROR);
    
    if (STATUS2(423))
	t_warning("PROPPATCH failed with %d not 423", GETSTATUS2);

    ONN("PUT on locked resource should fail",
	ne_put(i_session2, res, i_foo_fd) != NE_ERROR);

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

    return OK;    
}
示例#9
0
文件: common.c 项目: tolsen/Prestan
int begin(void)
{
    const char *scheme = use_secure?"https":"http";
    char *space;
    static const char blanks[] = "          ";
    static const char stars[] = "**********************************";
    

    i_session = ne_session_create(scheme, i_hostname, i_port);
    CALL(init_session(i_session));
    ne_hook_pre_send(i_session, i_pre_send, "X-Prestan");


    space = ne_concat(i_path, "davtest/", NULL);
    ne_delete(i_session, space);
    if (ne_mkcol(i_session, space)) {
	t_context("Could not create new collection `%s' for tests: %s\n"
	  "Server must allow `MKCOL %s' for tests to proceed", 
	  space, ne_get_error(i_session), space);
	return FAILHARD;
    }
    free(i_path);
    i_path = space;    
    
    warmup();

    printf("\nStart Testing %s:\n\n",pget_option.URL) ;
    printf("\n%s%s\n", blanks, stars);
    printf("\n%s* Number of Requests\t\t%d\n", blanks, pget_option.requests);
    printf("\n%s* Number of Dead Properties\t%d\n", 
    			blanks, pget_option.numprops);
    printf("\n%s* Depth of Collection\t\t%d\n", blanks, pget_option.depth);
    printf("\n%s* Width of Collection\t\t%d\n", blanks, pget_option.width);
    printf("\n%s* Type of Methods\t\t%s\n", blanks, pget_option.methods);
    printf("\n%s%s\n", blanks, stars);
    printf("\n\n");
    
    return OK;
}
示例#10
0
static int owncloud_rmdir(const char *uri) {
    int rc = NE_OK;
    char* curi = _cleanPath( uri );

    rc = dav_connect(uri);
    if (rc < 0) {
        errno = EINVAL;
    }

    if( rc >= 0 ) {
        rc = ne_delete(dav_session.ctx, curi);
        if ( rc != NE_OK ) {
          set_errno_from_session();
        }
    }
    SAFE_FREE( curi );
    if( rc < 0 || rc != NE_OK ) {
        return -1;
    }

    return 0;
}
示例#11
0
static int owncloud_unlink(const char *uri) {
    int rc = NE_OK;
    char *path = _cleanPath( uri );

    if( ! path ) {
        rc = NE_ERROR;
        errno = EINVAL;
    }
    if( rc == NE_OK ) {
        rc = dav_connect(uri);
        if (rc < 0) {
            errno = EINVAL;
        }
    }
    if( rc == NE_OK ) {
        rc = ne_delete( dav_session.ctx, path );
        if ( rc != NE_OK )
            set_errno_from_session();
    }
    SAFE_FREE( path );

    return 0;
}
示例#12
0
static int move_coll(void)
{
    int n;
    char *rsrc, *rdest, *subsrc, *subdest;
    char res[512];

    msrc = ne_concat(i_path, "mvsrc/", NULL);
    mdest = ne_concat(i_path, "mvdest/", NULL);
    mdest2 = ne_concat(i_path, "mvdest2/", NULL);
    rsrc = ne_concat(i_path, "mvsrc/foo", NULL);
    rdest = ne_concat(i_path, "mvdest/foo", NULL); 
    subsrc = ne_concat(i_path, "mvsrc/subcoll/", NULL);
    subdest = ne_concat(i_path, "mvdest/subcoll/", NULL);
    mnoncoll = ne_concat(i_path, "mvnoncoll", NULL);

    /* Set up the mvsrc collection. */
    ONMREQ("MKCOL", msrc, ne_mkcol(i_session, msrc));
    for (n = 0; n < 10; n++) {
	sprintf(res, "mvsrc/foo.%d", n);
	CALL(upload_foo(res));
    }
    CALL(upload_foo("mvnoncoll"));

    ONV(ne_mkcol(i_session, subsrc),
	("MKCOL of `%s' failed: %s\n", subsrc, SERR));
    
    /* Now make a copy of the collection */
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, msrc, mdest2),
	("collection COPY `%s' to `%s', depth infinity: %s",
	 msrc, mdest2, SERR));

    ONV(ne_move(i_session, 0, msrc, mdest),
	("collection MOVE `%s' to `%s': %s", msrc, mdest, SERR));

    ONN("MOVE-on-existing-coll should fail",
	ne_move(i_session, 0, mdest, mdest2) != NE_ERROR);
    
    ONN("MOVE-on-existing-coll with overwrite",
	ne_move(i_session, 1, mdest2, mdest));

    /* Take another copy. */
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, mdest, mdest2),
	("collection COPY `%s' to `%s', depth infinity: %s",
	 mdest, mdest2, ne_get_error(i_session)));

    /* Now delete things out of the destination collection to check if
     * they are there. */
    for (n = 0; n < 10; n++) {
	sprintf(res, "%s%s.%d", i_path, "mvdest/foo", n);
	ONV(ne_delete(i_session, res),
	    ("DELETE from copied collection failed for `%s': %s",
	     res, SERR));
    }

    ONV(ne_delete(i_session, subdest),
	("DELETE from copied collection failed for `%s': %s",
	 subdest, SERR));

    /* And move the spare collection over a non-coll. */
    ONV(ne_move(i_session, 1, mdest2, mnoncoll),
	("MOVE collection `%s' over non-collection `%s' with overwrite: %s",
	 mdest2, mnoncoll, ne_get_error(i_session)));

    return OK;
}
示例#13
0
文件: locks.c 项目: tolsen/limeberry
static int lock_on_no_file(void)
{
    char *tmp;
    res = ne_concat(i_path, "locknullfile", NULL);
    tmp = ne_concat(i_path, "whocares", NULL);
		
    getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO);
	
	if (STATUS(200)) 
		t_warning("Lock Null failed with %d not 200", GETSTATUS);

    //FIXME: After Lock Null is created, Do Unlock it to maintain integrity of tests
    //ONNREQ2("unlock of second shared lock",ne_unlock(i_session, &gotlock));
    
   
    // Copy of nulllock resource
    ONN("COPY null locked resource should ",
	ne_copy(i_session, 1, NE_DEPTH_ZERO, res, tmp) == NE_ERROR);
     
    // Delete of nulllockresource
    ONN("DELETE of locknull resource by owner", 
	ne_delete(i_session, tmp) == NE_ERROR);
    free(tmp);

    // Move of nulllockresource
    tmp = ne_concat(i_path, "who-cares", NULL);
    ONN("MOVE of null-locked resource", 
	ne_move(i_session, 0, res, tmp) == NE_ERROR);
    ONN("DELETE of locknull resource by owner after a MOVE with overwrite (F)", 
	ne_delete(i_session, tmp) == NE_ERROR);
   
    /* Delete the locktoken from store */ 	
    ne_lockstore_remove(store, gotlock);
    getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO);
	if (STATUS(200)) 
		t_warning("Lock Null failed with %d not 200", GETSTATUS);

     /* Lot of code duplication, but want to test each case individually.
      * Locknull resource. How it behaves when it is copied 
      * moved (with overwrite T/F)
      * PUT request on locknullresource should succeed. 
      */
     

    /*MOVE of null-locked resource with overwrite=T */
    ONN("MOVE of null-locked resource with overwrite=T (1)", 
	ne_move(i_session, 1, res, tmp) == NE_ERROR);
    ne_lockstore_remove(store, gotlock);
    getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO);
	if (STATUS(200)) 
		t_warning("Lock Null failed with %d not 200", GETSTATUS);
    ONN("MOVE of null-locked resource with overwrite=T (2)", 
	ne_move(i_session, 1, res, tmp) == NE_ERROR);
	
    ne_lockstore_remove(store, gotlock);
    getlock(ne_lockscope_shared, NE_DEPTH_ZERO);
	if (STATUS(200)) 
		t_warning("Lock Null failed with %d not 200", GETSTATUS);
    
    ONN("COPY on null-locked resource with overwrite=T", 
	ne_copy(i_session, 1, NE_DEPTH_ZERO, tmp, res) == NE_ERROR);

   ONN("DELETE of locknull resource by owner after a MOVE (T) ", 
	ne_delete(i_session, tmp) == NE_ERROR);
    free(tmp);

    // Put on nulllockresource
    ONV(ne_put(i_session,res, i_foo_fd),
	 ("PUT on locknullfile resource failed: %s", ne_get_error(i_session)));
	
	return OK;
}
示例#14
0
Hbf_State hbf_transfer( ne_session *session, hbf_transfer_t *transfer, const char *verb ) {
    Hbf_State state = HBF_TRANSFER_SUCCESS;
    int cnt;

    if( ! session ) {
        state = HBF_SESSION_FAIL;
    }
    if( ! transfer ) {
        state = HBF_SPLITLIST_FAIL;
    }
    if( ! verb ) {
        state = HBF_PARAM_FAIL;
    }

    if(state == HBF_TRANSFER_SUCCESS) {
        DEBUG_HBF("%s request to %s", verb, transfer->url);
    }

    for( cnt=0; state == HBF_TRANSFER_SUCCESS && cnt < transfer->block_cnt; cnt++ ) {
        /* cnt goes from O to block_cnt,  but block_id starts at start_id and wrap around
         * That way if we have not finished uploaded when we reach block_cnt, we re-upload
         * the beginning of the file that the server did not have in cache anymore.
         */
        int block_id = (cnt + transfer->start_id) % transfer->block_cnt;
        hbf_block_t *block = transfer->block_arr[block_id];
        char *transfer_url = NULL;

        if( ! block ) state = HBF_PARAM_FAIL;

        if( transfer->abort_cb ) {
            int do_abort = (transfer->abort_cb)(transfer->user_data);
            if( do_abort ) {
              state = HBF_USER_ABORTED;
              transfer->start_id = block_id  % transfer->block_cnt;
            }
        }

        if( state == HBF_TRANSFER_SUCCESS ) {
            transfer_url = get_transfer_url( transfer, block_id );
            if( ! transfer_url ) {
                state = HBF_PARAM_FAIL;
            }
        }

        if( state == HBF_TRANSFER_SUCCESS ) {
          if( transfer->block_cnt > 1 && cnt > 0 ) {
            /* The block count is > 1, check size and mtime before transmitting. */
            state = hbf_validate_source_file(transfer);
            if( state == HBF_SOURCE_FILE_CHANGE ) {
              /* The source file has changed meanwhile */
            }
          }
        }

        if( state == HBF_TRANSFER_SUCCESS || state == HBF_SUCCESS ) {
            ne_request *req = ne_request_create(session, verb, transfer_url);

            if( req ) {
                char buf[21];

                snprintf(buf, sizeof(buf), "%"PRId64, transfer->stat_size);
                ne_add_request_header(req, "OC-Total-Length", buf);
                if( transfer->oc_header_modtime > 0 ) {
                    snprintf(buf, sizeof(buf), "%"PRId64, transfer->oc_header_modtime);
                    ne_add_request_header(req, "X-OC-Mtime", buf);
                }

                if( transfer->previous_etag ) {
                  ne_add_request_header(req, "If-Match", transfer->previous_etag);
                }

                if( transfer->block_cnt > 1 ) {
                  ne_add_request_header(req, "OC-Chunked", "1");
                  snprintf(buf, sizeof(buf), "%"PRId64, transfer->threshold);
                  ne_add_request_header(req, "OC-Chunk-Size", buf);
                }
                ne_add_request_header( req, "Content-Type", "application/octet-stream");

                state = _hbf_dav_request(transfer,  req, transfer->fd, block );

                if( state != HBF_TRANSFER_SUCCESS && state != HBF_SUCCESS) {
                  if( transfer->error_string ) free( transfer->error_string );
                  transfer->error_string = strdup( ne_get_error(session) );
                  transfer->start_id = block_id  % transfer->block_cnt;
                  /* Set the code of the last transmission. */
                  state = HBF_FAIL;
                  transfer->status_code = transfer->block_arr[block_id]->http_result_code;
                }
                ne_request_destroy(req);

                if (transfer->block_cnt > 1 && state == HBF_SUCCESS && cnt == 0) {
                    /* Success on the first chunk is suspicious.
                       It could happen that the server did not support chunking */
                    int rc = ne_delete(session, transfer_url);
                    if (rc == NE_OK && _hbf_http_error_code(session) == 204) {
                        /* If delete suceeded, it means some proxy strips the OC_CHUNKING header
                           start again without chunking: */
                       free( transfer_url );
                       return _hbf_transfer_no_chunk(session, transfer, verb);
                    }
                }

                if (state == HBF_TRANSFER_SUCCESS && transfer->chunk_finished_cb) {
                    transfer->chunk_finished_cb(transfer, block_id, transfer->user_data);
                }

            } else {
                state = HBF_MEMORY_FAIL;
            }
        }
        free( transfer_url );
    }

    /* do the source file validation finally (again). */
    if( state == HBF_TRANSFER_SUCCESS ) {
        /* This means that no etag was returned on one of the chunks to indicate
         * that the upload was finished. */
        state = HBF_TRANSFER_NOT_ACKED;
    }

    return state;
}
示例#15
0
文件: dal.c 项目: thewacokid/marfs
int mc_del(DAL_Context* ctx) {
   char* path_template = MC_CONTEXT(ctx)->path_template;
   int nblocks = MC_CONFIG(ctx)->n + MC_CONFIG(ctx)->e;

   return ne_delete(path_template, nblocks);
}
示例#16
0
文件: locks.c 项目: tolsen/limeberry
static int lockcleanup(void)
{
    ne_delete(i_session, i_path);
    return OK;
}
示例#17
0
static int copy_coll(void)
{
    int n;
    char *csrc, *cdest, *rsrc, *rdest, *subsrc, *subdest, *cdest2;
    char res[512];

    csrc = ne_concat(i_path, "ccsrc/", NULL);
    cdest = ne_concat(i_path, "ccdest/", NULL);
    cdest2 = ne_concat(i_path, "ccdest2/", NULL);
    rsrc = ne_concat(i_path, "ccsrc/foo", NULL);
    rdest = ne_concat(i_path, "ccdest/foo", NULL); 
    subsrc = ne_concat(i_path, "ccsrc/subcoll/", NULL);
    subdest = ne_concat(i_path, "ccdest/subcoll/", NULL);

    /* Set up the ccsrc collection. */
    ONMREQ("MKCOL", csrc, ne_mkcol(i_session, csrc));
    for (n = 0; n < 10; n++) {
	sprintf(res, "ccsrc/foo.%d", n);
	CALL(upload_foo(res));
    }
    ONMREQ("MKCOL", subsrc, ne_mkcol(i_session, subsrc));
    
    /* Clean up to make some fresh copies. */
    ne_delete(i_session, cdest);
    ne_delete(i_session, cdest2);

    /* Now copy the collection a couple of times */
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, csrc, cdest),
	("collection COPY `%s' to `%s': %s", csrc, cdest,
	 ne_get_error(i_session)));
    ONV(ne_copy(i_session, 0, NE_DEPTH_INFINITE, csrc, cdest2),
	("collection COPY `%s' to `%s': %s", csrc, cdest,
	 ne_get_error(i_session)));

    ONN("COPY-on-existing-coll should fail",
	ne_copy(i_session, 0, NE_DEPTH_INFINITE, cdest, cdest2) != NE_ERROR);
    
    ONV(ne_copy(i_session, 1, NE_DEPTH_INFINITE, cdest2, cdest),
	("COPY-on-existing-coll with overwrite: %s", ne_get_error(i_session)));

    /* Remove the source, to be paranoid. */
    if (ne_delete(i_session, csrc)) {
	t_warning("Could not delete csrc");
    }

    /* Now delete things out of the destination collection to check if
     * they are there. */
    for (n = 0; n < 10; n++) {
	sprintf(res, "%s%s.%d", i_path, "ccdest/foo", n);
	ONV(ne_delete(i_session, res),
	    ("COPY destination coll missing %s? %s", res,
	     ne_get_error(i_session)));
    }

    ONV(ne_delete(i_session, subdest),
	("COPY destination missing sub-coll %s? %s", subdest,
	 ne_get_error(i_session)));	 

    /* Now nuke the whole of the second copy. */
    ONV(ne_delete(i_session, cdest2),
	("COPY destination %s missing? %s", cdest2, ne_get_error(i_session)));

    if (ne_delete(i_session, cdest)) {
	t_warning("Could not clean up cdest");
    }

    return OK;
}