summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
b7d95f9)
arbitrario a otro a traves de un stringstream (similar a String::to()).
- Se usa la nueva funcion en varios lugares.
+ /**
+ * Convierte de un tipo a otro (de p1 a p2) a través de un stringstream.
+ *
+ * \param p1 Parámetro origen.
+ * \param p1 Parámetro destino, al que se quiere convertir.
+ *
+ * \return Referencia a p2.
+ */
+ template < class T1, class T2 > static T2& to(const T1& p1, T2& p2) {
+ std::stringstream ss(p1);
+ ss << p1;
+ ss >> p2;
+ return p2;
+ }
+
/// Conexión.
class String: public std::string {
/// Conexión.
class String: public std::string {
cerr << __FILE__ << ": version = " << version << " | body ("
<< _body.length() << ") = " << _body << endl;
#endif // DEBUG
cerr << __FILE__ << ": version = " << version << " | body ("
<< _body.length() << ") = " << _body << endl;
#endif // DEBUG
+ headers["Accept-Ranges"] = "bytes";
set_body(_body);
}
void HTTPMessage::set_body(const string& _body) {
body = _body;
set_body(_body);
}
void HTTPMessage::set_body(const string& _body) {
body = _body;
- if (body.length()) {
- stringstream ss; // TODO ver forma mas linda de convertir
- ss << (body.length()); // FIXME No se por que tengo que sumarle 1.
- headers["Accept-Ranges"] = "bytes";
- headers["Content-Length"] = ss.str();
- }
+ headers["Content-Length"] = String().from(body.length());
}
const string& HTTPMessage::get_body(void) const {
}
const string& HTTPMessage::get_body(void) const {
String sbuf(buf);
sbuf.trim();
if (sbuf.length()) {
String sbuf(buf);
sbuf.trim();
if (sbuf.length()) {
- stringstream ss;
- ss << sbuf;
ss >> m.headers;
// Fin de las cabeceras.
} else {
// Hay Content-Length, entonces hay body (no respeta RFC AFAIK).
if (m.headers.find("Content-Length") != m.headers.end()) {
ss >> m.headers;
// Fin de las cabeceras.
} else {
// Hay Content-Length, entonces hay body (no respeta RFC AFAIK).
if (m.headers.find("Content-Length") != m.headers.end()) {
- stringstream ss(m.headers["Content-Length"]);
+ to(m.headers["Content-Length"], size);
char* const buf2 = new char[size+1];
if (is.readsome(buf2, size)) {
m.body = buf2;
char* const buf2 = new char[size+1];
if (is.readsome(buf2, size)) {
m.body = buf2;
-/*
-template < class T > T& String::to(T& p) const {
- stringstream ss(*this);
- ss >> p;
- return p;
-}
-
-template < class T > String& String::from(const T& p) {
- stringstream ss;
- ss << p;
- ss >> (*this);
- return *this;
-}
-*/
-
} // namespace Server
} // namespace PlaQui
} // namespace Server
} // namespace PlaQui
#include "plaqui/server/controlclient.h"
#include "plaqui/server/string.h"
#include <iostream>
#include "plaqui/server/controlclient.h"
#include "plaqui/server/string.h"
#include <iostream>
#include <exception>
#include <vector>
#include <exception>
#include <vector>
// Obtengo host.
host = argv[1];
}
// Obtengo host.
host = argv[1];
}
Connection::Port port = 7522;
if (argc > 2) {
Connection::Port port = 7522;
if (argc > 2) {
- // Obtengo puerto.
- stringstream str(argv[2]);
- str >> port;
//
#include "plaqui/server/receiver.h"
//
#include "plaqui/server/receiver.h"
+#include "plaqui/server/string.h"
#include <exception>
using namespace std;
#include <exception>
using namespace std;
Connection::Port port = 7528;
if (argc > 1) {
// Obtengo puerto.
Connection::Port port = 7528;
if (argc > 1) {
// Obtengo puerto.
- stringstream str(argv[1]);
- str >> port;
}
string host = "localhost";
if (argc > 2) {
}
string host = "localhost";
if (argc > 2) {
#include "plaqui/server/connection.h"
#include "plaqui/server/server.h"
#include "plaqui/server/connection.h"
#include "plaqui/server/server.h"
+#include "plaqui/server/string.h"
#include <socket++/sockinet.h>
#include <iostream>
#include <socket++/sockinet.h>
#include <iostream>
#include <exception>
using namespace std;
#include <exception>
using namespace std;
// Si tiene 2 parámetros.
if (argc > 2) {
// Obtengo puerto.
// Si tiene 2 parámetros.
if (argc > 2) {
// Obtengo puerto.
- stringstream ss(argv[2]);
- ss >> port;