int my_mkcol(char* uri, int depth) { char myuri[128]; int i, ret; if ( depth > 1){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%ssub/", myuri); if (ret=ne_mkcol(i_session, myuri)){ printf("my_mkcol failed 1\n"); return ret; } my_mkcol( 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, "%ssub%d/", myuri, i); if (ret=ne_mkcol(i_session, myuri)){ return ret; printf("my_mkcol failed 2\n"); } } return ret; }
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"); }
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 void mk_dir(char **md_vals, int depth) { /* * construct path to check */ int ret; char remote_path[1024]; switch (depth) { case 1: sprintf(remote_path, "%s/%s", "/webdav/oFotoHashDirs", md_vals[0]); break; case 2: sprintf(remote_path, "%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1]); break; case 3: sprintf(remote_path, "%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2]); break; case 4: sprintf(remote_path, "%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3]); break; case 5: sprintf(remote_path, "%s/%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3], md_vals[4]); break; case 6: sprintf(remote_path, "%s/%s/%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3], md_vals[4], md_vals[5]); break; } if (hc_host == NULL) { printf("%s\n", remote_path); return; } if (verbose) printf("%s\n", remote_path); ret = ne_mkcol(session.sess, remote_path); if (ret != NE_OK) { if (strstr(ne_get_error(session.sess), "409 Conflict")) { if (verbose) printf(" already exists\n"); else printf("already exists: %s\n", remote_path); return; } printf("failed: %s\n", ne_get_error(session.sess)); quit(1); } count++; }
static int prep_collection(void) { if (gotlock) { ne_lock_destroy(gotlock); gotlock = NULL; } ne_free(res); res = coll = ne_concat(i_path, "lockcoll/", NULL); ONV(ne_mkcol(i_session, res), ("MKCOL %s: %s", res, ne_get_error(i_session))); return OK; }
static int copy_init(void) { src = ne_concat(i_path, "copysrc", NULL); dest = ne_concat(i_path, "copydest", NULL); coll = ne_concat(i_path, "copycoll/", NULL); ncoll = ne_concat(i_path, "copycoll", NULL); CALL(upload_foo("copysrc")); ONNREQ("could not create collection", ne_mkcol(i_session, coll)); copy_ok = 1; return OK; }
static int prep_collection(void) { if (gotlock) { ne_lock_destroy(gotlock); gotlock = NULL; } ne_free(res); ne_free(res3); res = coll = ne_concat(i_path, "lockcoll/", NULL); /* Setting directories for further tests */ collX = ne_concat(coll,"collX/",NULL); collY = ne_concat(coll,"collY/",NULL); res3 = ne_concat(collX,"temp",NULL); collZ = ne_concat(i_path, "lockcoll2/", NULL); ONV(ne_mkcol(i_session, res), ("MKCOL %s: %s", res, ne_get_error(i_session))); ONV(ne_mkcol(i_session, collZ), ("MKCOL %s: %s", collZ, ne_get_error(i_session))); 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; }
/* * create a hierarchy of 10 levels deep, NBOTTOM files at bottom level */ void my_mkcol2(char* uri, int depth) { 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); if (ne_mkcol(i_session, myuri)){ printf("ne_mkcol failed\n"); return; } # Return error if myuri + "sub/" is > 128 if (strlen(myuri) >= sizeof(myuri) - 4) { printf("\nERROR: max depth reached.\n"); exit(1); } else { 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); if (ne_put(i_session, myuri, fd)){ printf("ne_put failed\n"); return; } } unlink(tmp); return; }
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; }
static int owncloud_mkdir(const char *uri, mode_t mode) { int rc = NE_OK; char buf[PATH_MAX +1]; int len = 0; char *path = _cleanPath( uri ); (void) mode; /* unused */ if( ! path ) { errno = EINVAL; rc = -1; } rc = dav_connect(uri); if (rc < 0) { errno = EINVAL; } /* the uri path is required to have a trailing slash */ if( rc >= 0 ) { memset( buf,0, PATH_MAX+1 ); len = strlen( path ); strncpy( buf, path, len ); if( buf[len-1] != '/' ) { buf[len] = '/'; } DEBUG_WEBDAV("MKdir on %s", buf ); rc = ne_mkcol(dav_session.ctx, buf ); if (rc != NE_OK ) { set_errno_from_session(); } } SAFE_FREE( path ); if( rc < 0 || rc != NE_OK ) { return -1; } return 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; }
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; }