mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-02 05:29:20 -06:00
add explicit file-based entry point
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1491 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
ceda19dfdb
commit
9e1b1f976e
@ -132,40 +132,67 @@ 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;
|
||||
|
||||
/* seriously invalid */
|
||||
if (!sid) {
|
||||
sess->errtype = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* seriously invalid */
|
||||
if (!filefrag) {
|
||||
sess->errtype = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------- */
|
||||
/* 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
|
||||
|
@ -67,6 +67,10 @@ void xaccSessionDestroy (Session *);
|
||||
* 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
|
||||
* the error value. This routine allows an implementation of multiple
|
||||
@ -132,6 +136,7 @@ void xaccSessionDestroy (Session *);
|
||||
*/
|
||||
|
||||
AccountGroup * xaccSessionBegin (Session *, char * sessionid);
|
||||
AccountGroup * xaccSessionBeginFile (Session *, char * filename);
|
||||
int xaccSessionGetError (Session *);
|
||||
AccountGroup * xaccSessionGetGroup (Session *);
|
||||
void xaccSessionSetGroup (Session *, AccountGroup *topgroup);
|
||||
|
Loading…
Reference in New Issue
Block a user