Index: src/webdav.h =================================================================== --- src/webdav.h (revision 0) +++ src/webdav.h (revision 0) @@ -0,0 +1,58 @@ +/* + * Authors: + * Bruno Dilly + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +extern "C" { +#include +#include +#include +#include +#include +} +#include + +/** \brief A class to interface with webdav servers */ +class WebDav { + + +public: + WebDav(void); + bool copy (int fd, char * path, char * url, char * username, char * password); + bool copy (char * url, char * path, int fd, char * username, char * password); + bool mkCol (char * url, char * path, char * username, char * password); + char * getUsername(void); + char * getPassword(void); + void setUserData(char * username, char * password); + +private: + /** \brief Username used to authenticate */ + char * username; + /** \brief Password used to authenticate */ + char * password; + int put (ne_session * sess, char * path, int fd); + int get (ne_session * sess, char * path, int fd); + int sockInit (void); + bool parseUri (char * url, ne_uri * uri); + bool createSession(char * url, ne_session ** sess); + void destroySession(ne_session * sess); +}; + +int authCallback(void *userdata, const char *realm, int attempts, + char *username, char *password); + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : Index: src/webdav.cpp =================================================================== --- src/webdav.cpp (revision 0) +++ src/webdav.cpp (revision 0) @@ -0,0 +1,310 @@ +/* + * Authors: + * Bruno Dilly + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "webdav.h" +#include +#include + + +/** \brief Creates a new WebDav object + + This function creates a new WebDav object, wich make possible + communicate with webdav servers. It initializes the username + and password used to authenticate as NULL. +*/ +WebDav::WebDav(void) { + username = NULL; + password = NULL; + return; +} + +/** \brief Copy a file from a local machine to a remote webdav server + \param fd File descriptor of the file to be saved + \param path Path to save the file in the server. Must include the filename. + \param url The url of the webdav server + \param username Username used to authenticate + \param password Password used to authenticate + \return Return true if the copy succeed, or false if it fails + + This function copies a file from the local machine to a webdav server. + The file will be saved in the path, that must include the filename. + The function initializes the socket library, creates a session, + authenticates the user, if necessary, puts the file in the server, + and destroys the session. +*/ +bool +WebDav::copy (int fd, char * path, char * url, char * username, + char * password) { + ne_session *sess = 0; + if (sockInit()) { + g_warning("Failed to initialize socket libraries.\n"); + return false; + } + if (!createSession(url, &sess)) { + g_warning("Failed to create session.\n"); + return false; + } + setUserData(username, password); + ne_set_server_auth(sess, authCallback, (void*)this); + if (put(sess, path, fd)){ + g_warning("Request failed PUT: %s\n", ne_get_error(sess)); + return false; + } + destroySession(sess); + return true; +} + +/** \brief Save the file found in the path, in the server, to the local machine + \param url The url of the webdav server + \param path The path of the file in the server + \param fd File descriptor of the file in the local machine + \param username Username used to authenticate + \param password Password used to authenticate + \return Return true if the copy succeed, or false if it fails + + This function copies a file from the webdav server to the local machine. + The file in the server will be found in the path, + that must include the filename. + The function initializes the socket library, creates a session, + authenticates the user, if necessary, gets the file from the server, + and destroys the session. +*/ +bool +WebDav::copy (char * url, char * path, int fd, char * username, char * password) { + ne_session * sess = 0; + if (sockInit()) { + g_warning("Failed to initialize socket libraries.\n"); + return false; + } + if (!createSession(url, &sess)) { + g_warning("Failed to create session.\n"); + return false; + } + setUserData(username, password); + ne_set_server_auth(sess, authCallback, (void*)this); + if (get(sess, path, fd)){ + g_warning("Request failed GET: %s\n", ne_get_error(sess)); + return false; + } + destroySession(sess); + return true; +} + +/** \brief Makes a new collection in the webdav server + \param url The url of the webdav server + \param path The collection to be created + \param username Username used to authenticate + \param password Password used to authenticate + \return Return true if the collection is created, or false if it fails + + This function makes a new collection (a.k.a. directory) in the server. + The function initializes the socket library, creates a session, + authenticates the user, if necessary, makes the new collection + in the server, and destroys the session. +*/ +bool +WebDav::mkCol (char * url, char * path, char * username, char * password) { + ne_session * sess = 0; + if (sockInit()) { + g_warning("Failed to initialize socket libraries.\n"); + return false; + } + if (!createSession(url, &sess)) { + g_warning("Failed to create session.\n"); + return false; + } + setUserData(username, password); + ne_set_server_auth(sess, authCallback, (void*)this); + ne_request *req = ne_request_create(sess, "MKCOL", path); + if (ne_request_dispatch(req)){ + g_warning("Request failed MKCOL: %s\n", ne_get_error(sess)); + return false; + } + destroySession(sess); + return true; +} + + +/** \brief Save the file found in the path from the local machine to the server + \param sess Webdav session + \param path Path to save the file in the server. Must include the filename. + \param fd File descriptor of the file to be saved + \return Return zero on success, or non-zero on error + + This function save a file, descripted by fd, in the path in the server + connected by the session. +*/ +int +WebDav::put (ne_session * sess, char * path, int fd) { + return ne_put(sess, path, fd); +} + +/** \brief Save the file found in the path from the server to the local machine + \param sess Webdav session + \param path Path to found the file in the server. Must include the filename. + \param fd File descriptor of the file to be saved + \return Return zero on success, or non-zero on error + + This function save a file, from the path in the server to the + file descripted by the file descriptor, connected by the session. +*/ +int +WebDav::get (ne_session * sess, char * path, int fd) { + return ne_get(sess, path, fd); +} + + + +/** \brief Initialize the socket library + \return Return zero on success, or non-zero on error + + This function initializes the socket library. + In some platforms and configurations, neon may be using + some socket or SSL libraries which require global + initialization before use. To perform this initialization, + the ne_sock_init function must be called once before any + other library functions are used. +*/ +int +WebDav::sockInit(void) { + return ne_sock_init(); +} + +/** \brief Parse URI creating a ne_uri + \param url The URL to be parsed + \param uri The parsed URI + \return Return true if the uri is parsed, or false if it fails + + This function parses an url creating a ne_uri, with path, host, + scheme and port. +*/ +bool +WebDav::parseUri (char * url, ne_uri * uri) { + if (ne_uri_parse(url, uri) || uri->path == NULL || uri->host == NULL) + return false; + if (uri->scheme == NULL) + uri->scheme = "http"; + if (uri->port == 0) + uri->port = ne_uri_defaultport(uri->scheme); + return true; +} + +/** \brief Create a http session + \param url The url of the webdav server + \param sess The webdav session + \return Return true if the session is created successfully or false if it fails + + This function creates a session, so any requests made + using the session can use a persistent connection, share + cached authentication credentials and any other + common attributes. + An ne_session object represents an http session. +*/ +bool +WebDav::createSession(char * url, ne_session ** sess) { + ne_uri uri; + if (!parseUri(url, &uri)) { + g_warning("Invalid URI `%s'.\n", url); + return false; + } + *sess = ne_session_create(uri.scheme, uri.host, uri.port); + return true; +} + +/** \brief Destroy the session + \param The session to be destroyed + + This function destroys the used session. +*/ +void +WebDav::destroySession(ne_session * sess) { + ne_session_destroy(sess); + return; +} + +/** \brief Get the username used to authenticates the user + \return Return the username used to authenticates + + This function gets the username used to authenticates + the user in the server +*/ +char * +WebDav::getUsername(void) { + return username; +} + +/** \brief Get the password used to authenticates the user + \return Return the password used to authenticates + + This function gets the password used to authenticates + the user in the server +*/ +char * +WebDav::getPassword(void) { + return password; +} + +/** \brief Set the userdata used to authenticate + \param username The username to be used to authenticate + \param password The password to be used to authenticate + + This function sets the userdata (username and password) + necessary to authenticate. If any of them are NULL, so an + empty string is attributed to them. +*/ +void +WebDav::setUserData(char * username, char * password) { + if(username != NULL && password != NULL) { + this->username = new char [strlen(username)]; + this->password = new char [strlen(password)]; + strcpy(this->username, username); + strcpy(this->password, password); + } + else { + username = new char [1]; + password = new char [1]; + strcpy(username, ""); + strcpy(password, ""); + } + return; +} + +/** brief + \param userdata Data that could be used to store the username and password + \param realm String supplied by the server + \param attempts A counter giving the number of times the request has been retried with different authentication credentials + \param username Username used to authenticate + \param password Password used to authenticate + \return The value of the attempts parameter. It allow one attempt to authenticate the credentials. + + This function is a a callback which is invoked when + a server or proxy server requires user authentication + for a particular request. +*/ +int +authCallback(void *userdata, const char *realm, int attempts, + char *username, char *password) { + WebDav * webdav = (WebDav *) userdata; + strncpy(username, webdav->getUsername(), NE_ABUFSIZ); + strncpy(password, webdav->getPassword(), NE_ABUFSIZ); + return attempts; +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : Index: src/Makefile_insert =================================================================== --- src/Makefile_insert (revision 15269) +++ src/Makefile_insert (working copy) @@ -266,6 +266,7 @@ vanishing-point.cpp vanishing-point.h \ verbs.cpp verbs.h \ version.cpp version.h \ + webdav.cpp webdav.h \ zoom-context.cpp zoom-context.h # Force libinkpost.a to be rebuilt if we add files to libinkpost_a_SOURCES. Index: configure.ac =================================================================== --- configure.ac (revision 15269) +++ configure.ac (working copy) @@ -280,6 +280,7 @@ fi fi + dnl ****************************** dnl GnomePrint checking dnl ****************************** @@ -557,6 +558,14 @@ [INKSCAPE_LIBS="$INKSCAPE_LIBS -lpopt"], AC_MSG_ERROR([libpopt is required])) +dnl ****************************** +dnl neon checking +dnl ****************************** + +PKG_CHECK_MODULES([NEON], [neon >= 0.25.5 neon <= 0.26.99]) +INKSCAPE_LIBS="$INKSCAPE_LIBS $NEON_LIBS" + + dnl Check for bind_textdomain_codeset, including -lintl if GLib brings it in. sp_save_LIBS=$LIBS LIBS="$LIBS $INKSCAPE_LIBS" Index: inkscape.spec.in =================================================================== --- inkscape.spec.in (revision 15269) +++ inkscape.spec.in (working copy) @@ -39,6 +39,7 @@ BuildRequires: perl-XML-Parser BuildRequires: pkgconfig BuildRequires: python-devel +BuildRequires: neon-devel Requires(post): desktop-file-utils Requires(postun): desktop-file-utils