Back to index

avfs  1.0.1
dav_locks.h
Go to the documentation of this file.
00001 /* 
00002    WebDAV Class 2 locking operations
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 DAV_LOCKS_H
00023 #define DAV_LOCKS_H
00024 
00025 #include "http_request.h" /* for http_session + http_req */
00026 
00027 /* The scope of a lock */
00028 enum dav_lock_scope {
00029     dav_lockscope_exclusive,
00030     dav_lockscope_shared
00031 };
00032 
00033 enum dav_lock_type {
00034     dav_locktype_write
00035 };
00036 
00037 /* Would be typedef'ed to dav_lock except lock is a verb and a noun,
00038  * so we already have dav_lock the function. Damn the English
00039  * language. */
00040 struct dav_lock {
00041     char *uri;
00042     int depth;
00043     enum dav_lock_type type;
00044     enum dav_lock_scope scope;
00045     char *token;
00046     char *owner;
00047     long timeout;
00048     struct dav_lock *next;
00049     struct dav_lock *prev;
00050 };
00051 
00052 #define DAV_TIMEOUT_INFINITE -1
00053 #define DAV_TIMEOUT_INVALID -2
00054 
00055 typedef struct dav_lock_session_s dav_lock_session;
00056 
00057 /* TODO: 
00058  * "session" is a bad word, and it's already used for http_session,
00059  * maybe think up a better name. lock_store is quite good.
00060  */
00061 
00062 /* Register the locking hooks with an http_session.  Owned locks
00063  * persist for the duration of this session. */
00064 dav_lock_session *dav_lock_register(http_session *sess);
00065 
00066 /* Call this after destroying the http_session which this lock session
00067  * was registered with. Or register the lock session with a new
00068  * http_session. Using 'sess' after this function returns will have
00069  * undefined behaviour.  */
00070 void dav_lock_unregister(dav_lock_session *sess);
00071 
00072 /* Add a lock to the given session. The lock will subsequently be
00073  * submitted as required in an If: header with any requests created
00074  * using the http_session which the lock session is tied to.  Requests
00075  * indicate to the locking layer which locks they might need using
00076  * dav_lock_using_*, as described below. */
00077 void dav_lock_add(dav_lock_session *sess, struct dav_lock *lock);
00078 
00079 /* Remove lock, which must have been previously added to the
00080  * session using 'dav_lock_add' above. */
00081 void dav_lock_remove(dav_lock_session *sess, struct dav_lock *lock);
00082 
00083 
00084 typedef void (*dav_lock_walkfunc)(struct dav_lock *lock, void *userdata);
00085 
00086 /* For each lock added to the session, call func, passing the lock
00087  * and the given userdata. Returns the number of locks. func may be
00088  * pass as NULL, in which case, can be used to simply return number
00089  * of locks in the session. */
00090 int dav_lock_iterate(dav_lock_session *sess, 
00091                    dav_lock_walkfunc func, void *userdata);
00092 
00093 /* Issue a LOCK request for the given lock. */
00094 int dav_lock(http_session *sess, struct dav_lock *lock);
00095 /* Issue an UNLOCK request for the given lock */
00096 int dav_unlock(http_session *sess, struct dav_lock *lock);
00097 
00098 /* Find a lock in the session with given URI */
00099 struct dav_lock *dav_lock_find(dav_lock_session *sess, const char *uri);
00100 
00101 /* Deep-copy a lock structure. */
00102 struct dav_lock *dav_lock_copy(const struct dav_lock *lock);
00103 
00104 /* Free a lock structure */
00105 void dav_lock_free(struct dav_lock *lock);
00106 
00107 /* Callback for lock discovery.  If 'lock' is NULL, 
00108  * something went wrong retrieving lockdiscover for the resource,
00109  * look at 'status' for the details. */
00110 typedef void (*dav_lock_result)(void *userdata, const struct dav_lock *lock, 
00111                             const char *uri, const http_status *status);
00112 
00113 /* Perform lock discovery on the given URI.  'result' is called
00114  * with the results (possibly >1 times).  */
00115 int dav_lock_discover(http_session *sess, const char *uri, 
00116                     dav_lock_result result, void *userdata);
00117 
00118 /*** For use by method functions */
00119 
00120 /* Indicate that this request is of depth n on given uri */
00121 void dav_lock_using_resource(http_req *req, const char *uri, int depth);
00122 /* Indicate that this request will modify parent collection of given URI */
00123 void dav_lock_using_parent(http_req *req, const char *uri);
00124 
00125 #endif /* DAV_LOCKS_H */