[Gnucash-changes] More HBCI work.
Christian Stimming
cstim at cvs.gnucash.org
Sat Oct 2 12:35:34 EDT 2004
Log Message:
-----------
More HBCI work.
Modified Files:
--------------
gnucash/src/import-export/hbci:
hbci-interaction.c
hbci-interaction.h
hbci-interactionP.h
Revision Data
-------------
Index: hbci-interaction.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/hbci-interaction.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -Lsrc/import-export/hbci/hbci-interaction.h -Lsrc/import-export/hbci/hbci-interaction.h -u -r1.11 -r1.12
--- src/import-export/hbci/hbci-interaction.h
+++ src/import-export/hbci/hbci-interaction.h
@@ -38,6 +38,7 @@
void GNCInteractor_delete(GNCInteractor *i);
void GNCInteractor_erasePIN(GNCInteractor *i);
void GNCInteractor_reparent (GNCInteractor *i, GtkWidget *new_parent);
+gboolean GNCInteractor_get_cache_valid(const GNCInteractor *i);
void GNCInteractor_set_cache_valid(GNCInteractor *i, gboolean value);
GtkWidget *GNCInteractor_parent(GNCInteractor *i);
void GNCInteractor_add_log_text (GNCInteractor *i, const char *msg);
Index: hbci-interactionP.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/hbci-interactionP.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lsrc/import-export/hbci/hbci-interactionP.h -Lsrc/import-export/hbci/hbci-interactionP.h -u -r1.10 -r1.11
--- src/import-export/hbci/hbci-interactionP.h
+++ src/import-export/hbci/hbci-interactionP.h
@@ -70,11 +70,6 @@
/* Flag on Whether the PIN should be cached. */
gboolean cache_pin;
- /* The cached PIN and the HBCI_User it's cached for. */
- char *pw;
- char *cache_text;
- /* Whether this PIN is really valid or not. */
- gboolean cache_valid;
/* Dialogs */
int showbox_id;
Index: hbci-interaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/hbci-interaction.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -Lsrc/import-export/hbci/hbci-interaction.c -Lsrc/import-export/hbci/hbci-interaction.c -u -r1.47 -r1.48
--- src/import-export/hbci/hbci-interaction.c
+++ src/import-export/hbci/hbci-interaction.c
@@ -57,7 +57,6 @@
data->gnc_iconv_handler = iconv_open("ISO8859-1", "UTF-8");
g_assert(data->gnc_iconv_handler != (iconv_t)(-1));
data->keepAlive = TRUE;
- data->cache_valid = FALSE;
data->cache_pin =
gnc_lookup_boolean_option(PREF_TAB_ONLINE_BANKING,
"HBCI Remember PIN in memory",
@@ -147,6 +146,7 @@
/* Make sure the cache_pin option is up to date. */
if (cache_pin != i->cache_pin) {
+ /* AB_Banking_SetEnablePinCaching (ab, cache_pin); */
i->cache_pin = cache_pin;
if (cache_pin == FALSE)
GNCInteractor_erasePIN (i);
@@ -172,20 +172,21 @@
(GTK_TOGGLE_BUTTON (i->close_checkbutton)));
}
+gboolean GNCInteractor_get_cache_valid(const GNCInteractor *i)
+{
+ g_assert(i);
+ return i->cache_pin;
+}
void GNCInteractor_set_cache_valid(GNCInteractor *i, gboolean value)
{
g_assert(i);
- i->cache_valid = value;
+ /* Nothing to be done right now. */
}
void GNCInteractor_erasePIN(GNCInteractor *i)
{
g_assert(i);
- if (i->pw != NULL)
- g_free (memset (i->pw, 0, strlen (i->pw)));
- i->pw = NULL;
- i->cache_valid = FALSE;
- /* i->user = NULL; */
+ /* Nothing to be done right now. */
}
void GNCInteractor_reparent (GNCInteractor *i, GtkWidget *new_parent)
{
@@ -323,21 +324,12 @@
&passwd);
}
else {
- if (data->cache_valid && text && data->cache_text &&
- (strcmp(text, data->cache_text)==0)) {
- /* Cached user matches, so use cached PIN. */
- /*printf("Got the cached PIN for user %s.\n", HBCI_User_userId (user));*/
- strcpy(resultbuffer, data->pw);
- return 0;
- }
- else {
- retval = gnc_hbci_get_password (data->parent,
- title,
- text,
- NULL,
- &passwd,
- hideInput);
- } /* user == data->user */
+ retval = gnc_hbci_get_password (data->parent,
+ title,
+ text,
+ NULL,
+ &passwd,
+ hideInput);
} /* newPin */
if (!retval)
@@ -359,17 +351,74 @@
else {
g_assert (maxLen > strlen(resultbuffer));
strcpy(resultbuffer, passwd);
- /* Watch out: If we only compare the user string, then don't
- cache this if a TAN is asked for. */
- if (text && data->cache_pin && !(strstr(text, "TAN"))) {
- /*printf("Cached the PIN for user %s.\n", HBCI_User_userId (user));*/
- data->cache_text= g_strdup(text);
- if (data->pw)
- g_free (memset (data->pw, 0, strlen (data->pw)));
- data->pw = passwd;
- }
- else
- g_free (memset (passwd, 0, strlen (passwd)));
+ g_free (memset (passwd, 0, strlen (passwd)));
+ g_free(title);
+ g_free(text);
+ return 0;
+ }
+ }
+
+ /* User wanted to abort. */
+ g_free(title);
+ g_free(text);
+ return 1;
+}
+
+/* ****************************************
+ */
+
+
+static int getTanCB(AB_BANKING *ab,
+ const char *token,
+ const char *utf8title,
+ const char *utf8text,
+ char *resultbuffer,
+ int minsize,
+ int maxLen)
+{
+ GNCInteractor *data;
+ char *passwd = NULL;
+ int retval = 0;
+ gchar *title, *text;
+
+ g_assert(ab);
+ data = AB_Banking_GetUserData(ab);
+ g_assert(data);
+ g_assert(maxLen > minsize);
+
+ text = gnc_hbci_utf8ToLatin1(data, utf8text);
+ title = gnc_hbci_utf8ToLatin1(data, utf8title);
+
+ while (TRUE) {
+
+ retval = gnc_hbci_get_password (data->parent,
+ title,
+ text,
+ NULL,
+ &passwd,
+ FALSE);
+
+ if (!retval)
+ break;
+
+ if (strlen(passwd) < (unsigned int)minsize) {
+ gboolean retval;
+ char *msg =
+ g_strdup_printf ( _("This TAN needs to be at least %d characters \n"
+ "long. Do you want to try again?"),
+ minsize);
+ retval = gnc_verify_dialog (GTK_WIDGET (data->parent),
+ TRUE,
+ msg);
+ g_free (msg);
+ if (!retval)
+ break;
+ }
+ else {
+ g_assert (maxLen > strlen(resultbuffer));
+ strcpy(resultbuffer, passwd);
+
+ g_free (memset (passwd, 0, strlen (passwd)));
g_free(title);
g_free(text);
return 0;
@@ -382,6 +431,10 @@
return 1;
}
+
+/* ************************************************************
+ */
+
static int keepAlive(void *user_data)
{
GNCInteractor *data = user_data;
@@ -401,14 +454,10 @@
if (data == NULL)
return;
- if (data->pw) {
- memset (data->pw, 0, strlen(data->pw));
- g_free (data->pw);
- data->pw = NULL;
- }
GNCInteractor_delete (data);
}
+
/* ************************************************************
*/
@@ -516,6 +565,7 @@
return result+1;
}
+
/* ************************************************************
*/
@@ -727,6 +777,9 @@
AB_Banking_SetProgressLogFn(ab, progressLogCB);
AB_Banking_SetProgressEndFn(ab, progressEndCB);
+ /* AB_Banking_SetGetPinFn(ab,); */
+ AB_Banking_SetGetTanFn(ab, getTanCB);
+
AB_Banking_SetUserData(ab, data);
}
More information about the gnucash-changes
mailing list