summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 280fba1)
raw | patch | inline | side by side (parent: 280fba1)
author | ishmal <ishmal@users.sourceforge.net> | |
Sun, 13 Apr 2008 20:11:16 +0000 (20:11 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Sun, 13 Apr 2008 20:11:16 +0000 (20:11 +0000) |
src/pedro/pedroutil.cpp | patch | blob | history | |
src/pedro/pedroutil.h | patch | blob | history | |
src/pedro/pedroxmpp.cpp | patch | blob | history |
index c19498281842148d203fb89b6fc2c5c10ccced4a..2197527fb44c5372bdd92acd2cb69e203e697e9f 100644 (file)
--- a/src/pedro/pedroutil.cpp
+++ b/src/pedro/pedroutil.cpp
}
+
+
#ifdef HAVE_SSL
static void cryptoLockCallback(int mode, int type, const char *file, int line)
err:
if (errstr)
{
- /* we cannot use bio_err here */
- fprintf(stderr, "openssl (lock_dbg_cb): %s (mode=%d, type=%d) at %s:%d\n",
- errstr, mode, type, file, line);
+ //how do we pass a context pointer here?
+ //error("openssl (lock_dbg_cb): %s (mode=%d, type=%d) at %s:%d",
+ // errstr, mode, type, file, line);
}
}
portno = other.portno;
}
+
+void TcpSocket::error(char *fmt, ...)
+{
+ static char buf[256];
+ lastError = "TcpSocket err: ";
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(buf, 255, fmt, args);
+ va_end(args);
+ lastError.append(buf);
+ fprintf(stderr, "%s\n", lastError.c_str());
+}
+
+
+DOMString &TcpSocket::getLastError()
+{
+ return lastError;
+}
+
+
+
static bool tcp_socket_inited = false;
void TcpSocket::init()
bool TcpSocket::startTls()
{
#ifndef HAVE_SSL
- fprintf(stderr,
- "SSL starttls() error: client not compiled with SSL enabled\n");
+ error("SSL starttls() error: client not compiled with SSL enabled");
return false;
#else /*HAVE_SSL*/
if (!libssl_is_present)
- {
- fprintf(stderr,
- "SSL starttls() error: the correct version of libssl was not found \n");
- return false;
- } else {
-
+ {
+ error("SSL starttls() error: the correct version of libssl was not found");
+ return false;
+ }
+
sslStream = NULL;
sslContext = NULL;
int ret = SSL_connect(sslStream);
if (ret == 0)
{
- fprintf(stderr, "SSL connection not successful\n");
+ error("SSL connection not successful");
disconnect();
return false;
}
else if (ret < 0)
{
int err = SSL_get_error(sslStream, ret);
- fprintf(stderr, "SSL connect error %d\n", err);
+ error("SSL connect error %d", err);
disconnect();
return false;
}
sslEnabled = true;
return true;
- }
#endif /* HAVE_SSL */
}
{
if (hostname.size()<1)
{
- fprintf(stderr, "open: null hostname\n");
+ error("open: null hostname");
return false;
}
if (portno<1)
{
- fprintf(stderr, "open: bad port number\n");
+ error("open: bad port number");
return false;
}
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
- fprintf(stderr, "open: error creating socket\n");
+ error("open: error creating socket");
return false;
}
struct hostent *server = gethostbyname(c_hostname);
if (!server)
{
- fprintf(stderr, "open: could not locate host '%s'\n", c_hostname);
+ error("open: could not locate host '%s'", c_hostname);
return false;
}
int ret = ::connect(sock, (const sockaddr *)&serv_addr, sizeof(serv_addr));
if (ret < 0)
{
- fprintf(stderr, "open: could not connect to host '%s'\n", c_hostname);
+ error("open: could not connect to host '%s'", c_hostname);
return false;
}
case 0:
case -1:
default:
- //printf("Shutdown failed");
+ error("Shutdown failed");
ret = false;
}
SSL_free(sslStream);
if (count<=0 && sslEnabled)
{
#ifdef HAVE_SSL
- if (libssl_is_present)
- {
+ if (libssl_is_present)
+ {
return SSL_pending(sslStream);
- }
+ }
#endif
}
return count;
{
if (!isConnected())
{
- fprintf(stderr, "write: socket closed\n");
+ error("write: socket closed");
return false;
}
unsigned char c = (unsigned char)ch;
switch(SSL_get_error(sslStream, r))
{
default:
- fprintf(stderr, "SSL write problem");
+ error("SSL write problem");
return -1;
}
}
if (send(sock, (const char *)&c, 1, 0) < 0)
//if (send(sock, &c, 1, 0) < 0)
{
- fprintf(stderr, "write: could not send data\n");
+ error("write: could not send data");
return false;
}
}
{
if (!isConnected())
{
- fprintf(stderr, "write(str): socket closed\n");
+ error("write(str): socket closed");
return false;
}
int len = strlen(str);
switch(SSL_get_error(sslStream, r))
{
default:
- fprintf(stderr, "SSL write problem");
+ error("SSL write problem");
return -1;
}
}
if (send(sock, str, len, 0) < 0)
//if (send(sock, &c, 1, 0) < 0)
{
- fprintf(stderr, "write: could not send data\n");
+ error("write: could not send data");
return false;
}
}
case SSL_ERROR_ZERO_RETURN:
return -1;
case SSL_ERROR_SYSCALL:
- fprintf(stderr, "SSL read problem(syscall) %s\n",
+ error("SSL read problem(syscall) %s",
ERR_error_string(ERR_get_error(), NULL));
return -1;
default:
- fprintf(stderr, "SSL read problem %s\n",
+ error("SSL read problem %s",
ERR_error_string(ERR_get_error(), NULL));
return -1;
}
{
if (recv(sock, (char *)&ch, 1, 0) <= 0)
{
- fprintf(stderr, "read: could not receive data\n");
+ error("read: could not receive data");
disconnect();
return -1;
}
diff --git a/src/pedro/pedroutil.h b/src/pedro/pedroutil.h
index b683080a189a7c8d2c53884ef1a02ddc8e4d01e1..767c23b95c3f2b67c6e54ad23d8839ca82a36b57 100644 (file)
--- a/src/pedro/pedroutil.h
+++ b/src/pedro/pedroutil.h
*/
#include <stdio.h>
+#include <stdarg.h>
#include <vector>
#include <string>
TcpSocket(const TcpSocket &other);
virtual ~TcpSocket();
+
+ void error(char *fmt, ...);
+
+ DOMString &getLastError();
bool isConnected();
private:
void init();
+ DOMString lastError;
+
std::string hostname;
int portno;
int sock;
bool sslEnabled;
unsigned long receiveTimeout;
+
#ifdef HAVE_SSL
SSL_CTX *sslContext;
index 23bfbad6fe052a957d7a89dc9c5c252abc157358..4880123e8c6b45b37bb25ebcce47b2e7e9cf30de 100644 (file)
--- a/src/pedro/pedroxmpp.cpp
+++ b/src/pedro/pedroxmpp.cpp
}
else
{
- error("socket read error");
+ error("socket read error: %s", sock->getLastError().c_str());
disconnect();
return "";
}
status("SEND: %s", buffer);
if (!sock->write(buffer))
{
- error("Cannot write to socket");
+ error("Cannot write to socket: %s", sock->getLastError().c_str());
rc = false;
}
g_free(buffer);
delete elem;
if (!sock->startTls())
{
- error("Could not start TLS");
+ DOMString tcperr = sock->getLastError();
+ error("Could not start TLS: %s", tcperr.c_str());
disconnect();
return false;
}
sock->enableSSL(true);
if (!sock->connect(host, port))
{
+ error("Cannot connect:%s", sock->getLastError().c_str());
return false;
}