mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-09-03 20:53:02 -05:00
quick, crude prototype network i/o
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3411 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
+7
-7
@@ -1,7 +1,5 @@
|
||||
/********************************************************************\
|
||||
* FileIO.c -- read and write binary format file for gnucash *
|
||||
* (GnuCash/X-Accountant) *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* FileIO.c -- read and write file wrappers (old and new format) *
|
||||
* Copyright (C) 1997-2000 Linas Vepstas <linas@linas.org> *
|
||||
* Copyright (C) 1999-2000 Rob Browning *
|
||||
* *
|
||||
@@ -24,17 +22,18 @@
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#include "FileIO.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DateUtils.h"
|
||||
#include "FileIO.h"
|
||||
#include "io-gncxml.h"
|
||||
#include "io-gncbin.h"
|
||||
#include "DateUtils.h"
|
||||
|
||||
AccountGroup *
|
||||
xaccReadAccountGroupFile(const gchar *name, GNCFileIOError *error_result) {
|
||||
xaccReadAccountGroupFile(const gchar *name, GNCFileIOError *error_result)
|
||||
{
|
||||
AccountGroup *result_grp;
|
||||
|
||||
if(is_gncxml_file(name)) {
|
||||
@@ -66,7 +65,8 @@ gboolean
|
||||
xaccWriteAccountGroupFile(const char *datafile,
|
||||
AccountGroup *grp,
|
||||
gboolean make_backup,
|
||||
GNCFileIOError *error_result) {
|
||||
GNCFileIOError *error_result)
|
||||
{
|
||||
|
||||
if(!datafile) {
|
||||
if(error_result) *error_result = ERR_FILEIO_MISC;
|
||||
|
||||
@@ -12,6 +12,7 @@ libgncengine_la_SOURCES = \
|
||||
DateUtils.c \
|
||||
FileIO.c \
|
||||
Group.c \
|
||||
NetIO.c \
|
||||
Query.c \
|
||||
Scrub.c \
|
||||
Transaction.c \
|
||||
@@ -45,6 +46,7 @@ noinst_HEADERS = \
|
||||
GNCIdP.h \
|
||||
Group.h \
|
||||
GroupP.h \
|
||||
NetIO.h \
|
||||
Query.h \
|
||||
Scrub.h \
|
||||
TransLog.h \
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/********************************************************************\
|
||||
* NetIO.c -- read and write network IO *
|
||||
* Copyright (C) 2001 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* ultra super reudimentary right now
|
||||
* this will be very very different in fianl verisn
|
||||
*/
|
||||
|
||||
|
||||
#include <ghttp.h>
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "NetIO.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "io-gncxml.h"
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
/* ==================================================================== */
|
||||
|
||||
AccountGroup *
|
||||
xaccRecvAccountGroup (char *url)
|
||||
{
|
||||
AccountGroup *grp;
|
||||
ghttp_request *request;
|
||||
char *bufp;
|
||||
int len;
|
||||
|
||||
ENTER ("url is %s\n", url);
|
||||
request = ghttp_request_new();
|
||||
ghttp_set_uri (request, url);
|
||||
ghttp_set_type (request, ghttp_type_get);
|
||||
ghttp_set_header (request, http_hdr_Connection, "close");
|
||||
ghttp_set_sync (request, ghttp_sync);
|
||||
ghttp_clean (request);
|
||||
ghttp_prepare (request);
|
||||
ghttp_process (request);
|
||||
|
||||
len = ghttp_get_body_len(request);
|
||||
|
||||
if (0 < len)
|
||||
{
|
||||
bufp = ghttp_get_body(request);
|
||||
PINFO ("reply length=%d\n", len);
|
||||
DEBUG ("%s\n", bufp);
|
||||
grp = gncxml_read_from_buf (bufp, len);
|
||||
return grp;
|
||||
}
|
||||
else
|
||||
{
|
||||
char * errstr = ghttp_get_error (request);
|
||||
char * reason = ghttp_reason_phrase (request);
|
||||
PERR ("connection failed: %s %s\n", errstr, reason);
|
||||
|
||||
ghttp_request_destroy(request);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ghttp_request_destroy(request);
|
||||
|
||||
LEAVE("\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ============================== END OF FILE ======================== */
|
||||
@@ -0,0 +1,32 @@
|
||||
/********************************************************************\
|
||||
* NetIO.h -- read and write network IO *
|
||||
* Copyright (C) 2001 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
#ifndef __XACC_NET_IO_H__
|
||||
#define __XACC_NET_IO_H__
|
||||
|
||||
#include "Group.h"
|
||||
|
||||
AccountGroup * xaccRecvAccountGroup (char *url);
|
||||
|
||||
#endif /* __XACC_NET_IO_H__ */
|
||||
+113
-95
@@ -45,6 +45,7 @@
|
||||
#include "BackendP.h"
|
||||
#include "FileIO.h"
|
||||
#include "Group.h"
|
||||
#include "NetIO.h"
|
||||
#include "Scrub.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-engine-util.h"
|
||||
@@ -175,66 +176,6 @@ gnc_book_get_file_path (GNCBook *book)
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
gboolean
|
||||
gnc_book_begin (GNCBook *book, const char * book_id, gboolean ignore_lock)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!book) return FALSE;
|
||||
ENTER (" book-id=%s\n", book_id);
|
||||
|
||||
/* clear the error condition of previous errors */
|
||||
book->errtype = 0;
|
||||
book->last_file_err = ERR_FILEIO_NONE;
|
||||
|
||||
/* check to see if this session is already open */
|
||||
if (book->book_id)
|
||||
{
|
||||
book->errtype = ETXTBSY;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* seriously invalid */
|
||||
if (!book_id)
|
||||
{
|
||||
book->errtype = EINVAL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* check to see if this is a type we know how to handle */
|
||||
if (!strncmp(book_id, "file:", 5))
|
||||
{
|
||||
/* add 5 to space past 'file:' */
|
||||
rc = gnc_book_begin_file (book, book_id + 5, ignore_lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!strncmp(book_id, "http://", 7))
|
||||
{
|
||||
book->errtype = ENOSYS;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!strncmp(book_id, "https://", 8))
|
||||
{
|
||||
book->errtype = ENOSYS;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!strncmp(book_id, "postgres://", 11))
|
||||
{
|
||||
book->errtype = ENOSYS;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* otherwise, lets just assume its a file. */
|
||||
rc = gnc_book_begin_file (book, book_id, ignore_lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
#if 0
|
||||
static AccountGroup *
|
||||
xaccSessionBeginSQL (Session *sess, const char * dbname)
|
||||
@@ -340,33 +281,13 @@ gnc_book_get_file_lock (GNCBook *book)
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
gboolean
|
||||
static gboolean
|
||||
gnc_book_begin_file (GNCBook *book, const char * filefrag,
|
||||
gboolean ignore_lock)
|
||||
{
|
||||
if (!book) return FALSE;
|
||||
ENTER ("filefrag=%s\n", filefrag);
|
||||
|
||||
/* clear the error condition of previous errors */
|
||||
book->errtype = 0;
|
||||
book->last_file_err = ERR_FILEIO_NONE;
|
||||
|
||||
/* check to see if this session is already open */
|
||||
if (book->book_id)
|
||||
{
|
||||
book->errtype = ETXTBSY;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* seriously invalid */
|
||||
if (!filefrag)
|
||||
{
|
||||
book->errtype = EINVAL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------- */
|
||||
/* OK, now we try to find or build an absolute file path */
|
||||
/* Try to find or build an absolute file path */
|
||||
|
||||
book->fullpath = xaccResolveFilePath (filefrag);
|
||||
if (!book->fullpath)
|
||||
@@ -397,12 +318,82 @@ gnc_book_begin_file (GNCBook *book, const char * filefrag,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef SQLHACK
|
||||
/* for testing the sql, just a hack, remove later ... */
|
||||
/* this should never ever appear here ... */
|
||||
xaccSessionBeginSQL (sess, "postgres://localhost/gnc_bogus");
|
||||
#endif
|
||||
/* ============================================================== */
|
||||
/* URL mostly a noop --- maybe this would be a login dialog ??? */
|
||||
|
||||
static gboolean
|
||||
gnc_book_begin_http (GNCBook *book, const char * pathfrag)
|
||||
{
|
||||
ENTER ("pathfrag=%s\n", pathfrag);
|
||||
|
||||
/* Store the sessionid URL */
|
||||
book->book_id = g_strdup (pathfrag);
|
||||
|
||||
LEAVE ("\n");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
gboolean
|
||||
gnc_book_begin (GNCBook *book, const char * book_id, gboolean ignore_lock)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (!book) return FALSE;
|
||||
ENTER (" book-id=%s\n", book_id);
|
||||
|
||||
/* clear the error condition of previous errors */
|
||||
book->errtype = 0;
|
||||
book->last_file_err = ERR_FILEIO_NONE;
|
||||
|
||||
/* check to see if this session is already open */
|
||||
if (book->book_id)
|
||||
{
|
||||
book->errtype = ETXTBSY;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* seriously invalid */
|
||||
if (!book_id)
|
||||
{
|
||||
book->errtype = EINVAL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* check to see if this is a type we know how to handle */
|
||||
if (!strncmp(book_id, "file:", 5))
|
||||
{
|
||||
/* add 5 to space past 'file:' */
|
||||
rc = gnc_book_begin_file (book, book_id + 5, ignore_lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!strncmp(book_id, "http://", 7))
|
||||
{
|
||||
rc = gnc_book_begin_http (book, book_id);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!strncmp(book_id, "https://", 8))
|
||||
{
|
||||
rc = gnc_book_begin_http (book, book_id);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!strncmp(book_id, "postgres://", 11))
|
||||
{
|
||||
|
||||
book->errtype = ENOSYS;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* otherwise, lets just assume its a file. */
|
||||
rc = gnc_book_begin_file (book, book_id, ignore_lock);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
gboolean
|
||||
@@ -412,6 +403,7 @@ gnc_book_load (GNCBook *book)
|
||||
if (!book->book_id) return FALSE;
|
||||
|
||||
ENTER ("book_id=%s\n", book->book_id);
|
||||
|
||||
if (strncmp(book->book_id, "file:", 5) == 0)
|
||||
{
|
||||
/* file: */
|
||||
@@ -422,8 +414,8 @@ gnc_book_load (GNCBook *book)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* At this point, we should have a valid book id and a lock on
|
||||
* the file. */
|
||||
/* At this point, we should are supposed to have a valid book
|
||||
* id and a lock on the file. */
|
||||
|
||||
xaccFreeAccountGroup (book->topgroup);
|
||||
book->topgroup = NULL;
|
||||
@@ -444,6 +436,34 @@ gnc_book_load (GNCBook *book)
|
||||
LEAVE("\n");
|
||||
return TRUE;
|
||||
}
|
||||
else if (strncmp(book->book_id, "http://", 7) == 0)
|
||||
{
|
||||
xaccFreeAccountGroup (book->topgroup);
|
||||
book->topgroup = NULL;
|
||||
|
||||
book->errtype = 0;
|
||||
book->last_file_err = ERR_FILEIO_NONE;
|
||||
book->topgroup = xaccRecvAccountGroup (book->book_id);
|
||||
|
||||
if (!book->topgroup || (book->last_file_err != ERR_FILEIO_NONE))
|
||||
{
|
||||
book->errtype = EIO;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LEAVE("\n");
|
||||
return TRUE;
|
||||
}
|
||||
else if (strncmp(book->book_id, "postgres://", 11) == 0)
|
||||
{
|
||||
#ifdef SQLHACK
|
||||
/* for testing the sql, just a hack, remove later ... */
|
||||
/* this should never ever appear here ... */
|
||||
xaccSessionBeginSQL (sess, book->book_id);
|
||||
#endif
|
||||
book->errtype = ENOSYS;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
book->errtype = ENOSYS;
|
||||
@@ -466,12 +486,6 @@ gnc_book_save_may_clobber_data (GNCBook *book)
|
||||
if (stat(book->fullpath, &statbuf) == 0) return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
||||
#ifdef SQLHACK
|
||||
/* for testing the sql, just a hack, remove later ... */
|
||||
/* this should never ever appear here ... */
|
||||
xaccSessionBeginSQL (sess, "postgres://localhost/gnc_bogus");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
@@ -729,7 +743,11 @@ xaccResolveURL (const char * pathfrag)
|
||||
|
||||
/* At this stage of checking, URL's are always, by definition,
|
||||
* resolved. If there's an error connecting, we'll find out later.
|
||||
*
|
||||
* FIXME -- we should probably use ghttp_uri_validate
|
||||
* to make sure hte uri is in good form...
|
||||
*/
|
||||
|
||||
if (!strncmp (pathfrag, "http://", 7)) {
|
||||
return (char *) pathfrag;
|
||||
}
|
||||
|
||||
+6
-11
@@ -76,6 +76,10 @@ void gnc_book_destroy (GNCBook *book);
|
||||
* "file:somefile.xac"
|
||||
* then a sequence of search paths are checked for a file of this name.
|
||||
*
|
||||
* The 'ignore_lock' argument, if set to TRUE, will cause this routine
|
||||
* to ignore any file locks that it finds. If set to FALSE, then
|
||||
* file locks will be tested and obeyed.
|
||||
*
|
||||
* If the file exists, can be opened and read, and a lock can be obtained
|
||||
* then a lock will be obtained and the function returns TRUE. Otherwise
|
||||
* the function returns FALSE.
|
||||
@@ -83,16 +87,6 @@ void gnc_book_destroy (GNCBook *book);
|
||||
gboolean gnc_book_begin (GNCBook *book, const char * book_id,
|
||||
gboolean ignore_lock);
|
||||
|
||||
/* The gnc_book_begin_file() routine is identical to the gnc_book_begin()
|
||||
* routine, except that the argument is assumed to be a filename, not
|
||||
* a URL.
|
||||
*
|
||||
* The 'ignore_lock' argument, if set to TRUE, will cause this routine
|
||||
* to ignore any file locks that it finds. If set to FALSE, then
|
||||
* file locks will be tested and obeyed.
|
||||
*/
|
||||
gboolean gnc_book_begin_file (GNCBook *book, const char * filename,
|
||||
gboolean ignore_lock);
|
||||
|
||||
/* The gnc_book_load() method loads the data associated with the book.
|
||||
* The function returns TRUE on success.
|
||||
@@ -108,7 +102,8 @@ gboolean gnc_book_load (GNCBook *book);
|
||||
*
|
||||
* Some important error values:
|
||||
* EINVAL -- bad argument
|
||||
* ETXTBSY -- book id is in use; it's locked by someone else.
|
||||
* ETXTBSY -- ???
|
||||
* EBUSY -- book id is in use; it's locked by someone else.
|
||||
* ENOSYS -- unsupported URI type.
|
||||
* ERANGE -- file path too long
|
||||
* ENOLCK -- book not open when gnc_book_save() was called.
|
||||
|
||||
@@ -481,7 +481,7 @@ sixtp_sax_end_handler(void *user_data, const xmlChar *name) {
|
||||
because this string is held by the parent parser's hash table. */
|
||||
end_tag = current_frame->tag;
|
||||
|
||||
PINFO("Finished with end of <%s>\n", end_tag);
|
||||
PINFO("Finished with end of <%s>", end_tag);
|
||||
|
||||
/*sixtp_print_frame_stack(pdata->stack, stderr);*/
|
||||
|
||||
@@ -542,15 +542,15 @@ sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) {
|
||||
gpointer lookup_key;
|
||||
gpointer lookup_value;
|
||||
|
||||
PINFO ("Killing sixtp child under key <%s>\n", (char *) key);
|
||||
PINFO ("Killing sixtp child under key <%s>", (char *) key);
|
||||
g_free(key);
|
||||
|
||||
if(!corpses) {
|
||||
PERR("BAD: no corpses in sixtp_destroy_child <%s>\n", (char *) key);
|
||||
PERR("no corpses in sixtp_destroy_child <%s>\n", (char *) key);
|
||||
return;
|
||||
}
|
||||
if(!child) {
|
||||
PERR("BAD: no child in sixtp_destroy_child <%s>\n", (char *) key);
|
||||
PERR("no child in sixtp_destroy_child <%s>\n", (char *) key);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,33 @@
|
||||
* e.g. even some simple #define macros might help here ...
|
||||
*
|
||||
* HISTORY:
|
||||
* Initial code by Rob l. Browning 4Q 2000
|
||||
* Initial code by Rob L. Browning 4Q 2000
|
||||
* Tuneups by James Lewis Moss Dec 2000
|
||||
* Generic I/O hack by Linas Vepstas January 2001
|
||||
*
|
||||
* Copyright (c) 2000,2001 Gnumatic Incorporated
|
||||
*/
|
||||
|
||||
/********************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program 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 General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
Reference in New Issue
Block a user