Skip to content

Commit

Permalink
Merge pull request #316 from Woazboat/build_system_cleanup
Browse files Browse the repository at this point in the history
Build system/include cleanup + some more tests
  • Loading branch information
mmd-osm authored Nov 28, 2023
2 parents d2d6114 + b4677c6 commit 63a06e4
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 81 deletions.
4 changes: 4 additions & 0 deletions include/cgimap/backend/apidb/common_pgsql_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ void extract_changesets(
const std::chrono::system_clock::time_point &now,
bool include_changeset_discussions);

// parses psql array based on specs given
// https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO
std::vector<std::string> psql_array_to_vector(std::string str);

#endif /* CGIMAP_BACKEND_APIDB_COMMON_PGSQL_SELECTION_HPP */
8 changes: 2 additions & 6 deletions include/cgimap/data_selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

#include "cgimap/types.hpp"
#include "cgimap/output_formatter.hpp"
#include "cgimap/backend/apidb/transaction_manager.hpp"

#include <chrono>
#include <memory>
#include <sstream>
#include <vector>

class Transaction_Owner_Base;

/**
* represents a selected set of data which can be written out to
* an output_formatter and manipulated by a nice set of commands
Expand Down Expand Up @@ -192,9 +193,4 @@ class data_selection {
};
};


// parses psql array based on specs given
// https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-IO
std::vector<std::string> psql_array_to_vector(std::string str);

#endif /* DATA_SELECTION_HPP */
2 changes: 1 addition & 1 deletion include/cgimap/mime_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum type {
unspecified_type, // a "null" type, used to indicate no choice.
text_plain,
application_xml,
#ifdef HAVE_YAJL
#if HAVE_YAJL
application_json,
#endif
any_type // the "*/*" type used to mean that anything is acceptable.
Expand Down
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ libcgimap_core_la_SOURCES=\
backend.cpp \
bbox.cpp \
choose_formatter.cpp \
data_selection.cpp \
handler.cpp \
http.cpp \
logger.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/backend/apidb/changeset.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "backend/apidb/pqxx_string_traits.hpp"
#include "cgimap/backend/apidb/pqxx_string_traits.hpp"
#include "cgimap/backend/apidb/changeset.hpp"
#include "cgimap/logger.hpp"
#include "cgimap/http.hpp"
Expand Down
4 changes: 1 addition & 3 deletions src/backend/apidb/changeset_upload/node_updater.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

#include "util.hpp"

#include "cgimap/api06/changeset_upload/osmchange_tracking.hpp"
#include "cgimap/backend/apidb/changeset_upload/node_updater.hpp"
#include "cgimap/backend/apidb/pqxx_string_traits.hpp"
Expand All @@ -9,6 +6,7 @@
#include "cgimap/http.hpp"
#include "cgimap/logger.hpp"
#include "cgimap/options.hpp"
#include "cgimap/util.hpp"


#include <algorithm>
Expand Down
3 changes: 1 addition & 2 deletions src/backend/apidb/changeset_upload/relation_updater.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "util.hpp"

#include "cgimap/api06/changeset_upload/osmchange_tracking.hpp"
#include "cgimap/backend/apidb/changeset_upload/relation_updater.hpp"
#include "cgimap/backend/apidb/pqxx_string_traits.hpp"
#include "cgimap/backend/apidb/utils.hpp"
#include "cgimap/http.hpp"
#include "cgimap/logger.hpp"
#include "cgimap/util.hpp"

#include <algorithm>
#include <iterator>
Expand Down
3 changes: 1 addition & 2 deletions src/backend/apidb/changeset_upload/way_updater.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "util.hpp"

#include "cgimap/api06/changeset_upload/osmchange_tracking.hpp"
#include "cgimap/backend/apidb/changeset_upload/way_updater.hpp"
#include "cgimap/backend/apidb/pqxx_string_traits.hpp"
#include "cgimap/backend/apidb/utils.hpp"
#include "cgimap/http.hpp"
#include "cgimap/logger.hpp"
#include "cgimap/options.hpp"
#include "cgimap/util.hpp"

#include <algorithm>
#include <cassert>
Expand Down
53 changes: 53 additions & 0 deletions src/backend/apidb/common_pgsql_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,56 @@ void extract_changesets(
elem, tags, include_changeset_discussions, comments, now);
}
}

