[166] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * pingaction.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 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.
|
---|
[166] | 9 | *
|
---|
[533] | 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 | *
|
---|
[166] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "pingaction.h"
|
---|
| 27 |
|
---|
| 28 | pingaction::pingaction () {
|
---|
| 29 | // this action uses cgi variable "a"
|
---|
| 30 | cgiarginfo arg_ainfo;
|
---|
| 31 | arg_ainfo.shortname = "a";
|
---|
| 32 | arg_ainfo.longname = "action";
|
---|
| 33 | arg_ainfo.multiplechar = true;
|
---|
| 34 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 35 | arg_ainfo.argdefault = "ping";
|
---|
| 36 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 37 |
|
---|
| 38 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 39 |
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[760] | 42 | void pingaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
| 43 | response_t &response, text_t &response_data,
|
---|
| 44 | ostream &/*logout*/) {
|
---|
[166] | 45 | response = content;
|
---|
| 46 | response_data = "text/html";
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
[760] | 50 | bool pingaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
| 51 | browsermapclass * /*browsers*/, displayclass &/*disp*/,
|
---|
[421] | 52 | outconvertclass &outconvert, ostream &textout,
|
---|
| 53 | ostream &logout) {
|
---|
[166] | 54 | bool wassuccess = false;
|
---|
| 55 | comerror_t err;
|
---|
[172] | 56 |
|
---|
[760] | 57 | recptproto *collectproto = protos->getrecptproto (args["c"], logout);
|
---|
[166] | 58 | if (!args["c"].empty() && (collectproto != NULL)) {
|
---|
| 59 | collectproto->ping (args["c"], wassuccess, err, logout);
|
---|
| 60 | if (err != noError) wassuccess = false; // a communication error
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | textout << outconvert
|
---|
| 64 | << "<html>\n"
|
---|
| 65 | << "<head>\n"
|
---|
| 66 | << "<title>Ping</title>\n"
|
---|
| 67 | << "</head>\n"
|
---|
| 68 | << "<body>\n"
|
---|
| 69 | << "Ping for \"" << args["c"] << "\" ";
|
---|
| 70 |
|
---|
| 71 | if (wassuccess) {
|
---|
| 72 | textout << outconvert << " succeeded.\n";
|
---|
| 73 | } else {
|
---|
| 74 | textout << outconvert << " did not succeed.\n";
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | textout << outconvert
|
---|
| 78 | << "</body>\n"
|
---|
| 79 | << "</html>\n";
|
---|
| 80 |
|
---|
| 81 | return true;
|
---|
| 82 | };
|
---|