1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/tracing/Logger.hpp>
10 #include <anna/core/functions.hpp>
12 #include <anna/http/wims20/Abstract.hpp>
17 http::wims20::Abstract::Abstract(const char* whatis, const std::string& domain, const std::string& path) :
20 a_path = createString(path);
25 http::wims20::Abstract::Abstract(const char* whatis, const std::string& domain) :
34 http::wims20::Abstract::~Abstract() {
35 destroyString(a_path);
41 /* Calcula la parte fija de la URI, se invoca desde el constructor. */
42 const string& http::wims20::Abstract::calculeFixedPart()
43 throw(RuntimeException) {
44 if(a_serviceID.empty() == true) {
45 string msg(asString());
46 msg += " | ServiceID can not be NULL";
47 throw RuntimeException(msg, ANNA_FILE_LOCATION);
50 if(a_guid.empty() == true) {
51 string msg(asString());
52 msg += " | GUID can not be NULL";
53 throw RuntimeException(msg, ANNA_FILE_LOCATION);
56 if(a_fixedPart.empty() == false)
59 calculeShortFixedPart();
60 appendWithSlash(a_fixedPart, a_serviceID);
61 appendWithSlash(a_fixedPart, a_guid);
65 const string& http::wims20::Abstract::calculeShortFixedPart()
66 throw(RuntimeException) {
67 string::size_type pos = a_domain.find("http://");
69 if(pos == string::npos) {
70 a_fixedPart = "http://";
71 a_fixedPart += a_domain;
74 string msg("Domain '");
76 msg += "' is not valid";
77 throw RuntimeException(msg, ANNA_FILE_LOCATION);
80 a_fixedPart = a_domain;
84 appendWithSlash(a_fixedPart, *a_path);
89 void http::wims20::Abstract::other_level_add(const std::string& otherLevel)
90 throw(RuntimeException) {
91 if(a_otherLevels == NULL)
92 a_otherLevels = new other_level_container;
94 a_otherLevels->push_back(createString(otherLevel));
96 string msg("http::wims20::Abstract::other_level_add | Level: ");
98 Logger::debug(msg, ANNA_FILE_LOCATION);
103 void http::wims20::Abstract::clearOtherLevels()
105 if(hasOtherLevels()) {
106 for(other_level_iterator ii = other_level_begin(), maxii = other_level_end(); ii != maxii; ii ++)
107 destroyString(otherLevel(ii));
109 a_otherLevels->clear();
113 void http::wims20::Abstract::parameter_set(const std::string& name, const std::string& value)
114 throw(RuntimeException) {
117 if(a_parameters == NULL)
118 a_parameters = new parameter_container;
120 for(parameter_iterator ii = parameter_begin(), maxii = parameter_end(); ii != maxii; ii ++) {
121 if(*parameter_name(ii) == name) {
122 *parameter_value(ii) = value;
128 if(exists == false) {
129 string* paramName = createString(name);
130 string* paramValue = createString(value);
131 parameter_pkv item(paramName, paramValue);
132 a_parameters->push_back(item);
136 string msg("http::wims20::Abstract::parameter_set | Name: ");
141 msg += functions::asString(!exists);
142 Logger::debug(msg, ANNA_FILE_LOCATION);
146 void http::wims20::Abstract::clearParameters()
148 if(hasParameters()) {
149 for(parameter_iterator ii = parameter_begin(), maxii = parameter_end(); ii != maxii; ii ++) {
150 destroyString(parameter_name(ii));
151 destroyString(parameter_value(ii));
154 a_parameters->clear();
158 string http::wims20::Abstract::asString() const
160 string result("http::wims20::");
162 result += " { Domain: ";
164 result += " | Path: ";
165 result += (a_path == NULL) ? "<null>" : a_path->c_str();
166 result += " | ServiceID: ";
167 result += a_serviceID;
168 result += " | GUID: ";
170 result += " | OtherLevels:";
172 if(hasOtherLevels() == true) {
173 for(const_other_level_iterator ii = other_level_begin(), maxii = other_level_end(); ii != maxii; ii ++) {
175 result += otherLevel(ii);
180 result += " | Parameters:";
182 if(hasParameters() == true) {
183 for(const_parameter_iterator ii = parameter_begin(), maxii = parameter_end(); ii != maxii; ii ++) {
185 result += parameter_name(ii);
187 result += parameter_value(ii);
192 return result += " }";
196 void http::wims20::Abstract::appendWithSlash(std::string& target, const std::string& other)
198 const char* str = target.c_str();
200 if(str [anna_strlen(str) - 1] != '/')