/* 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; }
void my_mkcol2_proppatch(char* uri, int depth, const ne_propname pops[]) { char tmp[256] = "/tmp/Davtest-XXXXXX"; char myuri[128]; int i, fd; if ( (fd=mkstemp(tmp)) < 0){ perror("mkstemp() :"); return ; } for( i=0; i<4; i++) write(fd, tmp, sizeof(tmp)); if ( depth > 1){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%ssub/", myuri); ONV(ne_mkcol(i_session, myuri), ("MKCOL %s: %s", myuri, ne_get_error(i_session))); ONMREQ("PROPPATCH",myuri, ne_proppatch(i_session, myuri, pops)); my_mkcol2( myuri, depth-1); }else if ( depth == 1) for ( i=0; i<pget_option.width; i++){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%sfile%d", myuri, i); ONV(ne_put(i_session, myuri, fd), ("PUT of %s: %s", myuri, ne_get_error(i_session))); } return; }
static int refresh(void) { PRECOND(gotlock); ONMREQ("LOCK refresh", gotlock->uri.path, ne_lock_refresh(i_session, gotlock)); return OK; }
static int unlock(void) { PRECOND(gotlock); ONMREQ("UNLOCK", gotlock->uri.path, ne_unlock(i_session, gotlock)); /* Remove lock from session. */ ne_lockstore_remove(store, gotlock); /* for safety sake. */ gotlock = NULL; return OK; }
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; }
/* Perform a conditional PUT request with given If: header value, * placing response status-code in *code and class in *klass. Fails * if requests cannot be dispatched. */ static int conditional_put(const char *ifhdr, int *klass, int *code) { ne_request *req; req = ne_request_create(i_session, "PUT", res); ne_set_request_body_fd(req, i_foo_fd, 0, i_foo_len); ne_print_request_header(req, "If", "%s", ifhdr); ONMREQ("PUT", res, ne_request_dispatch(req)); if (code) *code = ne_get_status(req)->code; if (klass) *klass = ne_get_status(req)->klass; ne_request_destroy(req); return OK; }
static int owner_modify(void) { PRECOND(gotlock); ne_proppatch_operation pops[] = { { NULL, ne_propset, "foobar" }, { NULL } }; const ne_propname pname = { "http://webdav.org/neon/litmus/", "random" }; pops[0].name = &pname; ONV(ne_put(i_session, res, i_foo_fd), ("PUT on locked resource failed: %s", ne_get_error(i_session))); ONMREQ("PROPPATCH on locked resouce", res, ne_proppatch(i_session, res, pops)); return OK; }
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; }
/* 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; }
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; }
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; }