std::vector<std::string> psql_array_to_vector(std::string str) {
std::vector<std::string> strs;
std::ostringstream value;
bool quotedValue = false;
bool escaped = false;
bool write = false;

if (str == "{NULL}" || str == "")
return strs;

for (unsigned int i=1; i<str.size(); i++) {
if (str[i]==',') {
if (quotedValue) {
value<<",";
} else {
write = true;
}
} else if (str[i]=='\"') {
if (escaped) {
value << "\"";
escaped = false;
} else if (quotedValue) {
quotedValue=false;
} else {
quotedValue = true;
}
} else if (str[i]=='\\'){
if (escaped) {
value << "\\";
escaped = false;
} else {
escaped = true;
}
} else if (str[i]=='}') {
if(quotedValue){
value << "}";
} else {
write = true;
}
} else {
value<<str[i];
}

if (write) {
strs.push_back(value.str());
value.str("");
value.clear();
write=false;
}
}
return strs;
}
6 changes: 4 additions & 2 deletions src/choose_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "cgimap/request_helpers.hpp"
#include "cgimap/xml_writer.hpp"
#include "cgimap/xml_formatter.hpp"
#if HAVE_YAJL
#include "cgimap/json_writer.hpp"
#include "cgimap/json_formatter.hpp"
#endif
#include "cgimap/text_writer.hpp"
#include "cgimap/text_formatter.hpp"
#include "cgimap/logger.hpp"
Expand Down Expand Up @@ -115,7 +117,7 @@ struct http_accept_grammar
= lit("* / *") [_val = mime::any_type]
| lit("text/xml") [_val = mime::application_xml]
| lit("application/xml") [_val = mime::application_xml]
#ifdef HAVE_YAJL
#if HAVE_YAJL
| lit("application/json")[_val = mime::application_json]
#endif
;
Expand Down Expand Up @@ -256,7 +258,7 @@ std::unique_ptr<output_formatter> create_formatter(mime::type best_type, output_
case mime::application_xml:
return std::make_unique<xml_formatter>(std::make_unique<xml_writer>(out, true));

#ifdef HAVE_YAJL
#if HAVE_YAJL
case mime::application_json:
return std::make_unique<json_formatter>(std::make_unique<json_writer>(out, false));
#endif
Expand Down
55 changes: 0 additions & 55 deletions src/data_selection.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions src/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct json_writer::pimpl_ {
// so seems best to be on the safe side.
yajl_gen gen;

#ifdef HAVE_YAJL2
#if HAVE_YAJL2
yajl_alloc_funcs alloc_funcs;
#else
yajl_gen_config config;
Expand All @@ -36,7 +36,7 @@ static void wrap_write(void *context, const char *str, unsigned int len) {

json_writer::json_writer(output_buffer &out, bool indent)
: pimpl(std::make_unique<pimpl_>()), out(out) {
#ifdef HAVE_YAJL2
#if HAVE_YAJL2
pimpl->gen = yajl_gen_alloc(NULL);

#else /* older version of YAJL */
Expand All @@ -56,7 +56,7 @@ json_writer::json_writer(output_buffer &out, bool indent)
throw std::runtime_error("error creating json writer.");
}

#ifdef HAVE_YAJL2
#if HAVE_YAJL2
if (indent) {
yajl_gen_config(pimpl->gen, yajl_gen_beautify, 1);
yajl_gen_config(pimpl->gen, yajl_gen_indent_string, " ");
Expand Down
3 changes: 2 additions & 1 deletion src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <unistd.h>
#include <unistd.h>
#include <memory>

#include "cgimap/logger.hpp"
#include <fmt/core.h>
Expand Down
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if ENABLE_APIDB
#include <pqxx/pqxx>
#endif
#include <iostream>
#include <sstream>

Expand Down Expand Up @@ -395,6 +397,8 @@ int main(int argc, char **argv) {
} catch (const po::error & e) {
std::cerr << "Error: " << e.what() << "\n(\"openstreetmap-cgimap --help\" for help)" << std::endl;
return 1;

#if ENABLE_APIDB
} catch (const pqxx::sql_error &er) {
// Catch-all for query related postgres exceptions
std::cerr << "Error: " << er.what() << std::endl
Expand All @@ -408,6 +412,7 @@ int main(int argc, char **argv) {
std::cerr << "Error: " << e.base().what() << std::endl;
return 1;

#endif
#endif

} catch (const std::exception &e) {
Expand Down
4 changes: 2 additions & 2 deletions src/mime_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ string to_string(type t) {
return "text/plain";
} else if (application_xml == t) {
return "application/xml";
#ifdef HAVE_YAJL
#if HAVE_YAJL
} else if (application_json == t) {
return "application/json";
#endif
Expand All @@ -37,7 +37,7 @@ type parse_from(const std::string &name) {
t = application_xml;
} else if (name == "application/xml") {
t = application_xml;
#ifdef HAVE_YAJL
#if HAVE_YAJL
} else if (name == "application/json") {
t = application_json;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/osm_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ osm_responder::~osm_responder() = default;
list<mime::type> osm_responder::types_available() const {
list<mime::type> types;
types.push_back(mime::application_xml);
#ifdef HAVE_YAJL
#if HAVE_YAJL
types.push_back(mime::application_json);
#endif
return types;
Expand Down
2 changes: 1 addition & 1 deletion src/routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ namespace {
*/
pair<string, mime::type> resource_mime_type(const string &path) {

#ifdef HAVE_YAJL
#if HAVE_YAJL
{
std::size_t json_found = path.rfind(".json");

Expand Down
1 change: 1 addition & 0 deletions test/test_apidb_backend_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "cgimap/routes.hpp"
#include "cgimap/process_request.hpp"
#include "cgimap/backend/apidb/utils.hpp"
#include "cgimap/backend/apidb/common_pgsql_selection.hpp"

#include "test_formatter.hpp"
#include "test_database.hpp"
Expand Down
1 change: 1 addition & 0 deletions test/test_apidb_backend_oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <sys/time.h>
#include <cstdio>
#include <memory>

#include "cgimap/config.hpp"
#include "cgimap/time.hpp"
Expand Down
Loading

0 comments on commit 63a06e4

Please sign in to comment.