[7] | 1 | |
---|
| 2 | /* |
---|
| 3 | Copyright 2013 Willem Vermin, SURFsara |
---|
| 4 | |
---|
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 6 | you may not use this file except in compliance with the License. |
---|
| 7 | You may obtain a copy of the License at |
---|
| 8 | |
---|
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | |
---|
| 11 | Unless required by applicable law or agreed to in writing, software |
---|
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | See the License for the specific language governing permissions and |
---|
| 15 | limitations under the License. |
---|
| 16 | */ |
---|
| 17 | #ifndef WREQUEST_H |
---|
| 18 | #define WREQUEST_H |
---|
| 19 | #include <string> |
---|
| 20 | #include <iostream> |
---|
| 21 | #include <curl/curl.h> |
---|
| 22 | #include "wutils.h" |
---|
| 23 | |
---|
| 24 | class messageclass |
---|
| 25 | { |
---|
| 26 | private: |
---|
| 27 | std::string protocol; |
---|
| 28 | std::string whoami; |
---|
| 29 | std::string pool; |
---|
| 30 | std::string command; |
---|
| 31 | std::string multi; |
---|
| 32 | std::string value; |
---|
| 33 | |
---|
| 34 | public: |
---|
| 35 | //constructor |
---|
| 36 | messageclass() |
---|
| 37 | { |
---|
| 38 | this->protocol = " "; |
---|
| 39 | this->whoami = " "; |
---|
| 40 | this->pool = " "; |
---|
| 41 | this->command = " "; |
---|
| 42 | this->multi = " "; |
---|
| 43 | this->value = " "; |
---|
| 44 | } |
---|
| 45 | void set_protocol(const std::string &p){ this->protocol = p; } |
---|
| 46 | std::string get_protocol(void) { return this->protocol; } |
---|
| 47 | |
---|
| 48 | void set_whoami(const std::string &u) { this->whoami = u; } |
---|
| 49 | std::string get_whoami(void) { return this->whoami; } |
---|
| 50 | |
---|
| 51 | void set_pool(const std::string &p) { this->pool = p; } |
---|
| 52 | std::string get_pool(void) { return this->pool; } |
---|
| 53 | |
---|
| 54 | void set_command(const std::string &c) { this->command = c; } |
---|
| 55 | std::string get_command(void) { return this->command; } |
---|
| 56 | |
---|
| 57 | void set_multi(const std::string &m) { this->multi = m; } |
---|
| 58 | std::string get_multi(void) { return this->multi; } |
---|
| 59 | |
---|
| 60 | void set_value(const std::string &v) { this->value = v; } |
---|
| 61 | std::string get_value(void) { return this->value; } |
---|
| 62 | |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | class wrequest |
---|
| 66 | { |
---|
| 67 | private: |
---|
| 68 | CURL *curl; |
---|
| 69 | |
---|
| 70 | std::string configfilename; |
---|
| 71 | std::string configdirname; |
---|
| 72 | std::string config; |
---|
| 73 | void set_configfilename(void); |
---|
| 74 | |
---|
| 75 | std::string serveraddress; |
---|
| 76 | std::string serverurl; |
---|
| 77 | int port; |
---|
| 78 | |
---|
| 79 | messageclass message; |
---|
| 80 | void compose_message(std::string &m); |
---|
| 81 | int get_answer(void); |
---|
| 82 | std::string data; |
---|
| 83 | bool debugging; |
---|
| 84 | |
---|
| 85 | public: |
---|
| 86 | //constructor |
---|
| 87 | wrequest(void); |
---|
| 88 | |
---|
| 89 | //destructor |
---|
| 90 | ~wrequest(void); |
---|
| 91 | |
---|
| 92 | static const unsigned int config_size = 8; |
---|
| 93 | |
---|
| 94 | std::string get_config(void) { return this->config; }; |
---|
| 95 | |
---|
| 96 | int set_serverurl(const std::string &u); |
---|
| 97 | std::string get_serverurl(void) { return this->serverurl; } |
---|
| 98 | |
---|
| 99 | void set_port(int); |
---|
| 100 | int get_port(void); |
---|
| 101 | |
---|
| 102 | int read_config(void); |
---|
| 103 | int write_config(void); |
---|
| 104 | |
---|
| 105 | void set_protocol(const std::string &p){ this->message.set_protocol(p); } |
---|
| 106 | std::string get_protocol(void) { return this->message.get_protocol(); } |
---|
| 107 | |
---|
| 108 | void set_whoami(const std::string &u) { this->message.set_whoami(u); } |
---|
| 109 | std::string get_whoami(void) { return this->message.get_whoami(); } |
---|
| 110 | |
---|
| 111 | void set_pool(const std::string &p) { this->message.set_pool(p); } |
---|
| 112 | std::string get_pool(void) { return this->message.get_pool(); } |
---|
| 113 | |
---|
| 114 | void set_command(const std::string &c) { this->message.set_command(c); } |
---|
| 115 | std::string get_command(void) { return this->message.get_command(); } |
---|
| 116 | |
---|
| 117 | void set_multi(const std::string &m) { this->message.set_multi(m); } |
---|
| 118 | std::string get_multi(void) { return this->message.get_multi(); } |
---|
| 119 | |
---|
| 120 | void set_value(const std::string &v) { this->message.set_value(v); } |
---|
| 121 | std::string get_value(void) { return this->message.get_value(); } |
---|
| 122 | |
---|
| 123 | void set_debug(void) { this->debugging = 1; } |
---|
| 124 | void unset_debug(void) { this->debugging = 0; } |
---|
| 125 | |
---|
| 126 | int send_message(std::string &body,std::string &header); |
---|
| 127 | |
---|
| 128 | }; |
---|
| 129 | #endif |
---|