Example #1
0
void
Controller::writeBenchmarkResponse(Client **client, Request **req, bool end) {
	if (canKeepAlive(*req)) {
		writeResponse(*client, P_STATIC_STRING(
			"HTTP/1.1 200 OK\r\n"
			"Status: 200 OK\r\n"
			"Date: Wed, 15 Nov 1995 06:25:24 GMT\r\n"
			"Content-Type: text/plain\r\n"
			"Content-Length: 3\r\n"
			"Connection: keep-alive\r\n"
			"\r\n"
			"ok\n"));
	} else {
		writeResponse(*client, P_STATIC_STRING(
			"HTTP/1.1 200 OK\r\n"
			"Status: 200 OK\r\n"
			"Date: Wed, 15 Nov 1995 06:25:24 GMT\r\n"
			"Content-Type: text/plain\r\n"
			"Content-Length: 3\r\n"
			"Connection: close\r\n"
			"\r\n"
			"ok\n"));
	}
	if (end && !(*req)->ended()) {
		endRequest(client, req);
	}
}
Example #2
0
DragNDropResponse::DragNDropResponse(JsonClient *client, const QtJson::JsonObject &command) :
    DelayedResponse(client, command)
{
    WidgetLocatorContext<QWidget> ctx(static_cast<Player *>(jsonClient()), command, "srcoid");
    WidgetLocatorContext<QWidget> ctx2(static_cast<Player *>(jsonClient()), command, "destoid");

    if (ctx.hasError()) { writeResponse(ctx.lastError); return; }
    if (ctx2.hasError()) { writeResponse(ctx2.lastError); return; }

    QPoint srcPos;
    if (command.contains("srcpos") && ! command["srcpos"].isNull()) {
        srcPos = pointFromString(command["srcpos"].toString());
    } else {
        srcPos = ctx.widget->rect().center();
    }

    QPoint destPos;
    if (command.contains("destpos") && ! command["destpos"].isNull()) {
        destPos = pointFromString(command["destpos"].toString());
    } else {
        destPos = ctx2.widget->rect().center();
    }

    m_src = ctx.widget;
    m_dest = ctx2.widget;
    m_srcPos = srcPos;
    m_destPos = destPos;
}
Example #3
0
bool UrlRetrievalServer::handleRequest(QHttpRequest *request, QHttpResponse *response) {
    const QStringList parts = request->path().split("/", QString::SkipEmptyParts);
    
    if ((parts.isEmpty()) || (parts.size() > 2) || (parts.first() != "urlretrieval")) {
        return false;
    }

    if (parts.size() == 1) {
        if (request->method() == QHttpRequest::HTTP_GET) {
            writeResponse(response, QHttpResponse::STATUS_OK, QtJson::Json::serialize(Qdl::getUrlRetrievals()));
            return true;
        }

        if (request->method() == QHttpRequest::HTTP_POST) {
            const QVariantMap properties = QtJson::Json::parse(request->body()).toMap();
            const QStringList urls = properties.value("urls").toStringList();
            
            if (urls.isEmpty()) {
                writeResponse(response, QHttpResponse::STATUS_BAD_REQUEST);
            }
            else {
                Qdl::addUrlRetrievals(urls, properties.value("pluginId").toString());
                writeResponse(response, QHttpResponse::STATUS_CREATED);
            }

            return true;
        }

        if (request->method() == QHttpRequest::HTTP_DELETE) {
            Qdl::clearUrlRetrievals();
            writeResponse(response, QHttpResponse::STATUS_OK);
            return true;
        }
    }

    if (request->method() == QHttpRequest::HTTP_GET) {
        const QVariantMap data = Qdl::getUrlRetrieval(parts.at(1));

        if (!data.isEmpty()) {
            writeResponse(response, QHttpResponse::STATUS_OK, QtJson::Json::serialize(data));
            return true;
        }

        return false;
    }

    if (request->method() == QHttpRequest::HTTP_DELETE) {
        if (Qdl::removeUrlRetrieval(parts.at(1))) {
            writeResponse(response, QHttpResponse::STATUS_OK);
        }
        else {
            writeResponse(response, QHttpResponse::STATUS_BAD_REQUEST);
        }

        return true;
    }

    writeResponse(response, QHttpResponse::STATUS_METHOD_NOT_ALLOWED);
    return true;
}
Example #4
0
void loggerClient(int socket, int method, Client *client, char *s1, char *s2) {
    switch (method) {
        case BADREQUEST:
            asprintf(&client->httpRes.filePath, "/%s/%d", sc.statusCodesDir, BADREQUEST);
            client->httpRes.statusCode = "400 Bad Request";
            break;
        case FORBIDDEN:
            asprintf(&client->httpRes.filePath, "/%s/%d", sc.statusCodesDir, FORBIDDEN);
            client->httpRes.statusCode = "403 Forbidden";
            break;
        case NOTFOUND:
            asprintf(&client->httpRes.filePath, "/%s/%d", sc.statusCodesDir, NOTFOUND);
            client->httpRes.statusCode = "404 Not Found";
            break;
        case INTERNALSERVERERROR:
            asprintf(&client->httpRes.filePath, "/%s/%d", sc.statusCodesDir, INTERNALSERVERERROR);
            client->httpRes.statusCode = "500 Internal Server Error";
            break;
        case NOTIMPLEMENTED:
            asprintf(&client->httpRes.filePath, "/%s/%d", sc.statusCodesDir, NOTIMPLEMENTED);
            client->httpRes.statusCode = "501 Not Implemented";
            break;
    }
    writeResponse(socket, client);
    free(client->httpRes.filePath);
}
Example #5
0
void work(int sock) {
	if (readRequest(sock) > 0) writeResponse(sock);
	snooze(0,1000000);						// sleep for 1 milisecond
	if (--timeout <= 0) done = 1;
	if (timeout%1000 == 0) debug("Socket %d has %ds before disconnect",sock,timeout/1000);
	if (done) closeSocket(sock);
}
Example #6
0
int
data(dsocket *sd)
{
	int retval = 0;
	dstrbuf *rbuf = DSB_NEW;

	/* Create the DATA command and send it */
	if (writeResponse(sd, "DATA\r\n") < 0) {
		smtpSetErr("Lost connection with SMTP server");
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("\r\n--> DATA\r\n");
#endif

	/* Read return message and let's return it's code */
	retval = readResponse(sd, rbuf);
	if (retval != 354) {
		if (retval != ERROR) {
			smtpSetErr(rbuf->str);
		}
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("<-- %s", rbuf->str);
#endif

end:
	dsbDestroy(rbuf);
	return retval;
}
Example #7
0
/**
 * Send the QUIT command
 */
static int
quit(dsocket *sd)
{
	int retval = 0;
	dstrbuf *rbuf = DSB_NEW;

	/* Create QUIT command and send it */
	if (writeResponse(sd, "QUIT\r\n") < 0) {
		smtpSetErr("Lost Connection with SMTP server: Quit()");
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("--> QUIT\r\n");
#endif

	retval = readResponse(sd, rbuf);
	if (retval != 221) {
		if (retval != ERROR) {
			smtpSetErr(rbuf->str);
		}
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("<-- %s", rbuf->str);
#endif

end:
	dsbDestroy(rbuf);
	return retval;
}
Example #8
0
/** 
 * Send the MAIL FROM: command to the smtp server 
 */
static int
mailFrom(dsocket *sd, const char *email)
{
	int retval = 0;
	dstrbuf *rbuf = DSB_NEW;

	/* Create the MAIL FROM: command */
	if (writeResponse(sd, "MAIL FROM:<%s>\r\n", email) < 0) {
		smtpSetErr("Lost connection with SMTP server");
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("\r\n--> MAIL FROM:<%s>\r\n", email);
#endif

	/* read return message and let's return it's code */
	retval = readResponse(sd, rbuf);
	if (retval != 250) {
		if (retval != ERROR) {
			smtpSetErr(rbuf->str);
		}
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("\r\n<-- %s", rbuf->str);
#endif

end:
	dsbDestroy(rbuf);
	return retval;
}
Example #9
0
static int
ehlo(dsocket *sd, const char *domain)
{
	int retval;
	dstrbuf *rbuf = DSB_NEW;

	if (writeResponse(sd, "EHLO %s\r\n", domain) < 0) {
		smtpSetErr("Lost connection to SMTP server");
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("\r\n--> EHLO %s\r\n", domain);
	fflush(stdout);
#endif

	retval = readResponse(sd, rbuf);
	if (retval != 250) {
		if (retval != ERROR) {
			smtpSetErr(rbuf->str);
		}
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("\r\n<-- %s", rbuf->str);
	fflush(stdout);
#endif

end:
	dsbDestroy(rbuf);
	return retval;
}
Example #10
0
// download a file, i.e., get it from remote FS
INT ExecGet(PAIO_DEV sock, PSERVICE_CONTEXT sc) {
	int status = STATUS_OK;
	HANDLE hFile= NULL;

	int fileSize = getFileSize(sc->req.fileName);
	if (fileSize == -1) status = FS_ERROR;
	else {
		hFile = CreateFileA(sc->req.fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile == INVALID_HANDLE_VALUE) {
			printf("Error %d opening file %s!\n", GetLastError(), sc->req.fileName);
			status = FS_ERROR;
		}
	}

	// Start send Response
	_itoa_s(status, sc->resp.status, 10);
	_itoa_s(fileSize, sc->resp.dataSize, 10);
	if (!writeResponse(sock->dev, &sc->resp)) status = IO_ERROR;

	if (status == STATUS_OK)
		status = downloadFile(hFile, (SOCKET) sock->dev, fileSize);
	CloseHandle(hFile);
	
	return status;
}
Example #11
0
void ClientConnection::loop() {
	if (state == FREE_STATE) {
		return;
	}

	if (client.connected()) {
		switch(state) {
		case READ_HEADER_STATE:
		case READ_REQUEST_STATE:
			readRequest();
			break;

		case WRITE_HEADER_STATE:
		case WRITE_RESPONSE_STATE:
			writeResponse();
			break;
		}

		if (millis() - lastUse > INACTIVITY_TIMEOUT_MS) {
			Serial.printlnf("%d: inactivity timeout", clientId);
			client.stop();
			clear();
		}
	}
	else {
		Serial.printlnf("%d: client disconnected", clientId);
		client.stop();
		clear();
	}
}
Example #12
0
void DelayedResponse::onTimerOut() {
    if (!m_hasResponded) {
        writeResponse(jsonClient()->createError(
            "DelayedResponseTimeOut",
            QString::fromUtf8("Timeout for non response: %2")
                .arg(staticMetaObject.className())));
    }
}
qint64 TActionContext::writeResponse(int statusCode, THttpResponseHeader &header, const QByteArray &contentType, QIODevice *body, qint64 length)
{
    T_TRACEFUNC("statusCode:%d  contentType:%s  length:%s", statusCode, contentType.data(), qPrintable(QString::number(length)));

    header.setStatusLine(statusCode, THttpUtility::getResponseReasonPhrase(statusCode));
    if (!contentType.isEmpty())
        header.setContentType(contentType);

    return writeResponse(header, body, length);
}
Example #14
0
INT ExecList(PAIO_DEV sock, PSERVICE_CONTEXT sc) {
	 
	printf("command not implemented: files list\n");
	
	_itoa_s(INTERNAL_ERROR, sc->resp.status, 10);
	 
	if (!writeResponse(sock->dev, &sc->resp)) 
		return IO_ERROR;
	 
	return STATUS_OK;
}
qint64 TActionContext::writeResponse(THttpResponseHeader &header, QIODevice *body, qint64 length)
{
    T_TRACEFUNC("length:%s", qPrintable(QString::number(length)));

    header.setContentLength(length);
    header.setRawHeader("Server", "TreeFrog server");
    header.setCurrentDate();

    // Write data
    return writeResponse(header, body);
}
Example #16
0
void DragNDropResponse::execute(int call) {
    switch (call) {
    case 0: // pre-phase : ensure widgets are painted in order to mapToGlobal to work
        m_src->repaint ();
        m_dest->repaint ();
        setInterval(100);
        break;
    case 1: // 1: press event
        m_srcPosGlobal = m_src->mapToGlobal(m_srcPos);
        m_destPosGlobal = m_dest->mapToGlobal(m_destPos);

        qApp->postEvent(m_src,
            new QMouseEvent(QEvent::MouseButtonPress,
                            m_srcPos,
                            m_srcPosGlobal,
                            Qt::LeftButton,
                            Qt::NoButton,
                            Qt::NoModifier));
        break;
    case 2: { // 2: WaitForDragStart
        setInterval(qApp->startDragTime() + 20);
        break;
    }
    case 3: { // 3: do some move event
        setInterval(0);
        QList<QPoint> moves;
        calculate_drag_n_drop_moves(moves, m_srcPosGlobal, m_destPosGlobal, 4);
        foreach (const QPoint & move, moves) {
            QWidget * widgetUnderCursor = qApp->widgetAt(move);
            if (widgetUnderCursor) {
                qApp->postEvent(widgetUnderCursor,
                    new QMouseEvent(QEvent::MouseMove,
                                    widgetUnderCursor->mapFromGlobal(move),
                                    move,
                                    Qt::LeftButton,
                                    Qt::NoButton,
                                    Qt::NoModifier));
            }
        }
        break;
    }
    case 4: { // 4: now release the button
        qApp->postEvent(m_dest,
            new QMouseEvent(QEvent::MouseButtonRelease,
                            m_destPos,
                            m_destPosGlobal,
                            Qt::LeftButton,
                            Qt::NoButton,
                            Qt::NoModifier));
    }
    case 5: // and reply
        writeResponse(QtJson::JsonObject());
        break;
    }
Example #17
0
void writeFileToResponse(int channelfd, char * fname){

	char buffer[128];
  memset(buffer, 0, 128);
	getcwd(buffer, 128);
	strcat(buffer, fname);

	printf("opening: %s\n", buffer);
	FILE *data = fopen(buffer, "r");

	if(data == NULL){
		perror("Error, 404");
		writeResponse(channelfd, "HTTP/1.1 404 NOT FOUND\n\n");
		getcwd(buffer, 128);
		strcat(buffer, "/fserv/404.html");
		printf("404: %s\n", buffer);
		data = fopen(buffer, "r");
    if(data == NULL){
      perror("Error, 404, you're really f****d now");
      exit(-1);
    }
	} else {
		writeResponse(channelfd, "HTTP/1.1 200 OK\n\n");
	}
	int i = 0;
	char c = fgetc(data);
	while( c != EOF){
		buffer[i] = c;
		i++;
		if( i == 127){
			buffer[i] = '\0';
			i = 0;
			writeResponse(channelfd, buffer);
		}
		c = fgetc(data);
	}

	buffer[i] = '\0';
	writeResponse(channelfd, buffer);
  fclose(data);
}
Example #18
0
File: server.c Project: Bipsy/Linux
void service(int server_fd) {
    for(;;) {
        Message msg = readRequest(server_fd);
        if (strncmp(msg.type, PIPE, 4) == 0) {
            char client_pipe[BUF_LEN];
            strncpy(client_pipe, msg.msg_buf, BUF_LEN);
            int client_fd = open(client_pipe, O_WRONLY);
            writeResponse(client_fd, OK, 2);
        } else {
            printf("Couldn't decipher message\n");
        }
    }
}
Example #19
0
bool Nuria::RestfulHttpNode::invokeMatchNow (Callback callback, const QVariantList &arguments, HttpClient *client) {
	int resultType = callback.returnType ();
	QVariant result = callback.invoke (arguments);
	
	if ((resultType == QMetaType::QVariant && !result.isValid ()) ||
	    (resultType != QMetaType::Void && resultType != 0 &&
	     resultType != result.userType ())) {
	        return false;
	}
	
	// Send response
	return writeResponse (result, client);
}
Example #20
0
void ShortcutResponse::execute(int call) {
    if (!m_target) {
        // this can happen when target is deleted for example in
        // step 2, after a press event has been sent. We do not
        // want it to be an error.
        writeResponse(QtJson::JsonObject());
        return;
    }
    if (call == 0) {
        m_target->repaint();
        setInterval(100);
    } else if (call == 1) {
        m_target->grabKeyboard();
    } else if (call == 2) {
        // taken from
        // http://stackoverflow.com/questions/14283764/how-can-i-simulate-emission-of-a-standard-key-sequence
        for (int i = 0; i < static_cast<int>(m_binding.count()); ++i) {
            uint key = m_binding[i];
            Qt::KeyboardModifiers modifiers =
                static_cast<Qt::KeyboardModifiers>(key &
                                                   Qt::KeyboardModifierMask);
            key = key & ~Qt::KeyboardModifierMask;
            QTest::keyPress(m_target, static_cast<Qt::Key>(key), modifiers);
        }
    } else if (call == 3) {
        for (int i = 0; i < static_cast<int>(m_binding.count()); ++i) {
            uint key = m_binding[i];
            Qt::KeyboardModifiers modifiers =
                static_cast<Qt::KeyboardModifiers>(key &
                                                   Qt::KeyboardModifierMask);
            key = key & ~Qt::KeyboardModifierMask;
            QTest::keyRelease(m_target, static_cast<Qt::Key>(key), modifiers);
        }
    } else if (call == 4) {
        m_target->releaseKeyboard();
        writeResponse(QtJson::JsonObject());
    }
}
qint64 TActionContext::writeResponse(THttpResponseHeader &header, QIODevice *body, qint64 length)
{
    T_TRACEFUNC("length:%s", qPrintable(QString::number(length)));

    header.setContentLength(length);
    header.setRawHeader("Server", "TreeFrog server");
# if QT_VERSION >= 0x040700
    QDateTime utc = QDateTime::currentDateTimeUtc();
#else
    QDateTime utc = QDateTime::currentDateTime().toUTC();
#endif
    header.setRawHeader("Date", QLocale(QLocale::C).toString(utc, QLatin1String("ddd, dd MMM yyyy hh:mm:ss 'GMT'")).toLatin1());

    // Write data
    return writeResponse(header, body);
}
void Connection::startCommand() {
  m_commandWaiting = false;
  if (m_pageSuccess) {
    m_command = createCommand(m_commandName.toAscii().constData());
    if (m_command) {
      connect(m_command,
              SIGNAL(finished(Response *)),
              this,
              SLOT(finishCommand(Response *)));
      m_command->start(m_arguments);
    } else {
      QString failure = QString("Unknown command: ") +  m_commandName + "\n";
      writeResponse(new Response(false, failure));
    }
    m_commandName = QString();
  } else {
Example #23
0
// upload a file, i.e. put it on remote fs
static INT ExecPut(PAIO_DEV sock, PSERVICE_CONTEXT sc) {
	int fileSize = atoi(sc->req.fileSize);
	
	HANDLE hFile = CreateFileA(sc->req.fileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if (hFile == INVALID_HANDLE_VALUE) {
		printf("Error %d creating file %s!\n", GetLastError(), sc->req.fileName);
		return FS_ERROR;
	}
	
	int status = uploadFile((SOCKET) sock->dev, hFile, fileSize);
	CloseHandle(hFile);
	
	_itoa_s(status, sc->resp.status, 10);	
	if (!writeResponse(sock->dev, &sc->resp)) return IO_ERROR;
	return STATUS_OK;
}
void Connection::startCommand() {
  m_commandWaiting = false;
  if (m_pageSuccess) {
    m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData());
    if (m_command) {
      connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
      connect(m_command,
              SIGNAL(finished(Response *)),
              this,
              SLOT(finishCommand(Response *)));
      m_command->start(m_arguments);
    } else {
      QString failure = QString("[Capybara WebKit] Unknown command: ") +  m_commandName + "\n";
      writeResponse(new Response(false, failure));
    }
    m_commandName = QString();
  } else {
Example #25
0
// sends a write chunk request to client
// returns -1 on error
int network_write_chunk(int32_t id, int fd, int file_id, int node_id, int stripe_id,
 int chunk_num, int offset, void* buf, int count) {

  std::string name = chunk_id_formatter(file_id, node_id, stripe_id, chunk_num);

  if (!chunk_map.count(name)) { // name is not yet in the map

    chunk_map[name] = (char*) malloc(MAX_CHUNK);
  }

  char* base = &((chunk_map[name])[offset]);
  memcpy(base, buf, count);

  WriteChunkResponse writeResponse(id, fd, file_id, stripe_id, chunk_num, offset, count);
  write_response_handler(&writeResponse);

  return 1;
}
Example #26
0
ShortcutResponse::ShortcutResponse(JsonClient * client,
                                   const QtJson::JsonObject & command)
    : DelayedResponse(client, command), m_target(NULL) {
    if (command.contains("oid")) {
        WidgetLocatorContext<QWidget> ctx(static_cast<Player *>(jsonClient()),
                                          command, "oid");
        if (ctx.hasError()) {
            writeResponse(ctx.lastError);
            return;
        }
        m_target = ctx.widget;
    } else {
        m_target = qApp->activeWindow();
    }
    if (m_target) {
        connect(m_target, SIGNAL(destroyed()), this, SLOT(on_target_deleted()));
    }
    m_binding = QKeySequence::fromString(command["keysequence"].toString());
}
qint64 TActionContext::writeResponse(int statusCode, THttpResponseHeader &header)
{
    T_TRACEFUNC("statusCode:%d", statusCode);
    QByteArray body;
    if (statusCode >= 400) {
        QFile html(Tf::app()->publicPath() + QString::number(statusCode) + ".html");
        if (html.exists() && html.open(QIODevice::ReadOnly)) {
            body = html.readAll();
            html.close();
        }
    }
    if (body.isEmpty()) {
        body  = "<html><body>";
        body += THttpUtility::getResponseReasonPhrase(statusCode);
        body += " (";
        body += QByteArray::number(statusCode);
        body += ")</body></html>";
    }

    QBuffer buf(&body);
    return writeResponse(statusCode, header, "text/html", &buf, body.length());
}
Example #28
0
static int
helo(dsocket *sd, const char *domain)
{
	int retval;
	dstrbuf *rbuf = DSB_NEW;

	/*
	 * We will be calling this function after ehlo() has already
	 * been called.  Since ehlo() already grabs the header, go
	 * straight into sending the HELO
	 */
	if (writeResponse(sd, "HELO %s\r\n", domain) < 0) {
		smtpSetErr("Lost connection to SMTP server");
		retval = ERROR;
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("--> HELO\n");
	fflush(stdout);
#endif

	retval = readResponse(sd, rbuf);
	if (retval != 250) {
		if (retval != ERROR) {
			smtpSetErr(rbuf->str);
		}
		goto end;
	}

#ifdef DEBUG_SMTP
	printf("<-- %s\n", rbuf->str);
	fflush(stdout);
#endif

end:
	dsbDestroy(rbuf);
	return retval;
}
Example #29
0
/**
 * Let's the SMTP server know it's the end of the data stream.
 *
 * Params
 * 	sd - Socket descriptor
 *
 * Return
 * 	- ERROR
 * 	- SUCCESS
 */
int 
smtpEndData(dsocket *sd)
{
	int retval=ERROR;
	dstrbuf *rbuf = DSB_NEW;

	printProgress("Ending Data...");
	if (writeResponse(sd, "\r\n.\r\n") != ERROR) {
		retval = readResponse(sd, rbuf);
		if (retval != 250) {
			if (retval != ERROR) {
				smtpSetErr(rbuf->str);
				retval = ERROR;
			}
		}
	} else {
		smtpSetErr("Lost Connection with SMTP server: smtpEndData()");
		retval = ERROR;
	}

	dsbDestroy(rbuf);
	return retval;
}
Example #30
0
int
smtpStartTls(dsocket *sd)
{
        int retval=SUCCESS;
#ifdef HAVE_LIBSSL
        dstrbuf *sb=DSB_NEW;

	printProgress("Starting TLS Communications...");
        if (writeResponse(sd, "STARTTLS\r\n") < 0) {
                smtpSetErr("Lost connection to SMTP Server");
                retval = ERROR;
                goto end;
        }

#ifdef DEBUG_SMTP
	printf("--> STARTTLS\n");
	fflush(stdout);
#endif

        retval = readResponse(sd, sb);
        if (retval != 220) {
                smtpSetErr(sb->str);
                retval = ERROR;
        }

#ifdef DEBUG_SMTP
	printf("<-- %s\n", sb->str);
	fflush(stdout);
#endif

end:
        dsbDestroy(sb);
#else
	sd = sd;
#endif
        return retval;
}