Skip to content

Commit

Permalink
fix: Use RAII to manage libcurl connections.
Browse files Browse the repository at this point in the history
- Fix error handling in LuaServer.cpp.
  • Loading branch information
Benjamin Geer committed Dec 20, 2016
1 parent fb1bdfc commit 87f1366
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 365 deletions.
6 changes: 5 additions & 1 deletion it/src/test/resources/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ http {
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;
log_format addHeaderlog '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$http_x_forwarded_for" "$request_body" "$http_Authorization" "$http_x_duid" "$http_x_ver" "$upstream_http_x_rqid"';

access_log logs/access.log addHeaderlog;

sendfile on;
#tcp_nopush on;
Expand Down
37 changes: 16 additions & 21 deletions shttps/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with Sipi. If not, see <http://www.gnu.org/licenses/>.
*/#include <cstring>
#include <sstream> // std::stringstream
*/

#include <sstream> // std::ostringstream

#include "Error.h"

using namespace std;
namespace shttps {

Error::Error (const char *file_p, const int line_p, const char *msg, int errno_p)
: runtime_error(string(string(msg) + "\nFile: ") + string(file_p) + string(" Line: ") + std::to_string(line_p)),
: runtime_error(std::string(msg) + "\nFile: " + std::string(file_p) + std::string(" Line: ") + std::to_string(line_p)),
line (line_p),
file (file_p),
message (msg),
Expand All @@ -39,8 +39,8 @@ namespace shttps {
//============================================================================


Error::Error (const char *file_p, const int line_p, const string &msg, int errno_p)
: runtime_error(msg + string("\nFile: ") + string(file_p) + string(" Line: ") + std::to_string(line_p)),
Error::Error (const char *file_p, const int line_p, const std::string &msg, int errno_p)
: runtime_error(std::string(msg) + "\nFile: " + std::string(file_p) + std::string(" Line: ") + std::to_string(line_p)),
line (line_p),
file (file_p),
message (msg),
Expand All @@ -50,26 +50,21 @@ namespace shttps {
}
//============================================================================

string Error::to_string(void)
std::string Error::to_string(void) const
{
stringstream ss;
ss << "SHTTPS-ERROR at [" << file << ": " << line << "] ";
if (sysErrno != 0) ss << "System error: " << strerror(sysErrno) << " ";
ss << "Description: " << message;

return ss.str();
std::ostringstream errStream;
errStream << "Error at [" << file << ": " << line << "]";
if (sysErrno != 0) errStream << " (system error: " << std::strerror(sysErrno) << ")";
errStream << ": " << message;
return errStream.str();
}
//============================================================================

ostream &operator<< (ostream &outstr, const Error &rhs)
std::ostream &operator<< (std::ostream &outStream, const Error &rhs)
{
outstr << endl << "SHTTPS-ERROR at [" << rhs.file << ": #" << rhs.line << "] " << endl;

if (rhs.sysErrno != 0) {
outstr << "System error: " << strerror(rhs.sysErrno) << endl;
}
outstr << "Description: " << rhs.message << endl;
return outstr;
std::string errStr = rhs.to_string();
outStream << errStr << std::endl; // TODO: remove the endl, the logging code should do it
return outStream;
}
//============================================================================

Expand Down
8 changes: 5 additions & 3 deletions shttps/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ namespace shttps {
std::string file; //!< Name of source code file where the exception has been thrown
std::string message; //!< Description of the problem
int sysErrno; //!< If there is a system error number

public:

inline int getLine(void) const { return line; }
inline std::string getFile(void) const { return file; }
inline std::string getMessage(void) const { return message; }
inline int getSysErrno(void) const { return sysErrno; }

/*!
* Constructor with all (char *) strings
*
Expand Down Expand Up @@ -78,16 +80,16 @@ namespace shttps {
*
* \returns Error string
*/
std::string to_string(void);
std::string to_string(void) const;

/*!
* The overloaded << operator which is used to write the error message to the output
*
* \param[in] lhs The output stream
* \param[in] outStream The output stream
* \param[in] rhs Reference to an instance of a Error
* \returns Returns an std::ostream object
*/
friend std::ostream &operator<< (std::ostream &outstr, const Error &rhs);
friend std::ostream &operator<< (std::ostream &outStream, const Error &rhs);
};
}

Expand Down
Loading

0 comments on commit 87f1366

Please sign in to comment.