diff --git a/src/engine/AccInfo.c b/src/engine/AccInfo.c index 83056bf6e1..d9d013b9aa 100644 --- a/src/engine/AccInfo.c +++ b/src/engine/AccInfo.c @@ -1,7 +1,30 @@ +/********************************************************************\ + * AccInfo.c -- the Account Info data structures * + * Copyright (C) 1998, 1999 Linas Vepstas * + * * + * 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, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +\********************************************************************/ + +#include +#include #include "AccInfo.h" +#include "AccInfoP.h" #include "messages.h" -/* whoa! */ + +/* =========================================================== */ char *account_type_name[NUM_ACCOUNT_TYPES] = { @@ -24,10 +47,65 @@ char *account_type_name[NUM_ACCOUNT_TYPES] = */ }; - char * xaccAccountGetTypeStr (int type) { if (0 > type) return ""; if (NUM_ACCOUNT_TYPES <= type) return ""; return (account_type_name [type]); } + +/* =========================================================== */ + +InvAcct * +xaccMallocInvAcct (void) +{ + InvAcct *iacc; + iacc = (InvAcct *) malloc (sizeof (InvAcct)); + xaccInitInvAcct (iacc); + return iacc; +} + +void +xaccInitInvAcct (InvAcct *iacc) +{ + if (!iacc) return; + iacc->pricesrc = NULL; + iacc->brokerid = NULL; + iacc->acctid = NULL; + iacc->accttype = NULL; + iacc->prodtype = NULL; + iacc->secid = NULL; + iacc->secidtype = strdup ("CUSIP"); +} + +void +xaccFreeInvAcct (InvAcct *iacc) +{ + if (!iacc) return; + if (iacc->pricesrc) { free(iacc->pricesrc); iacc->pricesrc = NULL; } + if (iacc->brokerid) { free(iacc->brokerid); iacc->brokerid = NULL; } + if (iacc->acctid) { free(iacc->acctid); iacc->acctid = NULL; } + if (iacc->accttype) { free(iacc->accttype); iacc->accttype = NULL; } + if (iacc->prodtype) { free(iacc->prodtype); iacc->prodtype = NULL; } + if (iacc->secid) { free(iacc->secid); iacc->secid = NULL; } + if (iacc->secidtype) { free(iacc->secidtype); iacc->secidtype = NULL; } +} + +/* =========================================================== */ + +void +xaccInvAcctSetPriceSrc (InvAcct *iacc, const char *src) +{ + if (!iacc || !src) return; + if (iacc->pricesrc) { free(iacc->pricesrc); } + iacc->pricesrc = strdup (src); +} + +char * +xaccInvAcctGetPriceSrc (InvAcct *iacc) +{ + if (!iacc) return NULL; + return (iacc->pricesrc); +} + +/* ==================== END OF FILE ========================== */ diff --git a/src/engine/AccInfo.h b/src/engine/AccInfo.h index 419369b267..4cba4029db 100644 --- a/src/engine/AccInfo.h +++ b/src/engine/AccInfo.h @@ -1,6 +1,6 @@ /********************************************************************\ * AccInfo.h -- the Account Info data structures * - * Copyright (C) 1998 Linas Vepstas * + * Copyright (C) 1998, 1999 Linas Vepstas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -15,11 +15,6 @@ * You should have received a copy of the GNU General Public License* * along with this program; if not, write to the Free Software * * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * * - * Author: Rob Clark * - * Internet: rclark@cs.hmc.edu * - * Address: 609 8th Street * - * Huntington Beach, CA 92648-4632 * \********************************************************************/ /* @@ -99,21 +94,21 @@ enum char * xaccAccountGetTypeStr (int type); -struct _BankAcct -{ - char * bankid; /* routing and transit number */ - char * branchid; /* branch office bank identifier */ - char * acctid; /* account number */ - char * accttype; /* account type */ - char * acctkey; /* checksum key */ - int acctype; /* account type. Must be one of - * CHECKING = 10; - * SAVINGS = 11; - * MONEYMRKT = 12; - * CREDITLINE = 13; - */ +typedef struct _BankAcct BankAcct; +typedef struct _InvAcct InvAcct; +typedef union _AccInfo AccInfo; -}; +InvAcct * xaccMallocInvAcct (void); +void xaccInitInvAcct (InvAcct *iacc); +void xaccFreeInvAcct (InvAcct *iacc); +/* + * The xaccInvAcctSetPriceSrc() and xaccInvAcctGetPriceSrc() + * routines are used to get and set a string that identifies the current + * source for investment pricing info. + * Currently supported values include "yahoo", "fidelity", "troweprice", etc. + */ +void xaccInvAcctSetPriceSrc (InvAcct *iacc, const char *src); +char * xaccInvAcctGetPriceSrc (InvAcct *iacc); #endif /* __ACCINFO_H__ */ diff --git a/src/engine/AccInfoP.h b/src/engine/AccInfoP.h new file mode 100644 index 0000000000..6be076c2ef --- /dev/null +++ b/src/engine/AccInfoP.h @@ -0,0 +1,81 @@ +/********************************************************************\ + * AccInfoP.h -- the Account Info data structures * + * Copyright (C) 1998, 1999 Linas Vepstas * + * * + * 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, write to the Free Software * + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +\********************************************************************/ + +/* + * Most of the structures here more or less resemble + * matching structures in the OFX DTD's. The match + * is not exact. + */ + +#ifndef __XACC_ACCINFO_P_H__ +#define __XACC_ACCINFO_P_H__ + +#include "config.h" +#include "AccInfo.h" + +/* + * Most of the structures here more or less resemble + * matching structures in the OFX DTD's. The match + * is not exact. + */ + +/* The BankAcct structure only applies when the account type is one of + * CHECKING = 10; + * SAVINGS = 11; + * MONEYMRKT = 12; + * CREDITLINE = 13; + */ +struct _BankAcct +{ + char * bankid; /* routing and transit number */ + char * branchid; /* branch office bank identifier */ + char * acctid; /* account number */ + char * accttype; /* account type */ + char * acctkey; /* checksum key */ + +}; + +/* The InvAcct structure only applies when the account type + * is one of + * MUTUAL STOCK + */ +struct _InvAcct +{ + char * pricesrc; /* source for price quotes ... + * one of Yahoo, Fidelity, TRowePrice, etc. + */ + char * brokerid; /* unique identifier for the FI */ + char * acctid; /* account number */ + char * accttype; /* account type (OFX INVACCTYPE) */ + /* possible values: INDIVIDUAL, JOINT + TRUST, CORPORATE */ + char * prodtype; /* account type (OFX USPRODUCTTYPE) */ + /* possible values: 401K 403B IRA KEOGH SARSEP + SIMPLE NORMAL TDA TRUST UGMA */ + char * secid; /* security id (CUSIP) (OFX UNIQUEID) */ + /* (9 digit alphanumeric) */ + char * secidtype; /* "CUSIP" (OFX UNIQUEIDTYPE) */ +}; + +union _AccInfo { + BankAcct bank_acct; + InvAcct inv_acct; +}; + +#endif /* __XACC_ACCINFO_P_H__ */ diff --git a/src/engine/Account.c b/src/engine/Account.c index 497d4ac028..8d48c22258 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -43,7 +43,7 @@ * as it can lead to scrambled data. * hack alert -- this should be a configurable parameter. */ -int unsafe_ops = 0; +int unsafe_ops = 1; int next_free_unique_account_id = 0; diff --git a/src/engine/AccountP.h b/src/engine/AccountP.h index 657f3dd6a4..8406516ad9 100644 --- a/src/engine/AccountP.h +++ b/src/engine/AccountP.h @@ -44,6 +44,7 @@ #define __XACC_ACCOUNT_P_H__ #include "config.h" +#include "AccInfo.h" #include "Transaction.h" /** STRUCTS *********************************************************/ @@ -87,6 +88,13 @@ struct _account { */ short type; + /* The accInfo field provides a hook for storing additional + * account-type specific data. Thus, it will contain different + * structures depending on whether the account is a bank, investment + * or other type of account. Implemented as a union. + */ + AccInfo *accInfo; + /* The currency field denotes the default currency in which all * splits in this account are denominated. It's value *MUST* * be a three-letter ISO currency code, or it must be a comma followed