Changeset 939
- Timestamp:
- 2000-02-17T15:40:21+13:00 (24 years ago)
- Location:
- trunk/gsdl/src/recpt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/historydb.cpp
r928 r939 1 /********************************************************************** 2 * 3 * historydb.cpp -- 4 * Copyright (C) 1999 The New Zealand Digital Library Project 5 * 6 * A component of the Greenstone digital library software 7 * from the New Zealand Digital Library Project at the 8 * University of Waikato, New Zealand. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 * $Id$ 25 * 26 *********************************************************************/ 27 28 /* 29 $Log$ 30 Revision 1.2 2000/02/17 02:40:21 sjboddie 31 tidied up a bit - fixed a bug (gdbm file wasn't always being closed properly) 32 33 34 */ 1 35 2 36 #include "historydb.h" … … 10 44 // returns true on success (in which case historyinfo will contain 11 45 // the information for this history) 12 bool get_history_info (const text_t &userid, text_tarray &historyinfo )13 { 46 bool get_history_info (const text_t &userid, text_tarray &historyinfo, ostream &logout) { 47 14 48 text_t historyfile = filename_cat(GSDL_GSDLHOME, "etc", "history.db"); 15 49 … … 21 55 // get history list 22 56 text_t historyresult; 23 57 24 58 historydb.getkeydata(userid, historyresult); 25 59 26 60 if (historyresult != "") { // there are entries, process them 27 61 28 62 splitchar(historyresult.begin(), historyresult.end(), '\n', historyinfo); 29 63 result = true; … … 31 65 historydb.closedatabase(); 32 66 33 } // opendatabase 34 else { 35 cerr << "couldn't open db\n"; 36 37 } 67 } else { 68 outconvertclass text_t2ascii; 69 logout << text_t2ascii << "couldn't open history database " << historyfile << "\n"; 70 } 38 71 return result; 39 } // get history info72 } 40 73 41 74 42 75 // returns true on success 43 bool set_history_info (const text_t &userid, const text_t &history) 44 { 76 bool set_history_info (const text_t &userid, const text_t &history) { 45 77 46 78 text_t historyfile = filename_cat(GSDL_GSDLHOME, "etc", "history.db"); … … 94 126 95 127 // deletes all a users history 96 bool delete_all_history_info (const text_t &userid) 97 { 128 bool delete_all_history_info (const text_t &userid) { 129 98 130 text_t historyfile = filename_cat(GSDL_GSDLHOME, "etc", "history.db"); 99 131 … … 104 136 105 137 historydb.deletekey(userid); 138 historydb.closedatabase(); 106 139 return true; 107 140 … … 109 142 110 143 //deletes only the selected records 111 bool delete_history_info(const text_t &userid, const text_t &deletemode, const text_t &selection) 112 { 144 bool delete_history_info(const text_t &userid, const text_t &deletemode, const text_t &selection) { 145 113 146 text_t historyfile = filename_cat(GSDL_GSDLHOME, "etc", "history.db"); 114 147 bool result; … … 211 244 } 212 245 213 bool get_selection_params (text_t &data, int &start, int &stop) 214 { 215 246 bool get_selection_params (text_t &data, int &start, int &stop) { 247 248 text_tarray results; 216 249 217 250 splitchar(data.begin(), data.end(), '-', results); … … 221 254 222 255 return true; 223 } 224 else {256 257 } else { 225 258 // error message 226 259 return false; 227 260 } 228 229 261 } 230 262 231 263 // expand query takes a HistRecord, and expands out any hashes in 232 264 // the query string for queries that aren't to be saved 233 bool expand_query(HistRecord &record, HistRecordmap &records) 234 { 265 bool expand_query(HistRecord &record, HistRecordmap &records) { 266 235 267 text_tarray args; 236 268 splitchar(record.entry.begin(), record.entry.end(), '&', args); 237 269 238 270 text_tarray::iterator begin=args.begin(); … … 246 278 args.erase(begin); 247 279 break; 248 } 249 else { 250 begin++; 251 } 280 } else begin++; 252 281 } 253 282 if (query !="") { 254 283 255 284 //remove the q= 256 285 text_t::iterator front = query.begin(); … … 271 300 272 301 return true; 273 } else return false;302 } else return false; 274 303 }// expand query 275 304 … … 293 322 // get history list 294 323 if (historydb.getkeydata(userid, historyresult)) { 295 324 exists=true; 296 325 297 326 historydb.closedatabase(); 298 327 } 299 328 } … … 313 342 314 343 // if have got to here, have a previous history in historyresult 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 text_t querynum;330 text_t newquery;331 332 while (begin!=end) {333 if (*begin==text_t('#')) {334 335 336 querynum.push_back(*begin);337 begin++;338 344 text_tarray historyinfo; 345 splitchar(historyresult.begin(), historyresult.end(), '\n', historyinfo); 346 text_tarray::iterator histbegin = historyinfo.begin(); 347 text_tarray::iterator histend = historyinfo.end(); 348 349 text_tmap historymap; 350 // put all entries into a map, so can pull out the appropriate one easily 351 while (histbegin != histend) { 352 text_t num; 353 get_query_num(*histbegin, num); 354 historymap[num]=*histbegin; 355 histbegin++; 356 } 357 while(it!=end) { // while there still is a hash present 358 text_t querynum; 359 text_t newquery; 360 361 while (begin!=end) { 362 if (*begin==text_t('#')) { 363 begin++; 364 while(begin !=end && *begin>='0'&&*begin<='9') { 365 querynum.push_back(*begin); 366 begin++; 367 } 339 368 text_t oldquery = historymap[querynum]; 340 341 parse_saved_args(oldquery, text_t("q"), newquery);342 decode_cgi_arg(newquery);343 queryresult += newquery;344 345 346 result=false;347 348 369 if (oldquery !="") { // valid entry 370 parse_saved_args(oldquery, "q", newquery); 371 decode_cgi_arg(newquery); 372 queryresult += newquery; 373 } 374 else { 375 result=false; 376 } 377 querynum.clear(); 349 378 // else do nothing (replace #x with nothing) 350 } // if351 else {352 353 354 }355 } // while begin!=end356 357 // have got to end of query string,358 // now go back and check for internal #359 query = queryresult;360 begin = query.begin();361 end = query.end();362 it = findchar(begin, end, '#');363 queryresult.clear();364 365 366 367 368 369 379 } // if 380 else { 381 queryresult.push_back(*begin); 382 begin++; 383 } 384 } // while begin!=end 385 386 // have got to end of query string, 387 // now go back and check for internal # 388 query = queryresult; 389 begin = query.begin(); 390 end = query.end(); 391 it = findchar(begin, end, '#'); 392 queryresult.clear(); 393 394 } // while it !=end 395 396 397 return result; 398 370 399 } // combine query 371 400 … … 383 412 bool changed=true; 384 413 while(it!=end && changed) { // while there still is a hash present 385 // and query has changed since last time round414 // and query has changed since last time round 386 415 // we are leaving some #X in 387 text_t querynum;388 text_t newquery;389 changed=false;390 while (begin!=end) { // go through the query looking for hash391 if (*begin==text_t('#')) {392 393 394 querynum.push_back(*begin);395 begin++;396 397 398 if (!records[querynum].save){ // referenced record to be deleted399 // get the q arg out of referenced query400 parse_saved_args(records[querynum].entry, text_t("q"), newquery);401 decode_cgi_arg(newquery);402 queryresult += newquery;403 changed=true;404 405 else { // leave the #x in416 text_t querynum; 417 text_t newquery; 418 changed=false; 419 while (begin!=end) { // go through the query looking for hash 420 if (*begin==text_t('#')) { 421 begin++; 422 while(begin !=end && *begin>='0'&&*begin<='9') { 423 querynum.push_back(*begin); 424 begin++; 425 } 426 if(records.count(querynum)>0) { // valid entry 427 if (!records[querynum].save){ // referenced record to be deleted 428 // get the q arg out of referenced query 429 parse_saved_args(records[querynum].entry, "q", newquery); 430 decode_cgi_arg(newquery); 431 queryresult += newquery; 432 changed=true; 433 } 434 else { // leave the #x in 406 435 queryresult.push_back('#'); 407 436 queryresult += querynum; 408 } 409 } 410 querynum.clear(); 411 newquery.clear(); 412 // else do nothing (replace #x with nothing) 413 } // if its a hash 414 else { 415 queryresult.push_back(*begin); 416 begin++; 417 } 418 } // while begin!=end 419 420 // have got to end of query string, 421 // now go back and check for internal # 422 query = queryresult; 423 begin = query.begin(); 424 end = query.end(); 425 it = findchar(begin, end, '#'); 426 queryresult.clear(); 427 428 } // while it !=end 429 430 431 return true; 432 437 } 438 } 439 querynum.clear(); 440 newquery.clear(); 441 // else do nothing (replace #x with nothing) 442 } // if its a hash 443 else { 444 queryresult.push_back(*begin); 445 begin++; 446 } 447 } // while begin!=end 448 449 // have got to end of query string, 450 // now go back and check for internal # 451 query = queryresult; 452 begin = query.begin(); 453 end = query.end(); 454 it = findchar(begin, end, '#'); 455 queryresult.clear(); 456 457 } // while it !=end 458 459 return true; 433 460 } // combine query 434 461 435 462 // retrieves the value of one of the arguments 436 void parse_saved_args(text_t &args, text_t &key, text_t &value)463 void parse_saved_args(text_t &args, text_t key, text_t &value) 437 464 { 438 465 text_t::iterator here = args.begin(); … … 492 519 493 520 while (*begin >='0'&& *begin <='9') { // get the digits 494 495 521 querynum.push_back(*begin); 522 begin++; 496 523 } 497 524 if (*begin != ':') { … … 499 526 } 500 527 } 528 501 529 void split_saved_query(text_t &query, text_t &querynum, text_t &numdocs, text_t &cgiargs) 502 530 { 503 531 text_t::iterator begin = query.begin(); 504 532 text_t::iterator end = query.end(); 505 533 506 534 while (*begin >='0'&& *begin <='9') { // get the digits 507 535 querynum.push_back(*begin); … … 513 541 else begin++; 514 542 while (*begin >='0'&& *begin <='9') { // get the digits 515 516 543 numdocs.push_back(*begin); 544 begin++; 517 545 } 518 546 if (*begin == '+') { // get the + if there … … 529 557 logout << "in format user info"; 530 558 text_tset metadata; 531 559 532 560 infodbclass argsinfo; 533 561 parse_saved_args(cgiargs, argsinfo); 534 562 535 563 text_t collect = argsinfo["c"]; 536 564 if (collect=="") { … … 558 586 mode = "some words"; 559 587 } 560 588 561 589 } 562 590 else { // advanced mode … … 568 596 } 569 597 } 570 598 571 599 text_t options; 572 600 if (argsinfo["k"]=="0") { … … 582 610 options += ", ignore word endings"; 583 611 } 584 612 585 613 userinfo.clear(); 586 614 userinfo = "collection ("+argsinfo["c"] + ") "; -
trunk/gsdl/src/recpt/historydb.h
r928 r939 1 /********************************************************************** 2 * 3 * historydb.h -- 4 * Copyright (C) 1999 The New Zealand Digital Library Project 5 * 6 * A component of the Greenstone digital library software 7 * from the New Zealand Digital Library Project at the 8 * University of Waikato, New Zealand. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 * $Id$ 25 * 26 *********************************************************************/ 1 27 2 28 3 #ifndef HISTORY _H4 #define HISTORY _H29 #ifndef HISTORYDB_H 30 #define HISTORYDB_H 5 31 6 32 #include "infodbclass.h" 7 33 #include "text_t.h" 8 34 #include "recptproto.h" 9 //#include <vector.h>10 35 #include <map.h> 11 36 … … 26 51 // returns true on success (in which case historyinfo will contain 27 52 // the information for this history) 28 bool get_history_info ( const text_t &userid, text_tarray &historyinfo );53 bool get_history_info ( const text_t &userid, text_tarray &historyinfo, ostream &logout); 29 54 30 55 // returns true on success … … 52 77 // retrieves the value of an arg (key) from a list of cgi args 53 78 // in the form a=q&b=1&... 54 void parse_saved_args(text_t &args, text_t &key, text_t &value);79 void parse_saved_args(text_t &args, text_t key, text_t &value); 55 80 56 81 // extracts out the components of an entry in the database
Note:
See TracChangeset
for help on using the changeset viewer.