From 9e1b1f976e7b02ca91b9296c1c2802f7b8b56b3e Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Mon, 28 Dec 1998 04:24:33 +0000 Subject: [PATCH] add explicit file-based entry point git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1491 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Session.c | 51 ++++++++++++++++++++++++++++++++++---------- src/engine/Session.h | 15 ++++++++----- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/src/engine/Session.c b/src/engine/Session.c index 33dd2f24c4..9fb88da15f 100644 --- a/src/engine/Session.c +++ b/src/engine/Session.c @@ -132,32 +132,60 @@ static char * searchpaths[] = { AccountGroup * xaccSessionBegin (Session *sess, char * sid) { - struct stat statbuf; - char pathbuf[PATH_MAX]; - char * filefrag, *path = NULL; - int namelen, len; - int i, rc; + AccountGroup *retval; if (!sess) return NULL; /* clear the error condition of previous errors */ sess->errtype = 0; + /* check to see if this session is already open */ + if (sess->sessionid) { + sess->errtype = ETXTBSY; + return NULL; + } + /* seriously invalid */ if (!sid) { sess->errtype = EINVAL; return NULL; } + /* check to see if this is a type we know how to handle */ + if (strncmp (sid, "file:", 5)) { + sess->errtype = ENOSYS; + return NULL; + } + + /* add 5 to space past 'file:' */ + retval = xaccSessionBeginFile (sess, sid+5); + + return retval; +} + +AccountGroup * +xaccSessionBeginFile (Session *sess, char * filefrag) +{ + struct stat statbuf; + char pathbuf[PATH_MAX]; + char *path = NULL; + int namelen, len; + int i, rc; + + if (!sess) return NULL; + + /* clear the error condition of previous errors */ + sess->errtype = 0; + /* check to see if this session is already open */ if (sess->sessionid) { sess->errtype = ETXTBSY; return NULL; } - /* check to see if this is a type we know how to handle */ - if (strncmp (sid, "file:", 5)) { - sess->errtype = ENOSYS; + /* seriously invalid */ + if (!filefrag) { + sess->errtype = EINVAL; return NULL; } @@ -165,7 +193,6 @@ xaccSessionBegin (Session *sess, char * sid) /* OK, now we try to find or build an absolute file path */ /* check for an absolute file path */ - filefrag = sess->sessionid + 5; /* space past 'file:' */ if ('/' == *filefrag) { sess->fullpath = strdup (filefrag); } else { @@ -256,8 +283,10 @@ xaccSessionBegin (Session *sess, char * sid) } assert (sess->fullpath); /* no one fucked with the code, yeah? */ - /* OK, we've got a good string ... */ - sess->sessionid = strdup (sid); + /* Store the sessionid URL also ... */ + strcpy (pathbuf, "file:"); + strcat (pathbuf, filefrag); + sess->sessionid = strdup (pathbuf); /* ---------------------------------------------------- */ /* Yow! OK, after all of that, we've finnaly got a fully diff --git a/src/engine/Session.h b/src/engine/Session.h index fc73882a72..e94fd98294 100644 --- a/src/engine/Session.h +++ b/src/engine/Session.h @@ -66,6 +66,10 @@ void xaccSessionDestroy (Session *); * If the file is succesfully opened and read, then a lock will have been * obtained, and all other access to the file will be denied. This feature * is intended to be a brute-force global lock to avoid multiple writers. + * + * The xaccSessionBeginFile() routine is identical to the xaccSessionBegin() + * routine, except that the argument is a filename (i.e. the five + * letters "file:" should not be prepended). * * The xaccSessionGetError() routine can be used to obtain the reason for * any failure. Standard errno values are used. Calling this routine resets @@ -131,13 +135,14 @@ void xaccSessionDestroy (Session *); * */ -AccountGroup * xaccSessionBegin (Session *, char * sessionid); -int xaccSessionGetError (Session *); -AccountGroup * xaccSessionGetGroup (Session *); -void xaccSessionSetGroup (Session *, AccountGroup *topgroup); +AccountGroup * xaccSessionBegin (Session *, char * sessionid); +AccountGroup * xaccSessionBeginFile (Session *, char * filename); +int xaccSessionGetError (Session *); +AccountGroup * xaccSessionGetGroup (Session *); +void xaccSessionSetGroup (Session *, AccountGroup *topgroup); void xaccSessionSave (Session *); -void xaccSessionEnd (Session *); +void xaccSessionEnd (Session *); #endif /* __XACC_SESSION_H__ */