X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzconn.cpp;h=5abb963bb3e2a6b474d7a3703ea5bb3c0fa19e40;hb=6716ec7295c7361a205cb2dbcd5c8e3af64e8df6;hp=d5d4c85ac8d6e75e628fd153ac70e5f530894636;hpb=88e190489a5c483e5b860048aeebde41bf262962;p=yazpp-moved-to-github.git diff --git a/zoom/zconn.cpp b/zoom/zconn.cpp index d5d4c85..5abb963 100644 --- a/zoom/zconn.cpp +++ b/zoom/zconn.cpp @@ -1,37 +1,59 @@ -// $Header: /home/cvsroot/yaz++/zoom/zconn.cpp,v 1.4 2002-11-30 22:33:21 mike Exp $ - // Z39.50 Connection class +#if HAVE_CONFIG_H +#include +#endif #include "zoom.h" namespace ZOOM { - connection::connection(const string &hostname, int portnum) { - const char *line_printer_size_hostname = hostname.c_str(); - //###cerr << "opening " << hostname << ":" << portnum << "\n"; - c = ZOOM_connection_new(line_printer_size_hostname, portnum); - //###cerr << "opened, got " << c << "\n"; - - int errcode; - const char *errmsg; // unused: carries same info as `errcode' - const char *addinfo; - if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) { - //###cerr << "oops: no connect, errcode=" << errcode << "\n"; - throw bib1Exception(errcode, addinfo); - } + connection::connection() { + ZOOM_options o = ZOOM_options_create(); + c = ZOOM_connection_create(o); + } + + void connection::connect(const std::string &hostname, int portnum) { + const char *line_printer_size_hostname = hostname.c_str(); + //###cerr << "opening " << hostname << ":" << portnum << "\n"; + ZOOM_connection_connect(c, line_printer_size_hostname, portnum); + //###cerr << "opened\n"; + + int errcode; + const char *errmsg; // unused: carries same info as `errcode' + const char *addinfo; + if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) { + //###cerr << "oops: no connect, errcode=" << errcode << "\n"; + throw bib1Exception(errcode, addinfo); + } } - string connection::option(const string &key) const { - return ZOOM_connection_option_get(c, key.c_str()); + connection::connection(const std::string &hostname, int portnum) { + ZOOM_options o = ZOOM_options_create(); + c = ZOOM_connection_create(o); + connect(hostname, portnum); } - bool connection::option(const string &key, const string &val) { - // No way to tell whether ZOOM_connection_option_set() accepts key - ZOOM_connection_option_set(c, key.c_str(), val.c_str()); - return true; + std::string connection::option(const std::string &key) const { + const char* val = ZOOM_connection_option_get(c, key.c_str()); + return (val) ? val : std::string(); + } + + bool connection::option(const std::string &key, const std::string &val) { + // No way to tell whether ZOOM_connection_option_set() accepts key + ZOOM_connection_option_set(c, key.c_str(), val.c_str()); + return true; } connection::~connection() { - ZOOM_connection_destroy(c); + ZOOM_connection_destroy(c); } } +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +