64
76
ifstream input_file;
66
78
char buffer[READ_BUFFER_SIZE];
79
char iconv_buffer[READ_BUFFER_SIZE];
68
81
char *filenames[3];
69
char tmp_filename[50];
82
char tmp_filename[256];
84
iconv_t conversion_descriptor;
71
86
libofx_context=(LibofxContext*)ctx;
73
88
if(p_filename!=NULL&&strcmp(p_filename,"")!=0)
75
90
message_out(DEBUG, string("ofx_proc_file():Opening file: ")+ p_filename);
77
92
input_file.open(p_filename);
78
strncpy(tmp_filename,"/tmp/libofxtmpXXXXXX",50);
93
mkTempFileName("libofxtmpXXXXXX", tmp_filename, sizeof(tmp_filename));
79
94
mkstemp(tmp_filename);
80
95
tmp_file.open(tmp_filename);
118
137
s_buffer.erase(0,ofx_start_idx);//Fix for really broken files that don't have a newline after the header.
119
138
message_out(DEBUG,"ofx_proc_file():<OFX> or <OFC> has been found");
142
if(ofx_encoding.compare("USASCII")==0){
143
if(ofx_charset.compare("ISO-8859-1")==0){
144
fromcode="ISO-8859-1";
146
else if(ofx_charset.compare("1252")==0){
149
else if(ofx_charset.compare("NONE")==0){
150
fromcode=LIBOFX_DEFAULT_INPUT_ENCODING;
153
else if(ofx_encoding.compare("USASCII")==0) {
158
fromcode=LIBOFX_DEFAULT_INPUT_ENCODING;
160
tocode = LIBOFX_DEFAULT_OUTPUT_ENCODING;
161
message_out(DEBUG,"ofx_proc_file(): Setting up iconv for fromcode: "+fromcode+", tocode: "+tocode);
162
conversion_descriptor = iconv_open (tocode.c_str(), fromcode.c_str());
166
//We are still in the headers
167
if ((header_separator_idx=s_buffer.find(':')) != string::npos) {
169
header_name.assign(s_buffer.substr(0,header_separator_idx));
170
header_value.assign(s_buffer.substr(header_separator_idx+1));
171
message_out(DEBUG,"ofx_proc_file():Header: "+header_name+" with value: "+header_value+" has been found");
172
if(header_name.compare("ENCODING")==0) {
173
ofx_encoding.assign(header_value);
175
if(header_name.compare("CHARSET")==0) {
176
ofx_charset.assign(header_value);
122
181
if(ofx_start==true && ofx_end==false){
123
182
s_buffer=sanitize_proprietary_tags(s_buffer);
124
183
//cout<< s_buffer<<"\n";
125
tmp_file.write(s_buffer.c_str(), s_buffer.length());
185
memset(iconv_buffer,0,READ_BUFFER_SIZE);
186
size_t inbytesleft = strlen(s_buffer.c_str());
187
size_t outbytesleft = READ_BUFFER_SIZE;
189
const char * inchar = (const char *)s_buffer.c_str();
191
char * inchar = (char *)s_buffer.c_str();
193
char * outchar = iconv_buffer;
194
int iconv_retval = iconv (conversion_descriptor,
195
&inchar, &inbytesleft,
196
&outchar, &outbytesleft);
197
if(iconv_retval==-1){
198
message_out(ERROR,"ofx_proc_file(): Conversion error");
200
s_buffer = iconv_buffer;
202
tmp_file.write(s_buffer.c_str(), s_buffer.length());
128
205
if (ofx_start==true &&
145
222
input_file.close();
146
223
tmp_file.close();
225
iconv_close(conversion_descriptor);
148
227
char filename_openspdtd[255];
149
228
char filename_dtd[255];
150
229
char filename_ofx[255];
151
strncpy(filename_openspdtd,find_dtd(OPENSPDCL_FILENAME).c_str(),255);//The opensp sgml dtd file
230
strncpy(filename_openspdtd,find_dtd(ctx, OPENSPDCL_FILENAME).c_str(),255);//The opensp sgml dtd file
152
231
if(libofx_context->currentFileType()==OFX)
154
strncpy(filename_dtd,find_dtd(OFX160DTD_FILENAME).c_str(),255);//The ofx dtd file
233
strncpy(filename_dtd,find_dtd(ctx, OFX160DTD_FILENAME).c_str(),255);//The ofx dtd file
156
235
else if(libofx_context->currentFileType()==OFC)
158
strncpy(filename_dtd,find_dtd(OFCDTD_FILENAME).c_str(),255);//The ofc dtd file
237
strncpy(filename_dtd,find_dtd(ctx, OFCDTD_FILENAME).c_str(),255);//The ofc dtd file
217
296
s_buffer=string(s, size);
219
strncpy(tmp_filename,"/tmp/libofxtmpXXXXXX",50);
298
mkTempFileName("libofxtmpXXXXXX", tmp_filename, sizeof(tmp_filename));
220
299
mkstemp(tmp_filename);
221
300
tmp_file.open(tmp_filename);
268
if (pos==string::npos) {
347
if (pos==string::npos || pos > s_buffer.size()) {
269
348
message_out(ERROR,"ofx_proc():</OF?> has not been found");
273
352
// erase everything after the /OFX tag
274
s_buffer.erase(pos+6);
353
if (s_buffer.size() > pos+6)
354
s_buffer.erase(pos+6);
275
355
message_out(DEBUG,"ofx_proc_file():<OFX> has been found");
283
363
char filename_openspdtd[255];
284
364
char filename_dtd[255];
285
365
char filename_ofx[255];
286
strncpy(filename_openspdtd,find_dtd(OPENSPDCL_FILENAME).c_str(),255);//The opensp sgml dtd file
366
strncpy(filename_openspdtd,find_dtd(ctx, OPENSPDCL_FILENAME).c_str(),255);//The opensp sgml dtd file
287
367
if(libofx_context->currentFileType()==OFX){
288
strncpy(filename_dtd,find_dtd(OFX160DTD_FILENAME).c_str(),255);//The ofx dtd file
368
strncpy(filename_dtd,find_dtd(ctx, OFX160DTD_FILENAME).c_str(),255);//The ofx dtd file
290
370
else if(libofx_context->currentFileType()==OFC){
291
strncpy(filename_dtd,find_dtd(OFCDTD_FILENAME).c_str(),255);//The ofc dtd file
371
strncpy(filename_dtd,find_dtd(ctx, OFCDTD_FILENAME).c_str(),255);//The ofc dtd file
294
374
message_out(ERROR,string("ofx_proc_file(): Error unknown file format for the OFX parser"));
432
512
Please note that currently the function will ALWAYS look for version 160, since OpenSP can't parse the 201 DTD correctly
434
string find_dtd(string dtd_filename)
514
string find_dtd(LibofxContextPtr ctx, string dtd_filename)
437
517
ifstream dtd_file;
438
518
string dtd_path_filename;
439
519
bool dtd_found=false;
441
for(i=0;i<DTD_SEARCH_PATH_NUM&&dtd_found==false;i++){
442
dtd_path_filename=DTD_SEARCH_PATH[i];
521
dtd_path_filename=((LibofxContext*)ctx)->dtdDir();
522
if (!dtd_path_filename.empty()) {
443
523
dtd_path_filename.append(dtd_filename);
444
524
dtd_file.clear();
445
525
dtd_file.open(dtd_path_filename.c_str());
447
message_out(DEBUG,"find_dtd():Unable to open the file "+dtd_path_filename);
450
527
message_out(STATUS,"find_dtd():DTD found: "+dtd_path_filename);
451
528
dtd_file.close();
534
for(i=0;i<DTD_SEARCH_PATH_NUM&&dtd_found==false;i++){
535
dtd_path_filename=DTD_SEARCH_PATH[i];
536
dtd_path_filename.append(dtd_filename);
538
dtd_file.open(dtd_path_filename.c_str());
540
message_out(DEBUG,"find_dtd():Unable to open the file "+dtd_path_filename);
543
message_out(STATUS,"find_dtd():DTD found: "+dtd_path_filename);
455
550
if(dtd_found==false){
456
551
message_out(ERROR,"find_dtd():Unable to find the DTD named " + dtd_filename);
457
552
dtd_path_filename="";