1 /* 2 HTTP/1.1 methods 3 Copyright (C) 1999-2002, Joe Orton <joe@manyfish.co.uk> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public 16 License along with this library; if not, write to the Free 17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 18 MA 02111-1307, USA 19 20 */ 21 22 #ifndef NE_BASIC_H 23 #define NE_BASIC_H 24 25 #include <sys/types.h> /* for time_t */ 26 27 #include "ne_request.h" 28 29 BEGIN_NEON_DECLS 30 31 /* Perform a GET request on resource at 'path', writing the entity 32 * body which is returned to 'fd'. */ 33 int ne_get(ne_session *sess, const char *path, int fd); 34 35 /* Perform a PUT request on resource at 'path', reading the entity 36 * body to submit from 'fd'. */ 37 int ne_put(ne_session *sess, const char *path, int fd); 38 39 #ifndef NEON_NODAV 40 41 #define NE_DEPTH_ZERO (0) 42 #define NE_DEPTH_ONE (1) 43 #define NE_DEPTH_INFINITE (2) 44 45 46 /* For ne_copy and ne_move: 47 * 48 * If a resource exists at "dest" and overwrite is zero, the operation 49 * will fail; if overwrite is non-zero, any existing resource will 50 * be over-written. 51 */ 52 53 /* Copy resource from 'src to 'dest' paths. If 'src' identifies a 54 * collection resource, depth may be NE_DEPTH_ZERO to request that the 55 * collection and its properties are to be copied, or 56 * NE_DEPTH_INFINITE to request that the collection and its contents 57 * are to be copied. */ 58 int ne_copy(ne_session *sess, int overwrite, int depth, 59 const char *src, const char *dest); 60 61 /* Move resource from 'src' to dest 'path'. */ 62 int ne_move(ne_session *sess, int overwrite, 63 const char *src, const char *dest); 64 65 /* Delete resource at 'path'. */ 66 int ne_delete(ne_session *sess, const char *path); 67 /* Create a collection at 'path', which MUST have a trailing slash. */ 68 int ne_mkcol(ne_session *sess, const char *path); 69 70 /* Adds a Depth: header to a request */ 71 void ne_add_depth_header(ne_request *req, int depth); 72 73 #endif /* NEON_NODAV */ 74 75 /* PUT resource at location as above, only if it has not been modified 76 * since given modtime. If server is HTTP/1.1, uses If-Unmodified-Since 77 * header; guaranteed failure if resource is modified after 'modtime'. 78 * If server is HTTP/1.0, HEAD's the resource first to fetch current 79 * modtime; race condition if resource is modified between HEAD and PUT. 80 */ 81 int ne_put_if_unmodified(ne_session *sess, 82 const char *path, int fd, time_t modtime); 83 84 /* Retrieve modification time of resource at location 'path', place in 85 * *modtime. (uses HEAD) */ 86 int ne_getmodtime(ne_session *sess, const char *path, time_t *modtime); 87 88 typedef struct { 89 const char *type, *subtype; 90 const char *charset; 91 char *value; 92 } ne_content_type; 93 94 /* Sets (*ne_content_type)userdata appropriately. 95 * Caller must free ->value after use */ 96 void ne_content_type_handler(void *userdata, const char *value); 97 98 /* Server capabilities: */ 99 typedef struct { 100 unsigned int dav_class1; /* True if Class 1 WebDAV server */ 101 unsigned int dav_class2; /* True if Class 2 WebDAV server */ 102 unsigned int dav_executable; /* True if supports the 'executable' 103 * property a. la. mod_dav */ 104 } ne_server_capabilities; 105 106 /* Determines server capabilities (using OPTIONS). Pass 'path' as "*" 107 * to determine proxy server capabilities if using a proxy server. */ 108 int ne_options(ne_session *sess, const char *path, 109 ne_server_capabilities *caps); 110 111 /* Defines a range of bytes, starting at 'start' and ending 112 * at 'end'. 'total' is the number of bytes in the range. 113 */ 114 typedef struct { 115 off_t start, end, total; 116 } ne_content_range; 117 118 /* Partial GET. range->start must be >= 0. range->total is ignored. 119 * 120 * If range->end is -1, then the rest of the resource from start is 121 * requested, and range->total and end are filled in on success. 122 * 123 * Otherwise, bytes from range->start to range->end are requested. 124 * 125 * This will write to the CURRENT position of f; so if you want 126 * to do a resume download, use: 127 * struct ne_content_range range; 128 * range.start = resume_from; 129 * range.end = range.start + 999; (= 1000 bytes) 130 * fseek(myfile, resume_from, SEEK_SET); 131 * ne_get_range(sess, path, &range, myfile); */ 132 int ne_get_range(ne_session *sess, const char *path, 133 ne_content_range *range, int fd); 134 135 /* Post using buffer as request-body: stream response into f */ 136 int ne_post(ne_session *sess, const char *path, int fd, const char *buffer); 137 138 END_NEON_DECLS 139 140 #endif /* NE_BASIC_H */ 141