1 /* 2 HTTP/1.1 methods 3 Copyright (C) 1999-2008, 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 NE_BEGIN_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 #define NE_DEPTH_ZERO (0) 40 #define NE_DEPTH_ONE (1) 41 #define NE_DEPTH_INFINITE (2) 42 43 /* For ne_copy and ne_move: 44 * 45 * If a resource exists at "dest" and overwrite is zero, the operation 46 * will fail; if overwrite is non-zero, any existing resource will 47 * be over-written. 48 */ 49 50 /* Copy resource from 'src to 'dest' paths. If 'src' identifies a 51 * collection resource, depth may be NE_DEPTH_ZERO to request that the 52 * collection and its properties are to be copied, or 53 * NE_DEPTH_INFINITE to request that the collection and its contents 54 * are to be copied. Returns NE_* error code. */ 55 int ne_copy(ne_session *sess, int overwrite, int depth, 56 const char *src, const char *dest); 57 58 /* Move resource from 'src' to 'dest' path. Returns NE_* error 59 * code. */ 60 int ne_move(ne_session *sess, int overwrite, 61 const char *src, const char *dest); 62 63 /* Delete resource at 'path'. Returns NE_* error code. */ 64 int ne_delete(ne_session *sess, const char *path); 65 66 /* Create a collection at 'path', which is required to have a trailing 67 * slash. Returns NE_* error code. */ 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 /* Retrieve modification time of resource at location 'path', using 74 * the HEAD method, placing parsed time in *modtime. *modtime is set 75 * to -1 if no Last-Modified response header was given, or the date 76 * given could not be parsed. Returns NE_* error code. */ 77 int ne_getmodtime(ne_session *sess, const char *path, time_t *modtime); 78 79 typedef struct { 80 const char *type, *subtype; 81 const char *charset; 82 char *value; 83 } ne_content_type; 84 85 /* Retrieve the content-type of the response; returns zero if response 86 * had valid content-type, in which case all fields in *ctype are set 87 * (and never NULL); the caller must free(ctype->value) after use. 88 * Returns non-zero on error, in which case *ctype is not altered. */ 89 int ne_get_content_type(ne_request *req, ne_content_type *ctype); 90 91 /* DEPRECATED: Server capabilities. */ 92 typedef struct { 93 unsigned int dav_class1; /* True if Class 1 WebDAV server */ 94 unsigned int dav_class2; /* True if Class 2 WebDAV server */ 95 unsigned int dav_executable; /* True if supports the 'executable' 96 * property a. la. mod_dav */ 97 } ne_server_capabilities; 98 99 /* DEPRECATED: Determines server capabilities (using OPTIONS). */ 100 int ne_options(ne_session *sess, const char *path, 101 ne_server_capabilities *caps); 102 103 #define NE_CAP_DAV_CLASS1 (0x0001) /* Class 1 WebDAV (RFC 2518) */ 104 #define NE_CAP_DAV_CLASS2 (0x0002) /* Class 2 WebDAV (RFC 2518) */ 105 #define NE_CAP_DAV_CLASS3 (0x0004) /* Class 3 WebDAV (RFC 4918) */ 106 #define NE_CAP_MODDAV_EXEC (0x0008) /* mod_dav "executable" property */ 107 #define NE_CAP_DAV_ACL (0x0010) /* WebDAV ACL (RFC 3744) */ 108 #define NE_CAP_VER_CONTROL (0x0020) /* DeltaV version-control */ 109 #define NE_CAP_CO_IN_PLACE (0x0040) /* DeltaV checkout-in-place */ 110 #define NE_CAP_VER_HISTORY (0x0080) /* DeltaV version-history */ 111 #define NE_CAP_WORKSPACE (0x0100) /* DeltaV workspace */ 112 #define NE_CAP_UPDATE (0x0200) /* DeltaV update */ 113 #define NE_CAP_LABEL (0x0400) /* DeltaV label */ 114 #define NE_CAP_WORK_RESOURCE (0x0800) /* DeltaV working-resouce */ 115 #define NE_CAP_MERGE (0x1000) /* DeltaV merge */ 116 #define NE_CAP_BASELINE (0x2000) /* DeltaV baseline */ 117 #define NE_CAP_ACTIVITY (0x4000) /* DeltaV activity */ 118 #define NE_CAP_VC_COLLECTION (0x8000) /* DeltaV version-controlled-collection */ 119 120 /* Determines resource capailities, using an OPTIONS request. On 121 * return, *caps is set to a bit-mask of the above NE_CAP_* constants 122 * describing the advertised resource capabilities. */ 123 int ne_options2(ne_session *sess, const char *path, unsigned int *caps); 124 125 /* Defines a range of bytes, starting at 'start' and ending 126 * at 'end'. 'total' is the number of bytes in the range. 127 */ 128 typedef struct { 129 ne_off_t start, end, total; 130 } ne_content_range; 131 132 /* Partial GET. range->start must be >= 0. range->total is ignored. 133 * 134 * If range->end is -1, then the rest of the resource from start is 135 * requested, and range->total and end are filled in on success. 136 * 137 * Otherwise, bytes from range->start to range->end are requested. 138 * 139 * This will write to the CURRENT position of f; so if you want 140 * to do a resume download, use: 141 * struct ne_content_range range; 142 * range.start = resume_from; 143 * range.end = range.start + 999; (= 1000 bytes) 144 * fseek(myfile, resume_from, SEEK_SET); 145 * ne_get_range(sess, path, &range, myfile); */ 146 int ne_get_range(ne_session *sess, const char *path, 147 ne_content_range *range, int fd); 148 149 /* Post using buffer as request-body: stream response into f */ 150 int ne_post(ne_session *sess, const char *path, int fd, const char *buffer); 151 152 NE_END_DECLS 153 154 #endif /* NE_BASIC_H */ 155