1 /***************************************************************************
2 begin : Mon Mar 01 2004
3 copyright : (C) 2004-2017 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * This file is part of the project "AqBanking". *
8 * Please see toplevel file COPYING of that project for license details. *
9 ***************************************************************************/
10
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14
15 #include "httpsession_p.h"
16
17 #include "aqbanking/i18n_l.h"
18 #include "aqbanking/backendsupport/siotlsext.h"
19
20 #include <gwenhywfar/misc.h>
21 #include <gwenhywfar/debug.h>
22 #include <gwenhywfar/gui.h>
23 #include <gwenhywfar/syncio_tls.h>
24
25 #ifdef OS_WIN32
26 # define DIRSEP "\\"
27 #else
28 # define DIRSEP "/"
29 #endif
30
31
32
GWEN_INHERIT(GWEN_HTTP_SESSION,AB_HTTP_SESSION)33 GWEN_INHERIT(GWEN_HTTP_SESSION, AB_HTTP_SESSION)
34
35
36
37 GWEN_HTTP_SESSION *AB_HttpSession_new(AB_PROVIDER *pro,
38 AB_USER *u,
39 const char *url,
40 const char *defaultProto,
41 int defaultPort)
42 {
43 GWEN_HTTP_SESSION *sess;
44 AB_HTTP_SESSION *xsess;
45
46 assert(pro);
47 assert(u);
48
49 sess=GWEN_HttpSession_new(url, defaultProto, defaultPort);
50 assert(sess);
51 GWEN_NEW_OBJECT(AB_HTTP_SESSION, xsess);
52 GWEN_INHERIT_SETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess, xsess,
53 AB_HttpSession_FreeData);
54
55 xsess->provider=pro;
56 xsess->user=u;
57 xsess->logs=GWEN_Buffer_new(0, 256, 0, 1);
58
59 /* set virtual functions */
60 GWEN_HttpSession_SetInitSyncIoFn(sess, AB_HttpSession_InitSyncIo);
61
62 return sess;
63 }
64
65
66
AB_HttpSession_FreeData(void * bp,void * p)67 void GWENHYWFAR_CB AB_HttpSession_FreeData(void *bp, void *p)
68 {
69 AB_HTTP_SESSION *xsess;
70
71 xsess=(AB_HTTP_SESSION *)p;
72 GWEN_Buffer_free(xsess->logs);
73 GWEN_FREE_OBJECT(xsess);
74 }
75
76
77
AB_HttpSession_GetProvider(const GWEN_HTTP_SESSION * sess)78 AB_PROVIDER *AB_HttpSession_GetProvider(const GWEN_HTTP_SESSION *sess)
79 {
80 AB_HTTP_SESSION *xsess;
81
82 assert(sess);
83 xsess=GWEN_INHERIT_GETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess);
84 assert(xsess);
85
86 return xsess->provider;
87 }
88
89
90
AB_HttpSession_GetUser(const GWEN_HTTP_SESSION * sess)91 AB_USER *AB_HttpSession_GetUser(const GWEN_HTTP_SESSION *sess)
92 {
93 AB_HTTP_SESSION *xsess;
94
95 assert(sess);
96 xsess=GWEN_INHERIT_GETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess);
97 assert(xsess);
98
99 return xsess->user;
100 }
101
102
103
Ab_HttpSession_AddLog(GWEN_HTTP_SESSION * sess,const char * s)104 void Ab_HttpSession_AddLog(GWEN_HTTP_SESSION *sess,
105 const char *s)
106 {
107 AB_HTTP_SESSION *xsess;
108
109 assert(sess);
110 xsess=GWEN_INHERIT_GETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess);
111 assert(xsess);
112
113 if (s) {
114 size_t l=strlen(s);
115 if (s) {
116 GWEN_Buffer_AppendString(xsess->logs, s);
117 if (s[l-1]!='\n')
118 GWEN_Buffer_AppendByte(xsess->logs, '\n');
119 }
120 }
121 }
122
123
124
AB_HttpSession_GetLog(const GWEN_HTTP_SESSION * sess)125 const char *AB_HttpSession_GetLog(const GWEN_HTTP_SESSION *sess)
126 {
127 AB_HTTP_SESSION *xsess;
128
129 assert(sess);
130 xsess=GWEN_INHERIT_GETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess);
131 assert(xsess);
132
133 if (GWEN_Buffer_GetUsedBytes(xsess->logs))
134 return GWEN_Buffer_GetStart(xsess->logs);
135 else
136 return NULL;
137 }
138
139
140
AB_HttpSession_ClearLog(GWEN_HTTP_SESSION * sess)141 void AB_HttpSession_ClearLog(GWEN_HTTP_SESSION *sess)
142 {
143 AB_HTTP_SESSION *xsess;
144
145 assert(sess);
146 xsess=GWEN_INHERIT_GETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess);
147 assert(xsess);
148
149 GWEN_Buffer_Reset(xsess->logs);
150 }
151
152
153
154
AB_HttpSession_InitSyncIo(GWEN_HTTP_SESSION * sess,GWEN_SYNCIO * sio)155 int GWENHYWFAR_CB AB_HttpSession_InitSyncIo(GWEN_HTTP_SESSION *sess, GWEN_SYNCIO *sio)
156 {
157 AB_HTTP_SESSION *xsess;
158 GWEN_SYNCIO *sioTls;
159
160 assert(sess);
161 xsess=GWEN_INHERIT_GETDATA(GWEN_HTTP_SESSION, AB_HTTP_SESSION, sess);
162 assert(xsess);
163
164 /* modify TLS layer */
165 sioTls=GWEN_SyncIo_GetBaseIoByTypeName(sio, GWEN_SYNCIO_TLS_TYPE);
166 if (sioTls) {
167 DBG_INFO(AQBANKING_LOGDOMAIN, "Extending TLS SyncIo");
168 AB_SioTlsExt_Extend(sioTls, xsess->user);
169 }
170 else {
171 DBG_INFO(AQBANKING_LOGDOMAIN, "No TLS SyncIo, not extending");
172 }
173
174 return 0;
175 }
176
177
178
179