This commit is contained in:
biosvos
2026-08-07 17:38:18 +09:00
commit 873193a243
9613 changed files with 2755992 additions and 0 deletions
@@ -0,0 +1,142 @@
/*
String utility functions
Copyright (C) 1999-2005, Joe Orton <joe@manyfish.co.uk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
#ifndef NE_STRING_H
#define NE_STRING_H
#include "ne_defs.h"
#include "ne_alloc.h"
#include <stdarg.h>
BEGIN_NEON_DECLS
/* ne_token and ne_qtoken return the next token in *str between *str
* and separator character 'sep' or the NUL terminator. ne_qtoken
* skips over any parts quoted using a pair of any one of the
* characters given in 'quotes'. After returning, *str will point to
* the next character after the separator, or NULL if no more
* separator characters were found.
*
* ne_qtoken may return NULL if unterminated quotes are found. */
char *ne_token(char **str, char sep);
char *ne_qtoken(char **str, char sep, const char *quotes);
/* Return portion of 'str' with any characters in 'whitespace' shaved
* off the beginning and end. Modifies str. */
char *ne_shave(char *str, const char *whitespace);
/* Cleanse 'str' of non-printable characters. 'str' is modified
* in-place, and returned. */
char *ne_strclean(char *str);
/* A base64 encoder: converts 'len' bytes of 'text' to base64.
* Returns malloc-allocated buffer; caller must free(). */
char *ne_base64(const unsigned char *text, size_t len);
/* Base64 decoder; decodes NUL-terminated base64-encoded string
* 'data', places malloc-allocated raw data in '*out', returns length,
* or zero on decode error (in which case *out is undefined). */
size_t ne_unbase64(const char *data, unsigned char **out);
/* String buffer handling. (Strings are zero-terminated still). A
* string buffer ne_buffer * which grows dynamically with the
* string. */
typedef struct {
char *data; /* contents: null-terminated string. */
size_t used; /* used bytes in buffer */
size_t length; /* length of buffer */
} ne_buffer;
/* Returns size of data in buffer, equiv to strlen(ne_buffer_data(buf)) */
#define ne_buffer_size(buf) ((buf)->used - 1)
/* Concatenate all given strings onto the end of the buffer. The
* strings must all be NUL-terminated, and MUST be followed by a NULL
* argument marking the end of the list. */
void ne_buffer_concat(ne_buffer *buf, ...);
/* Create a new ne_buffer. */
ne_buffer *ne_buffer_create(void);
/* Create a new ne_buffer of given minimum size. */
ne_buffer *ne_buffer_ncreate(size_t size);
/* Destroys (deallocates) a buffer */
void ne_buffer_destroy(ne_buffer *buf);
/* Append a NUL-terminated string 'str' to buf. */
void ne_buffer_zappend(ne_buffer *buf, const char *str);
/* Append 'len' bytes of 'data' to buf. 'data' does not need to be
* NUL-terminated. The resultant string will have a NUL-terminator,
* either way. */
void ne_buffer_append(ne_buffer *buf, const char *data, size_t len);
/* Append a literal constant string 'str' to buffer 'buf'. */
#define ne_buffer_czappend(buf, str) \
ne_buffer_append((buf), (str), sizeof((str)) - 1)
/* Empties the contents of buf; makes the buffer zero-length. */
void ne_buffer_clear(ne_buffer *buf);
/* Grows the ne_buffer to a minimum size. */
void ne_buffer_grow(ne_buffer *buf, size_t size);
void ne_buffer_altered(ne_buffer *buf);
/* Destroys a buffer, WITHOUT freeing the data, and returns the
* data. */
char *ne_buffer_finish(ne_buffer *buf);
/* Thread-safe strerror() wrapper; place system error for errno value
* 'errnum' in 'buffer', which is of length 'buflen'. Returns
* 'buffer'. */
char *ne_strerror(int errnum, char *buffer, size_t buflen);
/* ne_strnzcpy copies at most 'n'-1 bytes of 'src' to 'dest', and
* ensures that 'dest' is subsequently NUL-terminated. */
#define ne_strnzcpy(dest, src, n) do { \
strncpy(dest, src, n-1); dest[n-1] = '\0'; } while (0)
/* Return malloc-allocated concatenation of all NUL-terminated string
* arguments, up to a terminating NULL. */
char *ne_concat(const char *str, ...);
#define NE_ASC2HEX(x) (((x) <= '9') ? ((x) - '0') : (tolower((x)) + 10 - 'a'))
#define NE_HEX2ASC(x) ((char) ((x) > 9 ? ((x) - 10 + 'a') : ((x) + '0')))
/* Wrapper for snprintf: always NUL-terminates returned buffer, and
* returns strlen(str). */
size_t ne_snprintf(char *str, size_t size, const char *fmt, ...)
ne_attribute((format(printf, 3, 4)));
/* Wrapper for vsnprintf. */
size_t ne_vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
ne_attribute((format(printf, 3, 0)));
void ne_md5_buffer(const char *buffer, char *digest) ;
void ne_md5_buffer_bin(const char *buffer, char *digest) ;
END_NEON_DECLS
#endif /* NE_STRING_H */
@@ -0,0 +1,166 @@
/*
WebDAV Class 2 locking operations
Copyright (C) 1999-2002, Joe Orton <joe@manyfish.co.uk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
#ifndef NE_LOCKS_H
#define NE_LOCKS_H
#include "ne_request.h" /* for ne_session + ne_request */
#include "ne_uri.h" /* for ne_uri */
BEGIN_NEON_DECLS
/* The scope of a lock */
enum ne_lock_scope {
ne_lockscope_exclusive,
ne_lockscope_shared
};
/* Lock type. Only write locks are defined in RFC2518. */
enum ne_lock_type {
ne_locktype_write
};
/* A lock object. */
struct ne_lock {
ne_uri uri;
int depth; /* the depth of the lock (NE_DEPTH_*). */
enum ne_lock_type type;
enum ne_lock_scope scope;
char *token; /* the lock token: uniquely identifies this lock. */
char *owner; /* string describing the owner of the lock. */
long timeout; /* timeout in seconds. (or NE_TIMEOUT_*) */
};
/* NB: struct ne_lock Would be typedef'ed to ne_lock except lock is
* a verb and a noun, so we already have ne_lock the function. Damn
* the English language. */
#define NE_TIMEOUT_INFINITE -1
#define NE_TIMEOUT_INVALID -2
/* Create a depth zero, exclusive write lock, with default timeout
* (allowing a server to pick a default). token, owner and uri are
* unset. */
struct ne_lock *ne_lock_create(void);
/* HINT: to initialize uri host/port/scheme for the lock's URI, use
* ne_fill_server_uri from ne_session.h. */
/* Deep-copy a lock structure: strdup's any of path, token, owner,
* hostport which are set. */
struct ne_lock *ne_lock_copy(const struct ne_lock *lock);
/* Free a lock structure; free's any of any of the URI, token and
* owner which are set, but not the lock object itself. */
void ne_lock_free(struct ne_lock *lock);
/* Like ne_lock_free; but free's the lock object itself too. */
void ne_lock_destroy(struct ne_lock *lock);
/* ne_lock_store: an opaque type which is used to store a set of lock
* objects. */
typedef struct ne_lock_store_s ne_lock_store;
/* Create a lock store. */
ne_lock_store *ne_lockstore_create(void);
/* Register the lock store 'store' with the HTTP session 'sess': any
* operations made using 'sess' which operate on a locked resource,
* can use the locks from 'store' if needed. */
void ne_lockstore_register(ne_lock_store *store, ne_session *sess);
/* Destroy a lock store, free'ing any locks remaining inside. */
void ne_lockstore_destroy(ne_lock_store *store);
/* Add a lock to the store: the store then "owns" the lock object, and
* you must not free it. The lock MUST have all of:
* - a completed URI structure: scheme, host, port, and path all set
* - a valid lock token
* - a valid depth
*/
void ne_lockstore_add(ne_lock_store *store, struct ne_lock *lock);
/* Remove given lock object from store: 'lock' MUST point to a lock
* object which is known to be in the store. */
void ne_lockstore_remove(ne_lock_store *store, struct ne_lock *lock);
/* Returns the first lock in the lock store, or NULL if the store is
* empty. */
struct ne_lock *ne_lockstore_first(ne_lock_store *store);
/* After ne_lockstore_first has been called; returns the next lock in
* the lock store, or NULL if there are no more locks stored.
* Behaviour is undefined if ne_lockstore_first has not been called on
* 'store' since the store was created, or the last time this function
* returned NULL for the store.. */
struct ne_lock *ne_lockstore_next(ne_lock_store *store);
/* Find a lock in the store for the given server, and with the given
* path. */
struct ne_lock *ne_lockstore_findbyuri(ne_lock_store *store,
const ne_uri *uri);
/* Issue a LOCK request for the given lock. Requires that the uri,
* depth, type, scope, and timeout members of 'lock' are filled in.
* owner and token must be malloc-allocated if not NULL; and may be
* free()d by this function. On successful return, lock->token will
* contain the lock token. */
int ne_lock(ne_session *sess, struct ne_lock *lock);
/* Issue an UNLOCK request for the given lock */
int ne_unlock(ne_session *sess, const struct ne_lock *lock);
/* Refresh a lock. Updates lock->timeout appropriately. */
int ne_lock_refresh(ne_session *sess, struct ne_lock *lock);
/* Callback for lock discovery. If 'lock' is NULL, something went
* wrong performing lockdiscovery for the resource, look at 'status'
* for the details.
*
* If lock is non-NULL, at least lock->uri and lock->token will be
* filled in; and status will be NULL. */
typedef void (*ne_lock_result)(void *userdata, const struct ne_lock *lock,
const char *uri, const ne_status *status);
/* Perform lock discovery on the given path. 'result' is called with
* the results (possibly >1 times). */
int ne_lock_discover(ne_session *sess, const char *path,
ne_lock_result result, void *userdata);
/* The ne_lock_using_* functions should be used before dispatching a
* request which modify resources. If a lock store has been
* registered with the session associated with the request, and locks
* are present in the lock store which cover the resources which are
* being modified by the request, then the appropriate lock tokens are
* submitted in the request headers. */
/* Indicate that request 'req' will modify the resource at 'path', and
* is an operation of given 'depth'. */
void ne_lock_using_resource(ne_request *req, const char *path, int depth);
/* Indicate that request 'req' will modify the parent collection of
* the resource found at 'path' (for instance when removing the
* resource from the collection). */
void ne_lock_using_parent(ne_request *req, const char *path);
END_NEON_DECLS
#endif /* NE_LOCKS_H */