bes  Updated for version 3.20.6
GatewayError.cc
1 // GatewayError.cc
2 
3 // -*- mode: c++; c-basic-offset:4 -*-
4 
5 // This file is part of gateway_module, A C++ module that can be loaded in to
6 // the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
7 
8 // Copyright (c) 2002,2003 OPeNDAP, Inc.
9 // Author: Patrick West <pwest@ucar.edu>
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
26 
27 // Authors:
28 // pcw Patrick West <pwest@ucar.edu>
29 
30 #include <cstdio>
31 #include <cstdlib>
32 
33 #include "GatewayError.h"
34 
35 using namespace std;
36 using namespace gateway;
37 
47 void GatewayError::read_error(const string &filename, string &err, const string &url)
48 {
49  err = "Remote Request failed for url: " + url + " with error: ";
50 
51  // The temporary file will contain the error information that we need to
52  // report.
53  FILE *f = fopen(filename.c_str(), "r");
54  if (!f) {
55  err = err + "Could not open the error file " + filename;
56  return;
57  }
58 
59  // read from the file until there is no more to read
60  bool done = false;
61  const unsigned int bufsize = 1025;
62  while (!done) {
63  char buff[bufsize];
64  size_t bytes_read = fread(buff, 1, bufsize-1, f);
65  if (0 == bytes_read) {
66  done = true;
67  }
68  else {
69  if (bytes_read < bufsize)
70  buff[bytes_read] = '\0';
71  else
72  buff[bufsize-1] = '\0';
73 
74  err = err + buff;
75  }
76  }
77 
78  fclose(f);
79 }