Back to index

avfs  1.0.1
http_basic.h
Go to the documentation of this file.
00001 /* 
00002    HTTP/1.1 methods
00003    Copyright (C) 1999-2001, Joe Orton <joe@light.plus.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018    MA 02111-1307, USA
00019 
00020 */
00021 
00022 #ifndef HTTP_BASIC_H
00023 #define HTTP_BASIC_H
00024 
00025 #include <sys/types.h> /* for time_t */
00026 
00027 #include <stdio.h> /* for FILE * */
00028 
00029 #include "http_request.h"
00030 
00031 BEGIN_NEON_DECLS
00032 
00033 /* PUT resource at uri, reading request body from f */
00034 int http_put(http_session *sess, const char *uri, FILE *f);
00035 
00036 /* PUT resource at uri as above, only if it has not been modified
00037  * since given modtime. If server is HTTP/1.1, uses If-Unmodified-Since
00038  * header; guaranteed failure if resource is modified after 'modtime'.
00039  * If server is HTTP/1.0, HEAD's the resource first to fetch current
00040  * modtime; race condition if resource is modified between HEAD and PUT.
00041  */
00042 int http_put_if_unmodified(http_session *sess,
00043                         const char *uri, FILE *stream, time_t modtime);
00044 
00045 /* GET resource at uri, writing response body into f */
00046 int http_get(http_session *sess, const char *uri, FILE *f);
00047 
00048 /* GET resource at uri, passing response body blocks to 'reader' */
00049 int http_read_file(http_session *sess, const char *uri, 
00050                  http_block_reader reader, void *userdata);
00051 
00052 /* Retrieve modification time of resource at uri, place in *modtime.
00053  * (uses HEAD) */
00054 int http_getmodtime(http_session *sess, const char *uri, time_t *modtime);
00055 
00056 typedef struct {
00057     const char *type, *subtype;
00058     const char *charset;
00059     char *value;
00060 } http_content_type;   
00061 
00062 /* Sets (*http_content_type)userdata appropriately. 
00063  * Caller must free ->value after use */
00064 void http_content_type_handler(void *userdata, const char *value);
00065 
00066 /* Server capabilities: */
00067 typedef struct {
00068     unsigned int broken_expect100:1; /* True if the server is known to
00069                                   * have broken Expect:
00070                                   * 100-continue support; Apache
00071                                   * 1.3.6 and earlier. */
00072 
00073     unsigned int dav_class1; /* True if Class 1 WebDAV server */
00074     unsigned int dav_class2; /* True if Class 2 WebDAV server */
00075     unsigned int dav_executable; /* True if supports the 'executable'
00076                               * property a. la. mod_dav */
00077 } http_server_capabilities;
00078 
00079 /* Determines server capabilities (using OPTIONS). 
00080  * Pass uri="*" to determine proxy server capabilities if using
00081  * a proxy server. */
00082 int http_options(http_session *sess, const char *uri, 
00083                http_server_capabilities *caps);
00084 
00085 typedef struct {
00086     off_t start, end, total;
00087 } http_content_range;
00088 
00089 /* This will write to the CURRENT position of f; so if you want
00090  * to do a resume download, use:
00091  *      struct http_content_range range;
00092  *      range.start = resume_from; 
00093  *      range.end = range.total = 1000;
00094  *      fseek(myfile, resume_from, SEEK_SET);
00095  *      http_get_range(sess, uri, &range, myfile);
00096  */
00097 int http_get_range(http_session *sess, const char *uri, 
00098                  http_content_range *range, FILE *f);
00099 
00100 /* Post using buffer as request-body: stream response into f */
00101 int http_post(http_session *sess, const char *uri, FILE *f, 
00102              const char *buffer);
00103 
00104 END_NEON_DECLS
00105 
00106 #endif