├── LICENSE ├── README.md ├── example ├── Makefile ├── cacert.pem ├── example ├── example.cpp ├── example.run.sh ├── example_aggTrades ├── example_aggTrades.cpp ├── example_aggTrades.run.sh ├── example_depthCache ├── example_depthCache.cpp ├── example_depthCache.run.sh ├── example_klines ├── example_klines.cpp ├── example_klines.run.sh ├── example_template ├── example_template.cpp ├── example_template.run.sh ├── example_userStream ├── example_userStream.cpp ├── example_userStream.run.sh ├── example_wapi.cpp └── run.template.sh ├── lib ├── jsoncpp-1.8.3 │ ├── include │ │ └── json │ │ │ ├── json-forwards.h │ │ │ └── json.h │ └── src │ │ └── jsoncpp.cpp ├── libbinacpp │ ├── include │ │ ├── binacpp.h │ │ ├── binacpp_logger.h │ │ ├── binacpp_utils.h │ │ └── binacpp_websocket.h │ └── lib │ │ ├── binacpp.o │ │ ├── binacpp_logger.o │ │ ├── binacpp_utils.o │ │ ├── binacpp_websocket.o │ │ ├── jsoncpp.o │ │ └── libbinacpp.so ├── libcurl-7.56.0 │ ├── include │ │ └── curl │ │ │ ├── curl.h │ │ │ ├── curlver.h │ │ │ ├── easy.h │ │ │ ├── mprintf.h │ │ │ ├── multi.h │ │ │ ├── stdcheaders.h │ │ │ ├── system.h │ │ │ └── typecheck-gcc.h │ └── lib │ │ ├── libcurl.a │ │ ├── libcurl.la │ │ ├── libcurl.so │ │ ├── libcurl.so.4 │ │ └── libcurl.so.4.5.0 └── libwebsockets-2.4.0 │ ├── include │ ├── libwebsockets.h │ ├── lws-plugin-ssh.h │ └── lws_config.h │ └── lib │ ├── libwebsockets.a │ ├── libwebsockets.so │ └── libwebsockets.so.11 └── src ├── Makefile ├── binacpp.cpp ├── binacpp.h ├── binacpp_logger.cpp ├── binacpp_logger.h ├── binacpp_utils.cpp ├── binacpp_utils.h ├── binacpp_websocket.cpp ├── binacpp_websocket.h └── readme.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018+ tensaix2j tensaix2j@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Binance C++ API 3 | 4 | #### Installation 5 | git clone https://github.com/tensaix2j/binacpp 6 | 7 | #### Dependencies 8 | 9 | jsoncpp-1.8.3 10 | libcurl-7.56.0 11 | libwebsockets-2.4.0 12 | 13 | 14 | 15 | Depended shared libraries and their headers are included in the repository's lib directory 16 | 17 | use -I to include header paths for compiler to look for headers 18 | 19 | and -L and -l for linker to link against shared libraries. 20 | 21 | libcurl_dir=../lib/libcurl-7.56.0 22 | libcurl_include=${libcurl_dir}/include 23 | libcurl_lib=${libcurl_dir}/lib 24 | 25 | jsoncpp_dir=../lib/jsoncpp-1.8.3 26 | jsoncpp_include=${jsoncpp_dir}/include 27 | jsoncpp_src=${jsoncpp_dir}/src 28 | 29 | libwebsockets_dir=../lib/libwebsockets-2.4.0 30 | libwebsockets_include=${libwebsockets_dir}/include 31 | libwebsockets_lib=${libwebsockets_dir}/lib 32 | 33 | libbinacpp_dir=../lib/libbinacpp 34 | libbinacpp_include=${libbinacpp_dir}/include 35 | libbinacpp_lib=${libbinacpp_dir}/lib 36 | 37 | 38 | 39 | . 40 | Then compile like this: 41 | 42 | 43 | g++ -I$(libcurl_include) -I$(jsoncpp_include) -I$(libwebsockets_include) -I$(libbinacpp_include) \ 44 | example.cpp \ 45 | -L$(libcurl_lib) \ 46 | -L$(libwebsockets_lib) \ 47 | -L$(libbinacpp_lib) \ 48 | -lcurl -lcrypto -lwebsockets -lbinacpp -o example 49 | 50 | 51 | 52 | 53 | 54 | And export LD\_LIBRARY\_PATH and run like this: 55 | 56 | libcurl_dir=../lib/libcurl-7.56.0 57 | libcurl_lib=${libcurl_dir}/lib 58 | 59 | libwebsockets_dir=../lib/libwebsockets-2.4.0 60 | libwebsockets_lib=${libwebsockets_dir}/lib 61 | 62 | libbinacpp_dir=../lib/libbinacpp 63 | libbinacpp_lib=${libbinacpp_dir}/lib 64 | 65 | export SSL_CERT_FILE=`pwd`/cacert.pem 66 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 67 | 68 | ./example 69 | 70 | 71 | 72 | 73 | 74 | You can refer to the following Makefile to get a better picture... 75 | 76 | https://github.com/tensaix2j/binacpp/blob/master/example/Makefile 77 | 78 | 79 | #### To Build Example 80 | 81 | cd example 82 | make example 83 | 84 | --- 85 | ## Coding with libBinaCPP 86 | 87 | #### Headers to include 88 | 89 | #include "binacpp.h" 90 | #include "binacpp_websocket.h" 91 | #include 92 | 93 | 94 | #### Init 95 | string api_key = API_KEY; 96 | string secret_key = SECRET_KEY; 97 | BinaCPP::init( api_key , secret_key ); 98 | 99 | --- 100 | #### Example : Get Server Time. 101 | 102 | Json::Value result; 103 | BinaCPP::get_serverTime( result ) ; 104 | 105 | #### Example : Get all Prices 106 | 107 | Json::Value result; 108 | BinaCPP::get_allPrices( result ); 109 | 110 | #### Example: Get price of single pair. Eg: BNBETH 111 | 112 | double bnbeth_price = BinaCPP::get_price( "BNBETH"); 113 | 114 | #### Example: Get Account 115 | 116 | Json::Value result; 117 | long recvWindow = 10000; 118 | BinaCPP::get_account( recvWindow , result ); 119 | 120 | #### Example : Get all bid/ask prices 121 | 122 | Json::Value result; 123 | BinaCPP::get_allBookTickers( result ); 124 | 125 | #### Example: Get bid/ask for single pair 126 | 127 | Json::Value result; 128 | BinaCPP::get_bookTicker("bnbeth", result ); 129 | 130 | #### Example: Get Depth of single pair 131 | 132 | Json::Value result; 133 | BinaCPP::get_depth( "ETHBTC", 5, result ) ; 134 | 135 | 136 | #### Example: Placing a LIMIT order 137 | 138 | long recvWindow = 10000; 139 | Json::Value result; 140 | BinaCPP::send_order( "BNBETH", "BUY", "LIMIT", "GTC", 20 , 0.00380000, "",0,0, recvWindow, result ); 141 | 142 | #### Example: Placing a MARKET order 143 | 144 | long recvWindow = 10000; 145 | Json::Value result; 146 | BinaCPP::send_order( "BNBETH", "BUY", "MARKET", "GTC", 20 , 0, "",0,0, recvWindow, result ); 147 | 148 | #### Example: Placing an ICEBERG order 149 | 150 | long recvWindow = 10000; 151 | Json::Value result; 152 | BinaCPP::send_order( "BNBETH", "BUY", "MARKET", "GTC", 1 , 0, "",0,20, recvWindow , result ); 153 | 154 | #### Example: Check an order's status 155 | 156 | long recvWindow = 10000; 157 | Json::Value result; 158 | BinaCPP::get_order( "BNBETH", 12345678, "", recvWindow, result ); 159 | 160 | #### Example: Cancel an order 161 | 162 | long recvWindow = 10000; 163 | Json::Value result; 164 | BinaCPP::cancel_order("BNBETH", 12345678, "","", recvWindow, result); 165 | 166 | #### Example: Getting list of open orders for specific pair 167 | 168 | long recvWindow = 10000; 169 | Json::Value result; 170 | BinaCPP::get_openOrders( "BNBETH", recvWindow, result ) ; 171 | 172 | #### Example: Get all account orders; active, canceled, or filled. 173 | 174 | long recvWindow = 10000; 175 | Json::Value result; 176 | BinaCPP::get_allOrders( "BNBETH", 0,0, recvWindow, result ) 177 | 178 | #### Example : Get all trades history 179 | 180 | long recvWindow = 10000; 181 | Json::Value result; 182 | BinaCPP::get_myTrades( "BNBETH", 0,0, recvWindow , result ); 183 | 184 | #### Example: Getting 24hr ticker price change statistics for a symbol 185 | 186 | Json::Value result; 187 | BinaCPP::get_24hr( "ETHBTC", result ) ; 188 | 189 | #### Example: Get Kline/candlestick data for a symbol 190 | 191 | Json::Value result; 192 | BinaCPP::get_klines( "ETHBTC", "1h", 10 , 0, 0, result ); 193 | 194 | --- 195 | 196 | ### Websocket Endpoints ### 197 | 198 | 199 | #### Example: Maintain Market Depth Cache Locally via Web Socket 200 | 201 | 202 | [example_depthCache.cpp](https://github.com/tensaix2j/binacpp/blob/master/example/example_depthCache.cpp) 203 | 204 | #### Example: KLine/Candlestick Cache and update via Web Socket 205 | 206 | 207 | [example_klines.cpp](https://github.com/tensaix2j/binacpp/blob/master/example/example_klines.cpp) 208 | 209 | #### Example: Aggregated Trades and update via Web Socket 210 | 211 | [example_aggTrades.cpp](https://github.com/tensaix2j/binacpp/blob/master/example/example_aggTrades.cpp) 212 | 213 | 214 | #### Example: User stream, Order Execution Status and Balance Update via Web Socket 215 | 216 | [example_userStream.cpp](https://github.com/tensaix2j/binacpp/blob/master/example/example_userStream.cpp) 217 | 218 | 219 | #### Example: To subscribe multiple streams at the same time, do something like this 220 | 221 | BinaCPP::start_userDataStream(result ); 222 | string ws_path = string("/ws/"); 223 | ws_path.append( result["listenKey"].asString() ); 224 | 225 | 226 | BinaCPP_websocket::init(); 227 | 228 | BinaCPP_websocket::connect_endpoint( ws_aggTrade_OnData ,"/ws/bnbbtc@aggTrade" ); 229 | BinaCPP_websocket::connect_endpoint( ws_userStream_OnData , ws_path.c_str() ); 230 | BinaCPP_websocket::connect_endpoint( ws_klines_onData ,"/ws/bnbbtc@kline_1m" ); 231 | BinaCPP_websocket::connect_endpoint( ws_depth_onData ,"/ws/bnbbtc@depth" ); 232 | 233 | BinaCPP_websocket::enter_event_loop(); 234 | 235 | [example.cpp](https://github.com/tensaix2j/binacpp/blob/master/example/example.cpp) 236 | 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | libcurl_dir=../lib/libcurl-7.56.0 6 | libcurl_include=${libcurl_dir}/include 7 | libcurl_lib=${libcurl_dir}/lib 8 | 9 | jsoncpp_dir=../lib/jsoncpp-1.8.3 10 | jsoncpp_include=${jsoncpp_dir}/include 11 | jsoncpp_src=${jsoncpp_dir}/src 12 | 13 | 14 | libwebsockets_dir=../lib/libwebsockets-2.4.0 15 | libwebsockets_include=${libwebsockets_dir}/include 16 | libwebsockets_lib=${libwebsockets_dir}/lib 17 | 18 | libbinacpp_dir=../lib/libbinacpp 19 | libbinacpp_include=${libbinacpp_dir}/include 20 | libbinacpp_lib=${libbinacpp_dir}/lib 21 | 22 | 23 | 24 | %: %.cpp 25 | @echo -n "\nMaking $@\n\n\n" 26 | g++ -I$(libcurl_include) -I$(jsoncpp_include) -I$(libwebsockets_include) -I$(libbinacpp_include) \ 27 | $@.cpp \ 28 | -L$(libcurl_lib) \ 29 | -L$(libwebsockets_lib) \ 30 | -L$(libbinacpp_lib) \ 31 | -lcurl -ljsoncpp -lcrypto -lwebsockets -lbinacpp -o $@ 32 | 33 | cat run.template.sh | sed s/%executable%/$@/ > $@.run.sh 34 | chmod 755 $@.run.sh 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/example: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/example/example -------------------------------------------------------------------------------- /example/example.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "binacpp.h" 8 | #include "binacpp_websocket.h" 9 | #include 10 | 11 | #define API_KEY "api key" 12 | #define SECRET_KEY "user key" 13 | 14 | 15 | // Some code to make terminal to have colors 16 | #define KGRN "\033[0;32;32m" 17 | #define KCYN "\033[0;36m" 18 | #define KRED "\033[0;32;31m" 19 | #define KYEL "\033[1;33m" 20 | #define KBLU "\033[0;32;34m" 21 | #define KCYN_L "\033[1;36m" 22 | #define KBRN "\033[0;33m" 23 | #define RESET "\033[0m" 24 | 25 | 26 | using namespace std; 27 | 28 | map < string, map > depthCache; 29 | map < long, map > klinesCache; 30 | map < long, map > aggTradeCache; 31 | map < long, map > userTradeCache; 32 | map < string, map > userBalance; 33 | 34 | 35 | int lastUpdateId; 36 | 37 | 38 | 39 | 40 | 41 | //------------------------------ 42 | void print_depthCache() { 43 | 44 | map < string, map >::iterator it_i; 45 | 46 | for ( it_i = depthCache.begin() ; it_i != depthCache.end() ; it_i++ ) { 47 | 48 | string bid_or_ask = (*it_i).first ; 49 | cout << bid_or_ask << endl ; 50 | cout << "Price Qty" << endl ; 51 | 52 | map ::reverse_iterator it_j; 53 | 54 | for ( it_j = depthCache[bid_or_ask].rbegin() ; it_j != depthCache[bid_or_ask].rend() ; it_j++ ) { 55 | 56 | double price = (*it_j).first; 57 | double qty = (*it_j).second; 58 | printf("%.08f %.08f\n", price, qty ); 59 | } 60 | } 61 | } 62 | 63 | 64 | 65 | 66 | 67 | //------------------ 68 | void print_klinesCache() { 69 | 70 | map < long, map >::iterator it_i; 71 | 72 | cout << "==================================" << endl; 73 | 74 | for ( it_i = klinesCache.begin() ; it_i != klinesCache.end() ; it_i++ ) { 75 | 76 | long start_of_candle = (*it_i).first; 77 | map candle_obj = (*it_i).second; 78 | 79 | cout << "s:" << start_of_candle << ","; 80 | cout << "o:" << candle_obj["o"] << ","; 81 | cout << "h:" << candle_obj["h"] << ","; 82 | cout << "l:" << candle_obj["l"] << ","; 83 | cout << "c:" << candle_obj["c"] << ","; 84 | cout << "v:" << candle_obj["v"] ; 85 | cout << " " << endl; 86 | 87 | } 88 | } 89 | 90 | 91 | //--------------- 92 | void print_aggTradeCache() { 93 | 94 | map < long, map >::iterator it_i; 95 | 96 | cout << "==================================" << endl; 97 | 98 | for ( it_i = aggTradeCache.begin() ; it_i != aggTradeCache.end() ; it_i++ ) { 99 | 100 | long timestamp = (*it_i).first; 101 | map aggtrade_obj = (*it_i).second; 102 | 103 | cout << "T:" << timestamp << ", "; 104 | printf("p: %.08f, ", aggtrade_obj["p"] ); 105 | printf("q: %.08f " , aggtrade_obj["q"] ); 106 | cout << " " << endl; 107 | 108 | } 109 | } 110 | 111 | 112 | 113 | 114 | 115 | //--------------- 116 | void print_userBalance() { 117 | 118 | map < string, map >::iterator it_i; 119 | 120 | cout << "==================================" << endl; 121 | 122 | for ( it_i = userBalance.begin() ; it_i != userBalance.end() ; it_i++ ) { 123 | 124 | string symbol = (*it_i).first; 125 | map balance = (*it_i).second; 126 | 127 | cout << "Symbol :" << symbol << ", "; 128 | printf("Free : %.08f, ", balance["f"] ); 129 | printf("Locked : %.08f " , balance["l"] ); 130 | cout << " " << endl; 131 | 132 | } 133 | 134 | } 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | //------------- 144 | int ws_depth_onData( Json::Value &json_result ) { 145 | 146 | int i; 147 | 148 | int new_updateId = json_result["u"].asInt(); 149 | 150 | if ( new_updateId > lastUpdateId ) { 151 | 152 | for ( i = 0 ; i < json_result["b"].size() ; i++ ) { 153 | double price = atof( json_result["b"][i][0].asString().c_str()); 154 | double qty = atof( json_result["b"][i][1].asString().c_str()); 155 | if ( qty == 0.0 ) { 156 | depthCache["bids"].erase(price); 157 | } else { 158 | depthCache["bids"][price] = qty; 159 | } 160 | } 161 | for ( i = 0 ; i < json_result["a"].size() ; i++ ) { 162 | double price = atof( json_result["a"][i][0].asString().c_str()); 163 | double qty = atof( json_result["a"][i][1].asString().c_str()); 164 | if ( qty == 0.0 ) { 165 | depthCache["asks"].erase(price); 166 | } else { 167 | depthCache["asks"][price] = qty; 168 | } 169 | } 170 | lastUpdateId = new_updateId; 171 | } 172 | print_depthCache(); 173 | } 174 | 175 | 176 | 177 | 178 | 179 | 180 | //------------- 181 | int ws_klines_onData( Json::Value &json_result ) { 182 | 183 | long start_of_candle = json_result["k"]["t"].asInt64(); 184 | klinesCache[start_of_candle]["o"] = atof( json_result["k"]["o"].asString().c_str() ); 185 | klinesCache[start_of_candle]["h"] = atof( json_result["k"]["h"].asString().c_str() ); 186 | klinesCache[start_of_candle]["l"] = atof( json_result["k"]["l"].asString().c_str() ); 187 | klinesCache[start_of_candle]["c"] = atof( json_result["k"]["c"].asString().c_str() ); 188 | klinesCache[start_of_candle]["v"] = atof( json_result["k"]["v"].asString().c_str() ); 189 | 190 | print_klinesCache(); 191 | } 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | //----------- 200 | int ws_aggTrade_OnData( Json::Value &json_result ) { 201 | 202 | 203 | long timestamp = json_result["T"].asInt64(); 204 | aggTradeCache[timestamp]["p"] = atof( json_result["p"].asString().c_str() ); 205 | aggTradeCache[timestamp]["q"] = atof( json_result["q"].asString().c_str() ); 206 | 207 | print_aggTradeCache(); 208 | } 209 | 210 | 211 | 212 | //--------------- 213 | int ws_userStream_OnData( Json::Value &json_result ) { 214 | 215 | int i; 216 | string action = json_result["e"].asString(); 217 | if ( action == "executionReport" ) { 218 | 219 | string executionType = json_result["x"].asString(); 220 | string orderStatus = json_result["X"].asString(); 221 | string reason = json_result["r"].asString(); 222 | string symbol = json_result["s"].asString(); 223 | string side = json_result["S"].asString(); 224 | string orderType = json_result["o"].asString(); 225 | string orderId = json_result["i"].asString(); 226 | string price = json_result["p"].asString(); 227 | string qty = json_result["q"].asString(); 228 | 229 | if ( executionType == "NEW" ) { 230 | if ( orderStatus == "REJECTED" ) { 231 | printf(KRED"Order Failed! Reason: %s\n"RESET, reason.c_str() ); 232 | } 233 | printf(KGRN"\n\n%s %s %s %s(%s) %s %s\n\n"RESET, symbol.c_str() , side.c_str() , orderType.c_str() , orderId.c_str() , orderStatus.c_str(), price.c_str(), qty.c_str() ); 234 | return 0; 235 | } 236 | printf(KBLU"\n\n%s %s %s %s %s\n\n"RESET, symbol.c_str() , side.c_str() , executionType.c_str() , orderType.c_str() , orderId.c_str() ); 237 | 238 | 239 | } else if ( action == "outboundAccountInfo" ) { 240 | 241 | // Update user balance 242 | for ( i = 0 ; i < json_result["B"].size() ; i++ ) { 243 | 244 | string symbol = json_result["B"][i]["a"].asString(); 245 | userBalance[symbol]["f"] = atof( json_result["B"][i]["f"].asString().c_str() ); 246 | userBalance[symbol]["l"] = atof( json_result["B"][i]["f"].asString().c_str() ); 247 | } 248 | print_userBalance(); 249 | 250 | } 251 | 252 | } 253 | 254 | 255 | 256 | //--------------------------- 257 | /* 258 | Examples of how to use BinaCPP Binance API library 259 | Simply uncomment out the code and compile with : 260 | 261 | make example 262 | 263 | and run with 264 | 265 | ./example.run.sh 266 | */ 267 | 268 | //-------------------------- 269 | 270 | int main() { 271 | 272 | 273 | string api_key = API_KEY; 274 | string secret_key = SECRET_KEY; 275 | BinaCPP::init( api_key , secret_key ); 276 | 277 | 278 | /* 279 | The Json::value object each element can be access like hash map <>, 280 | or vector <> if it is Json::array 281 | */ 282 | Json::Value result; 283 | long recvWindow = 10000; 284 | 285 | 286 | //------------------------------------ 287 | // Example : Get Server Time. 288 | BinaCPP::get_serverTime( result ) ; 289 | cout << result << endl; 290 | //*/ 291 | 292 | /*------------------------------------------------------------- 293 | // Example : Get all Prices 294 | BinaCPP::get_allPrices( result ); 295 | cout << result << endl; 296 | */ 297 | 298 | 299 | /*------------------------------------------------------------- 300 | //Example: Get price of single pair. Eg: BNBETH 301 | double bnbeth_price = BinaCPP::get_price( "BNBETH"); 302 | cout << bnbeth_price << endl; 303 | //*/ 304 | 305 | 306 | /* 307 | // ------------------------------------------------------------- 308 | // Example: Get Account 309 | BinaCPP::get_account( recvWindow , result ); 310 | cout << result << endl; 311 | //*/ 312 | 313 | 314 | 315 | /*------------------------------------------------------------- 316 | // Example : Get all bid/ask prices 317 | BinaCPP::get_allBookTickers( result ); 318 | cout << result << endl; 319 | */ 320 | 321 | 322 | /*------------------------------------------------------------- 323 | // Example: Get bid/ask for single pair 324 | /* 325 | BinaCPP::get_bookTicker("bnbeth", result ); 326 | cout << result << endl; 327 | */ 328 | 329 | 330 | /*------------------------------------------------------------- 331 | // Example: Get Depth of single pair 332 | BinaCPP::get_depth( "ETHBTC", 5, result ) ; 333 | cout << result << endl; 334 | */ 335 | 336 | 337 | 338 | //------------------------------------------------------------- 339 | // Example: Placing a LIMIT order 340 | //BinaCPP::send_order( "BNBETH", "BUY", "LIMIT", "GTC", 20 , 0.00380000, "",0,0, recvWindow, result ); 341 | //cout << result << endl; 342 | //*/ 343 | 344 | 345 | /*------------------------------------------------------------- 346 | // Example: Placing a MARKET order 347 | BinaCPP::send_order( "BNBETH", "BUY", "MARKET", "GTC", 20 , 0, "",0,0, recvWindow, result ); 348 | cout << result << endl; 349 | */ 350 | 351 | /*------------------------------------------------------------- 352 | // Example: Placing an ICEBERG order 353 | //BinaCPP::send_order( "BNBETH", "BUY", "MARKET", "GTC", 1 , 0, "",0,20, recvWindow , result ); 354 | //cout << result << endl; 355 | 356 | 357 | /*------------------------------------------------------------- 358 | // Example: Check an order's status 359 | BinaCPP::get_order( "BNBETH", 12345678, "", recvWindow, result ); 360 | cout << result << endl; 361 | */ 362 | 363 | /*------------------------------------------------------------- 364 | // Example: Cancel an order 365 | BinaCPP::cancel_order("BNBETH", 12345678, "","", recvWindow, result); 366 | cout << result << endl; 367 | */ 368 | 369 | 370 | 371 | /*------------------------------------------------------------- 372 | // Example: Getting list of open orders for specific pair 373 | /* 374 | BinaCPP::get_openOrders( "BNBETH", recvWindow, result ) ; 375 | cout << result << endl; 376 | */ 377 | 378 | 379 | /*------------------------------------------------------------- 380 | // Example: Get all account orders; active, canceled, or filled. 381 | BinaCPP::get_allOrders( "BNBETH", 0,0, recvWindow, result ) 382 | cout << result << endl; 383 | */ 384 | 385 | 386 | /*------------------------------------------------------------- 387 | // Example : Get all trades history 388 | /* 389 | BinaCPP::get_myTrades( "BNBETH", 0,0, recvWindow , result ); 390 | cout << result << endl; 391 | */ 392 | 393 | 394 | /*------------------------------------------------------------- 395 | /* 396 | // Example: Getting 24hr ticker price change statistics for a symbol 397 | BinaCPP::get_24hr( "ETHBTC", result ) ; 398 | cout << result << endl; 399 | */ 400 | 401 | 402 | /*------------------------------------------------------------- 403 | /* 404 | // Example: Get Kline/candlestick data for a symbol 405 | BinaCPP::get_klines( "ETHBTC", "1h", 10 , 0, 0, result ); 406 | cout << result << endl; 407 | */ 408 | 409 | 410 | /*------------------------------------------------------------- 411 | /* Websockets Endpoints */ 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | // Market Depth 421 | int i; 422 | string symbol = "BNBBTC"; 423 | BinaCPP::get_depth( symbol.c_str(), 20, result ) ; 424 | 425 | // Initialize the lastUpdateId 426 | lastUpdateId = result["lastUpdateId"].asInt(); 427 | 428 | for ( int i = 0 ; i < result["asks"].size(); i++ ) { 429 | 430 | double price = atof( result["asks"][i][0].asString().c_str() ); 431 | double qty = atof( result["asks"][i][1].asString().c_str() ); 432 | depthCache["asks"][price] = qty; 433 | } 434 | for ( int i = 0 ; i < result["bids"].size() ; i++ ) { 435 | 436 | double price = atof( result["bids"][i][0].asString().c_str() ); 437 | double qty = atof( result["bids"][i][1].asString().c_str() ); 438 | depthCache["bids"][price] = qty; 439 | } 440 | print_depthCache(); 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | // Klines/CandleStick 450 | BinaCPP::get_klines( "ETHBTC", "1h", 10 , 0, 0, result ); 451 | for ( int i = 0 ; i < result.size() ; i++ ) { 452 | long start_of_candle = result[i][0].asInt64(); 453 | klinesCache[start_of_candle]["o"] = atof( result[i][1].asString().c_str() ); 454 | klinesCache[start_of_candle]["h"] = atof( result[i][2].asString().c_str() ); 455 | klinesCache[start_of_candle]["l"] = atof( result[i][3].asString().c_str() ); 456 | klinesCache[start_of_candle]["c"] = atof( result[i][4].asString().c_str() ); 457 | klinesCache[start_of_candle]["v"] = atof( result[i][5].asString().c_str() ); 458 | } 459 | print_klinesCache(); 460 | 461 | 462 | 463 | 464 | 465 | // AggTrades 466 | BinaCPP::get_aggTrades( "BNBBTC", 0, 0, 0, 10, result ); 467 | for ( int i = 0 ; i < result.size() ; i++ ) { 468 | long timestamp = result[i]["T"].asInt64(); 469 | aggTradeCache[timestamp]["p"] = atof( result[i]["p"].asString().c_str() ); 470 | aggTradeCache[timestamp]["q"] = atof( result[i]["q"].asString().c_str() ); 471 | } 472 | print_aggTradeCache(); 473 | 474 | 475 | 476 | 477 | 478 | // User Balance 479 | BinaCPP::get_account( recvWindow , result ); 480 | for ( int i = 0 ; i < result["balances"].size() ; i++ ) { 481 | string symbol = result["balances"][i]["asset"].asString(); 482 | userBalance[symbol]["f"] = atof( result["balances"][i]["free"].asString().c_str() ); 483 | userBalance[symbol]["l"] = atof( result["balances"][i]["locked"].asString().c_str() ); 484 | } 485 | print_userBalance(); 486 | 487 | 488 | 489 | 490 | 491 | 492 | // User data stream 493 | BinaCPP::start_userDataStream(result ); 494 | 495 | cout << result << endl; 496 | 497 | string ws_path = string("/ws/"); 498 | ws_path.append( result["listenKey"].asString() ); 499 | 500 | 501 | 502 | 503 | BinaCPP_websocket::init(); 504 | 505 | BinaCPP_websocket::connect_endpoint( ws_aggTrade_OnData ,"/ws/bnbbtc@aggTrade" ); 506 | BinaCPP_websocket::connect_endpoint( ws_userStream_OnData , ws_path.c_str() ); 507 | BinaCPP_websocket::connect_endpoint( ws_klines_onData ,"/ws/bnbbtc@kline_1m" ); 508 | BinaCPP_websocket::connect_endpoint( ws_depth_onData ,"/ws/bnbbtc@depth" ); 509 | 510 | BinaCPP_websocket::enter_event_loop(); 511 | 512 | 513 | 514 | return 0; 515 | } -------------------------------------------------------------------------------- /example/example.run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | export SSL_CERT_FILE=`pwd`/cacert.pem 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./example $@ 16 | -------------------------------------------------------------------------------- /example/example_aggTrades: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/example/example_aggTrades -------------------------------------------------------------------------------- /example/example_aggTrades.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "binacpp.h" 8 | #include "binacpp_websocket.h" 9 | #include 10 | 11 | 12 | 13 | using namespace std; 14 | map < long, map > aggTradeCache; 15 | 16 | 17 | //--------------- 18 | void print_aggTradeCache() { 19 | 20 | map < long, map >::iterator it_i; 21 | 22 | cout << "==================================" << endl; 23 | 24 | for ( it_i = aggTradeCache.begin() ; it_i != aggTradeCache.end() ; it_i++ ) { 25 | 26 | long aggTradeId = (*it_i).first; 27 | map aggtrade_obj = (*it_i).second; 28 | 29 | cout << "AggtradeId:" << aggTradeId << ", "; 30 | printf("p: %.08f, ", aggtrade_obj["p"] ); 31 | printf("q: %.08f " , aggtrade_obj["q"] ); 32 | cout << " " << endl; 33 | 34 | } 35 | } 36 | 37 | 38 | 39 | //----------- 40 | int ws_aggTrade_OnData( Json::Value &json_result ) { 41 | 42 | 43 | long aggTradeId = json_result["a"].asInt64(); 44 | aggTradeCache[aggTradeId]["p"] = atof( json_result["p"].asString().c_str() ); 45 | aggTradeCache[aggTradeId]["q"] = atof( json_result["q"].asString().c_str() ); 46 | 47 | print_aggTradeCache(); 48 | } 49 | 50 | 51 | //--------------------------- 52 | /* 53 | To compile, type 54 | make example_aggTrades 55 | */ 56 | 57 | //-------------------------- 58 | 59 | int main() { 60 | 61 | Json::Value result; 62 | long recvWindow = 10000; 63 | 64 | // AggTrades 65 | BinaCPP::get_aggTrades( "BNBBTC", 0, 0, 0, 10, result ); 66 | 67 | for ( int i = 0 ; i < result.size() ; i++ ) { 68 | long aggTradeId = result[i]["a"].asInt64(); 69 | aggTradeCache[aggTradeId]["p"] = atof( result[i]["p"].asString().c_str() ); 70 | aggTradeCache[aggTradeId]["q"] = atof( result[i]["q"].asString().c_str() ); 71 | } 72 | print_aggTradeCache(); 73 | 74 | 75 | BinaCPP_websocket::init(); 76 | BinaCPP_websocket::connect_endpoint( ws_aggTrade_OnData ,"/ws/bnbbtc@aggTrade" ); 77 | BinaCPP_websocket::enter_event_loop(); 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /example/example_aggTrades.run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | export SSL_CERT_FILE=`pwd`/cacert.pem 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./example_aggTrades $@ 16 | -------------------------------------------------------------------------------- /example/example_depthCache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/example/example_depthCache -------------------------------------------------------------------------------- /example/example_depthCache.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "binacpp.h" 8 | #include "binacpp_websocket.h" 9 | #include 10 | 11 | 12 | 13 | using namespace std; 14 | 15 | map < string, map > depthCache; 16 | int lastUpdateId; 17 | 18 | //------------------------------ 19 | void print_depthCache() { 20 | 21 | map < string, map >::iterator it_i; 22 | 23 | for ( it_i = depthCache.begin() ; it_i != depthCache.end() ; it_i++ ) { 24 | 25 | string bid_or_ask = (*it_i).first ; 26 | cout << bid_or_ask << endl ; 27 | cout << "Price Qty" << endl ; 28 | 29 | map ::reverse_iterator it_j; 30 | 31 | for ( it_j = depthCache[bid_or_ask].rbegin() ; it_j != depthCache[bid_or_ask].rend() ; it_j++ ) { 32 | 33 | double price = (*it_j).first; 34 | double qty = (*it_j).second; 35 | printf("%.08f %.08f\n", price, qty ); 36 | } 37 | } 38 | } 39 | 40 | 41 | 42 | 43 | 44 | //------------- 45 | int ws_depth_onData( Json::Value &json_result ) { 46 | 47 | int i; 48 | 49 | int new_updateId = json_result["u"].asInt(); 50 | 51 | if ( new_updateId > lastUpdateId ) { 52 | 53 | for ( i = 0 ; i < json_result["b"].size() ; i++ ) { 54 | double price = atof( json_result["b"][i][0].asString().c_str()); 55 | double qty = atof( json_result["b"][i][1].asString().c_str()); 56 | if ( qty == 0.0 ) { 57 | depthCache["bids"].erase(price); 58 | } else { 59 | depthCache["bids"][price] = qty; 60 | } 61 | } 62 | for ( i = 0 ; i < json_result["a"].size() ; i++ ) { 63 | double price = atof( json_result["a"][i][0].asString().c_str()); 64 | double qty = atof( json_result["a"][i][1].asString().c_str()); 65 | if ( qty == 0.0 ) { 66 | depthCache["asks"].erase(price); 67 | } else { 68 | depthCache["asks"][price] = qty; 69 | } 70 | } 71 | lastUpdateId = new_updateId; 72 | } 73 | print_depthCache(); 74 | } 75 | 76 | 77 | //--------------------------- 78 | /* 79 | To compile, type 80 | make example_depthCache 81 | 82 | */ 83 | 84 | //-------------------------- 85 | 86 | int main() { 87 | 88 | Json::Value result; 89 | long recvWindow = 10000; 90 | 91 | 92 | // Market Depth 93 | int i; 94 | string symbol = "BNBBTC"; 95 | BinaCPP::get_depth( symbol.c_str(), 20, result ) ; 96 | 97 | // Initialize the lastUpdateId 98 | lastUpdateId = result["lastUpdateId"].asInt(); 99 | 100 | for ( int i = 0 ; i < result["asks"].size(); i++ ) { 101 | 102 | double price = atof( result["asks"][i][0].asString().c_str() ); 103 | double qty = atof( result["asks"][i][1].asString().c_str() ); 104 | depthCache["asks"][price] = qty; 105 | } 106 | for ( int i = 0 ; i < result["bids"].size() ; i++ ) { 107 | 108 | double price = atof( result["bids"][i][0].asString().c_str() ); 109 | double qty = atof( result["bids"][i][1].asString().c_str() ); 110 | depthCache["bids"][price] = qty; 111 | } 112 | print_depthCache(); 113 | 114 | 115 | BinaCPP_websocket::init(); 116 | BinaCPP_websocket::connect_endpoint( ws_depth_onData ,"/ws/bnbbtc@depth" ); 117 | BinaCPP_websocket::enter_event_loop(); 118 | 119 | } -------------------------------------------------------------------------------- /example/example_depthCache.run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | export SSL_CERT_FILE=`pwd`/cacert.pem 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./example_depthCache $@ 16 | -------------------------------------------------------------------------------- /example/example_klines: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/example/example_klines -------------------------------------------------------------------------------- /example/example_klines.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "binacpp.h" 8 | #include "binacpp_websocket.h" 9 | #include 10 | 11 | 12 | 13 | using namespace std; 14 | map < long, map > klinesCache; 15 | 16 | 17 | //------------------ 18 | void print_klinesCache() { 19 | 20 | map < long, map >::iterator it_i; 21 | 22 | cout << "==================================" << endl; 23 | 24 | for ( it_i = klinesCache.begin() ; it_i != klinesCache.end() ; it_i++ ) { 25 | 26 | long start_of_candle = (*it_i).first; 27 | map candle_obj = (*it_i).second; 28 | 29 | cout << "s:" << start_of_candle << ","; 30 | cout << "o:" << candle_obj["o"] << ","; 31 | cout << "h:" << candle_obj["h"] << ","; 32 | cout << "l:" << candle_obj["l"] << ","; 33 | cout << "c:" << candle_obj["c"] << ","; 34 | cout << "v:" << candle_obj["v"] ; 35 | cout << " " << endl; 36 | 37 | } 38 | } 39 | 40 | 41 | 42 | //------------- 43 | int ws_klines_onData( Json::Value &json_result ) { 44 | 45 | long start_of_candle = json_result["k"]["t"].asInt64(); 46 | klinesCache[start_of_candle]["o"] = atof( json_result["k"]["o"].asString().c_str() ); 47 | klinesCache[start_of_candle]["h"] = atof( json_result["k"]["h"].asString().c_str() ); 48 | klinesCache[start_of_candle]["l"] = atof( json_result["k"]["l"].asString().c_str() ); 49 | klinesCache[start_of_candle]["c"] = atof( json_result["k"]["c"].asString().c_str() ); 50 | klinesCache[start_of_candle]["v"] = atof( json_result["k"]["v"].asString().c_str() ); 51 | 52 | print_klinesCache(); 53 | } 54 | 55 | 56 | 57 | 58 | 59 | 60 | //--------------------------- 61 | /* 62 | To compile, type 63 | make example_klines 64 | */ 65 | 66 | //-------------------------- 67 | 68 | int main() { 69 | 70 | Json::Value result; 71 | long recvWindow = 10000; 72 | 73 | // Klines/CandleStick 74 | BinaCPP::get_klines( "BNBBTC", "1h", 10 , 0, 0, result ); 75 | for ( int i = 0 ; i < result.size() ; i++ ) { 76 | long start_of_candle = result[i][0].asInt64(); 77 | klinesCache[start_of_candle]["o"] = atof( result[i][1].asString().c_str() ); 78 | klinesCache[start_of_candle]["h"] = atof( result[i][2].asString().c_str() ); 79 | klinesCache[start_of_candle]["l"] = atof( result[i][3].asString().c_str() ); 80 | klinesCache[start_of_candle]["c"] = atof( result[i][4].asString().c_str() ); 81 | klinesCache[start_of_candle]["v"] = atof( result[i][5].asString().c_str() ); 82 | } 83 | print_klinesCache(); 84 | 85 | // Klines/Candlestick update via websocket 86 | BinaCPP_websocket::init(); 87 | BinaCPP_websocket::connect_endpoint( ws_klines_onData ,"/ws/bnbbtc@kline_1m" ); 88 | BinaCPP_websocket::enter_event_loop(); 89 | 90 | return 0; 91 | } -------------------------------------------------------------------------------- /example/example_klines.run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | export SSL_CERT_FILE=`pwd`/cacert.pem 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./example_klines $@ 16 | -------------------------------------------------------------------------------- /example/example_template: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/example/example_template -------------------------------------------------------------------------------- /example/example_template.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include "binacpp.h" 5 | #include "binacpp_websocket.h" 6 | 7 | 8 | #include 9 | 10 | #define API_KEY "myapikey" 11 | #define SECRET_KEY "mysecretkey" 12 | 13 | 14 | //----------------------------- 15 | int ws_klines_onData( Json::Value &json_result) { 16 | 17 | cout << json_result << endl; 18 | 19 | } 20 | 21 | //------------------------- 22 | int main() { 23 | 24 | string api_key = API_KEY; 25 | string secret_key = SECRET_KEY; 26 | 27 | BinaCPP::init( api_key, secret_key ) ; 28 | 29 | BinaCPP_websocket::init(); 30 | BinaCPP_websocket::connect_endpoint( ws_klines_onData ,"/ws/bnbbtc@kline_1m" ); 31 | BinaCPP_websocket::enter_event_loop(); 32 | 33 | return 0; 34 | 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/example_template.run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./example_template $@ 16 | -------------------------------------------------------------------------------- /example/example_userStream: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/example/example_userStream -------------------------------------------------------------------------------- /example/example_userStream.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "binacpp.h" 8 | #include "binacpp_websocket.h" 9 | #include 10 | 11 | 12 | 13 | using namespace std; 14 | 15 | 16 | #define API_KEY "api key" 17 | #define SECRET_KEY "secret_key" 18 | 19 | 20 | // Some code to make terminal to have colors 21 | #define KGRN "\033[0;32;32m" 22 | #define KCYN "\033[0;36m" 23 | #define KRED "\033[0;32;31m" 24 | #define KYEL "\033[1;33m" 25 | #define KBLU "\033[0;32;34m" 26 | #define KCYN_L "\033[1;36m" 27 | #define KBRN "\033[0;33m" 28 | #define RESET "\033[0m" 29 | 30 | map < string, map > userBalance; 31 | 32 | 33 | //--------------- 34 | void print_userBalance() { 35 | 36 | map < string, map >::iterator it_i; 37 | 38 | cout << "==================================" << endl; 39 | 40 | for ( it_i = userBalance.begin() ; it_i != userBalance.end() ; it_i++ ) { 41 | 42 | string symbol = (*it_i).first; 43 | map balance = (*it_i).second; 44 | 45 | cout << "Symbol :" << symbol << ", "; 46 | printf("Free : %.08f, ", balance["f"] ); 47 | printf("Locked : %.08f " , balance["l"] ); 48 | cout << " " << endl; 49 | 50 | } 51 | 52 | } 53 | 54 | 55 | //--------------- 56 | int ws_userStream_OnData( Json::Value &json_result ) { 57 | 58 | int i; 59 | string action = json_result["e"].asString(); 60 | if ( action == "executionReport" ) { 61 | 62 | string executionType = json_result["x"].asString(); 63 | string orderStatus = json_result["X"].asString(); 64 | string reason = json_result["r"].asString(); 65 | string symbol = json_result["s"].asString(); 66 | string side = json_result["S"].asString(); 67 | string orderType = json_result["o"].asString(); 68 | string orderId = json_result["i"].asString(); 69 | string price = json_result["p"].asString(); 70 | string qty = json_result["q"].asString(); 71 | 72 | if ( executionType == "NEW" ) { 73 | if ( orderStatus == "REJECTED" ) { 74 | printf(KRED"Order Failed! Reason: %s\n"RESET, reason.c_str() ); 75 | } 76 | printf(KGRN"\n\n%s %s %s %s(%s) %s %s\n\n"RESET, symbol.c_str() , side.c_str() , orderType.c_str() , orderId.c_str() , orderStatus.c_str(), price.c_str(), qty.c_str() ); 77 | return 0; 78 | } 79 | printf(KBLU"\n\n%s %s %s %s %s\n\n"RESET, symbol.c_str() , side.c_str() , executionType.c_str() , orderType.c_str() , orderId.c_str() ); 80 | 81 | 82 | } else if ( action == "outboundAccountInfo" ) { 83 | 84 | // Update user balance 85 | for ( i = 0 ; i < json_result["B"].size() ; i++ ) { 86 | 87 | string symbol = json_result["B"][i]["a"].asString(); 88 | userBalance[symbol]["f"] = atof( json_result["B"][i]["f"].asString().c_str() ); 89 | userBalance[symbol]["l"] = atof( json_result["B"][i]["f"].asString().c_str() ); 90 | } 91 | print_userBalance(); 92 | 93 | } 94 | 95 | } 96 | 97 | 98 | //--------------------------- 99 | /* 100 | To compile, type 101 | make example_userStream 102 | 103 | */ 104 | 105 | //-------------------------- 106 | 107 | int main() { 108 | 109 | Json::Value result; 110 | long recvWindow = 10000; 111 | 112 | string api_key = API_KEY; 113 | string secret_key = SECRET_KEY; 114 | BinaCPP::init( api_key , secret_key ); 115 | 116 | 117 | // User Balance 118 | BinaCPP::get_account( recvWindow , result ); 119 | for ( int i = 0 ; i < result["balances"].size() ; i++ ) { 120 | string symbol = result["balances"][i]["asset"].asString(); 121 | userBalance[symbol]["f"] = atof( result["balances"][i]["free"].asString().c_str() ); 122 | userBalance[symbol]["l"] = atof( result["balances"][i]["locked"].asString().c_str() ); 123 | } 124 | print_userBalance(); 125 | 126 | // User data stream 127 | BinaCPP::start_userDataStream(result ); 128 | cout << result << endl; 129 | 130 | string ws_path = string("/ws/"); 131 | ws_path.append( result["listenKey"].asString() ); 132 | 133 | 134 | 135 | BinaCPP_websocket::init(); 136 | BinaCPP_websocket::connect_endpoint( ws_userStream_OnData , ws_path.c_str() ); 137 | BinaCPP_websocket::enter_event_loop(); 138 | 139 | 140 | } -------------------------------------------------------------------------------- /example/example_userStream.run.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | export SSL_CERT_FILE=`pwd`/cacert.pem 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./example_userStream $@ 16 | -------------------------------------------------------------------------------- /example/example_wapi.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | #include "binacpp.h" 8 | #include "binacpp_websocket.h" 9 | #include 10 | 11 | #define API_KEY "api key" 12 | #define SECRET_KEY "secret key" 13 | 14 | 15 | //---------------------- 16 | int main() { 17 | 18 | 19 | string api_key = API_KEY; 20 | string secret_key = SECRET_KEY; 21 | BinaCPP::init( api_key , secret_key ); 22 | 23 | 24 | Json::Value result; 25 | long recvWindow = 10000; 26 | 27 | BinaCPP::withdraw("ETH", "0x7bBd854e1CC7A762FFa19DfF07Da7E68D997bFa2", "", 10.0, "", recvWindow, result); 28 | cout << result << endl; 29 | 30 | BinaCPP::get_depositHistory( "ETH", 0, 0,0, recvWindow, result ) ; 31 | cout << result << endl; 32 | 33 | BinaCPP::get_withdrawHistory( "ETH", 0, 0,0, recvWindow, result ) ; 34 | cout << result << endl; 35 | 36 | BinaCPP::get_depositAddress( "ETH", recvWindow, result ) ; 37 | cout << result << endl; 38 | 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /example/run.template.sh: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_lib=${libcurl_dir}/lib 5 | 6 | libwebsockets_dir=../lib/libwebsockets-2.4.0 7 | libwebsockets_lib=${libwebsockets_dir}/lib 8 | 9 | libbinacpp_dir=../lib/libbinacpp 10 | libbinacpp_lib=${libbinacpp_dir}/lib 11 | 12 | export SSL_CERT_FILE=`pwd`/cacert.pem 13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libcurl_lib:$libwebsockets_lib:$libbinacpp_lib 14 | 15 | ./%executable% $@ 16 | -------------------------------------------------------------------------------- /lib/jsoncpp-1.8.3/include/json/json-forwards.h: -------------------------------------------------------------------------------- 1 | /// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/). 2 | /// It is intended to be used with #include "json/json-forwards.h" 3 | /// This header provides forward declaration for all JsonCpp types. 4 | 5 | // ////////////////////////////////////////////////////////////////////// 6 | // Beginning of content of file: LICENSE 7 | // ////////////////////////////////////////////////////////////////////// 8 | 9 | /* 10 | The JsonCpp library's source code, including accompanying documentation, 11 | tests and demonstration applications, are licensed under the following 12 | conditions... 13 | 14 | Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all 15 | jurisdictions which recognize such a disclaimer. In such jurisdictions, 16 | this software is released into the Public Domain. 17 | 18 | In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 19 | 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 20 | The JsonCpp Authors, and is released under the terms of the MIT License (see below). 21 | 22 | In jurisdictions which recognize Public Domain property, the user of this 23 | software may choose to accept it either as 1) Public Domain, 2) under the 24 | conditions of the MIT License (see below), or 3) under the terms of dual 25 | Public Domain/MIT License conditions described here, as they choose. 26 | 27 | The MIT License is about as close to Public Domain as a license can get, and is 28 | described in clear, concise terms at: 29 | 30 | http://en.wikipedia.org/wiki/MIT_License 31 | 32 | The full text of the MIT License follows: 33 | 34 | ======================================================================== 35 | Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 36 | 37 | Permission is hereby granted, free of charge, to any person 38 | obtaining a copy of this software and associated documentation 39 | files (the "Software"), to deal in the Software without 40 | restriction, including without limitation the rights to use, copy, 41 | modify, merge, publish, distribute, sublicense, and/or sell copies 42 | of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be 46 | included in all copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 49 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 50 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 51 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 52 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 53 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 54 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | ======================================================================== 57 | (END LICENSE TEXT) 58 | 59 | The MIT license is compatible with both the GPL and commercial 60 | software, affording one all of the rights of Public Domain with the 61 | minor nuisance of being required to keep the above copyright notice 62 | and license text in the source code. Note also that by accepting the 63 | Public Domain "license" you can re-license your copy using whatever 64 | license you like. 65 | 66 | */ 67 | 68 | // ////////////////////////////////////////////////////////////////////// 69 | // End of content of file: LICENSE 70 | // ////////////////////////////////////////////////////////////////////// 71 | 72 | 73 | 74 | 75 | 76 | #ifndef JSON_FORWARD_AMALGATED_H_INCLUDED 77 | # define JSON_FORWARD_AMALGATED_H_INCLUDED 78 | /// If defined, indicates that the source file is amalgated 79 | /// to prevent private header inclusion. 80 | #define JSON_IS_AMALGAMATION 81 | 82 | // ////////////////////////////////////////////////////////////////////// 83 | // Beginning of content of file: include/json/config.h 84 | // ////////////////////////////////////////////////////////////////////// 85 | 86 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 87 | // Distributed under MIT license, or public domain if desired and 88 | // recognized in your jurisdiction. 89 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 90 | 91 | #ifndef JSON_CONFIG_H_INCLUDED 92 | #define JSON_CONFIG_H_INCLUDED 93 | #include 94 | #include //typedef String 95 | #include //typedef int64_t, uint64_t 96 | 97 | /// If defined, indicates that json library is embedded in CppTL library. 98 | //# define JSON_IN_CPPTL 1 99 | 100 | /// If defined, indicates that json may leverage CppTL library 101 | //# define JSON_USE_CPPTL 1 102 | /// If defined, indicates that cpptl vector based map should be used instead of 103 | /// std::map 104 | /// as Value container. 105 | //# define JSON_USE_CPPTL_SMALLMAP 1 106 | 107 | // If non-zero, the library uses exceptions to report bad input instead of C 108 | // assertion macros. The default is to use exceptions. 109 | #ifndef JSON_USE_EXCEPTION 110 | #define JSON_USE_EXCEPTION 1 111 | #endif 112 | 113 | /// If defined, indicates that the source file is amalgated 114 | /// to prevent private header inclusion. 115 | /// Remarks: it is automatically defined in the generated amalgated header. 116 | // #define JSON_IS_AMALGAMATION 117 | 118 | #ifdef JSON_IN_CPPTL 119 | #include 120 | #ifndef JSON_USE_CPPTL 121 | #define JSON_USE_CPPTL 1 122 | #endif 123 | #endif 124 | 125 | #ifdef JSON_IN_CPPTL 126 | #define JSON_API CPPTL_API 127 | #elif defined(JSON_DLL_BUILD) 128 | #if defined(_MSC_VER) || defined(__MINGW32__) 129 | #define JSON_API __declspec(dllexport) 130 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 131 | #endif // if defined(_MSC_VER) 132 | #elif defined(JSON_DLL) 133 | #if defined(_MSC_VER) || defined(__MINGW32__) 134 | #define JSON_API __declspec(dllimport) 135 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 136 | #endif // if defined(_MSC_VER) 137 | #endif // ifdef JSON_IN_CPPTL 138 | #if !defined(JSON_API) 139 | #define JSON_API 140 | #endif 141 | 142 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for 143 | // integer 144 | // Storages, and 64 bits integer support is disabled. 145 | // #define JSON_NO_INT64 1 146 | 147 | #if defined(_MSC_VER) // MSVC 148 | # if _MSC_VER <= 1200 // MSVC 6 149 | // Microsoft Visual Studio 6 only support conversion from __int64 to double 150 | // (no conversion from unsigned __int64). 151 | # define JSON_USE_INT64_DOUBLE_CONVERSION 1 152 | // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255' 153 | // characters in the debug information) 154 | // All projects I've ever seen with VS6 were using this globally (not bothering 155 | // with pragma push/pop). 156 | # pragma warning(disable : 4786) 157 | # endif // MSVC 6 158 | 159 | # if _MSC_VER >= 1500 // MSVC 2008 160 | /// Indicates that the following function is deprecated. 161 | # define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 162 | # endif 163 | 164 | #endif // defined(_MSC_VER) 165 | 166 | // In c++11 the override keyword allows you to explicity define that a function 167 | // is intended to override the base-class version. This makes the code more 168 | // managable and fixes a set of common hard-to-find bugs. 169 | #if __cplusplus >= 201103L 170 | # define JSONCPP_OVERRIDE override 171 | # define JSONCPP_NOEXCEPT noexcept 172 | #elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900 173 | # define JSONCPP_OVERRIDE override 174 | # define JSONCPP_NOEXCEPT throw() 175 | #elif defined(_MSC_VER) && _MSC_VER >= 1900 176 | # define JSONCPP_OVERRIDE override 177 | # define JSONCPP_NOEXCEPT noexcept 178 | #else 179 | # define JSONCPP_OVERRIDE 180 | # define JSONCPP_NOEXCEPT throw() 181 | #endif 182 | 183 | #ifndef JSON_HAS_RVALUE_REFERENCES 184 | 185 | #if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010 186 | #define JSON_HAS_RVALUE_REFERENCES 1 187 | #endif // MSVC >= 2010 188 | 189 | #ifdef __clang__ 190 | #if __has_feature(cxx_rvalue_references) 191 | #define JSON_HAS_RVALUE_REFERENCES 1 192 | #endif // has_feature 193 | 194 | #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) 195 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L) 196 | #define JSON_HAS_RVALUE_REFERENCES 1 197 | #endif // GXX_EXPERIMENTAL 198 | 199 | #endif // __clang__ || __GNUC__ 200 | 201 | #endif // not defined JSON_HAS_RVALUE_REFERENCES 202 | 203 | #ifndef JSON_HAS_RVALUE_REFERENCES 204 | #define JSON_HAS_RVALUE_REFERENCES 0 205 | #endif 206 | 207 | #ifdef __clang__ 208 | # if __has_extension(attribute_deprecated_with_message) 209 | # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) 210 | # endif 211 | #elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) 212 | # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) 213 | # define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) 214 | # elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 215 | # define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) 216 | # endif // GNUC version 217 | #endif // __clang__ || __GNUC__ 218 | 219 | #if !defined(JSONCPP_DEPRECATED) 220 | #define JSONCPP_DEPRECATED(message) 221 | #endif // if !defined(JSONCPP_DEPRECATED) 222 | 223 | #if __GNUC__ >= 6 224 | # define JSON_USE_INT64_DOUBLE_CONVERSION 1 225 | #endif 226 | 227 | #if !defined(JSON_IS_AMALGAMATION) 228 | 229 | # include "version.h" 230 | 231 | # if JSONCPP_USING_SECURE_MEMORY 232 | # include "allocator.h" //typedef Allocator 233 | # endif 234 | 235 | #endif // if !defined(JSON_IS_AMALGAMATION) 236 | 237 | namespace Json { 238 | typedef int Int; 239 | typedef unsigned int UInt; 240 | #if defined(JSON_NO_INT64) 241 | typedef int LargestInt; 242 | typedef unsigned int LargestUInt; 243 | #undef JSON_HAS_INT64 244 | #else // if defined(JSON_NO_INT64) 245 | // For Microsoft Visual use specific types as long long is not supported 246 | #if defined(_MSC_VER) // Microsoft Visual Studio 247 | typedef __int64 Int64; 248 | typedef unsigned __int64 UInt64; 249 | #else // if defined(_MSC_VER) // Other platforms, use long long 250 | typedef int64_t Int64; 251 | typedef uint64_t UInt64; 252 | #endif // if defined(_MSC_VER) 253 | typedef Int64 LargestInt; 254 | typedef UInt64 LargestUInt; 255 | #define JSON_HAS_INT64 256 | #endif // if defined(JSON_NO_INT64) 257 | #if JSONCPP_USING_SECURE_MEMORY 258 | #define JSONCPP_STRING std::basic_string, Json::SecureAllocator > 259 | #define JSONCPP_OSTRINGSTREAM std::basic_ostringstream, Json::SecureAllocator > 260 | #define JSONCPP_OSTREAM std::basic_ostream> 261 | #define JSONCPP_ISTRINGSTREAM std::basic_istringstream, Json::SecureAllocator > 262 | #define JSONCPP_ISTREAM std::istream 263 | #else 264 | #define JSONCPP_STRING std::string 265 | #define JSONCPP_OSTRINGSTREAM std::ostringstream 266 | #define JSONCPP_OSTREAM std::ostream 267 | #define JSONCPP_ISTRINGSTREAM std::istringstream 268 | #define JSONCPP_ISTREAM std::istream 269 | #endif // if JSONCPP_USING_SECURE_MEMORY 270 | } // end namespace Json 271 | 272 | #endif // JSON_CONFIG_H_INCLUDED 273 | 274 | // ////////////////////////////////////////////////////////////////////// 275 | // End of content of file: include/json/config.h 276 | // ////////////////////////////////////////////////////////////////////// 277 | 278 | 279 | 280 | 281 | 282 | 283 | // ////////////////////////////////////////////////////////////////////// 284 | // Beginning of content of file: include/json/forwards.h 285 | // ////////////////////////////////////////////////////////////////////// 286 | 287 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 288 | // Distributed under MIT license, or public domain if desired and 289 | // recognized in your jurisdiction. 290 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 291 | 292 | #ifndef JSON_FORWARDS_H_INCLUDED 293 | #define JSON_FORWARDS_H_INCLUDED 294 | 295 | #if !defined(JSON_IS_AMALGAMATION) 296 | #include "config.h" 297 | #endif // if !defined(JSON_IS_AMALGAMATION) 298 | 299 | namespace Json { 300 | 301 | // writer.h 302 | class FastWriter; 303 | class StyledWriter; 304 | 305 | // reader.h 306 | class Reader; 307 | 308 | // features.h 309 | class Features; 310 | 311 | // value.h 312 | typedef unsigned int ArrayIndex; 313 | class StaticString; 314 | class Path; 315 | class PathArgument; 316 | class Value; 317 | class ValueIteratorBase; 318 | class ValueIterator; 319 | class ValueConstIterator; 320 | 321 | } // namespace Json 322 | 323 | #endif // JSON_FORWARDS_H_INCLUDED 324 | 325 | // ////////////////////////////////////////////////////////////////////// 326 | // End of content of file: include/json/forwards.h 327 | // ////////////////////////////////////////////////////////////////////// 328 | 329 | 330 | 331 | 332 | 333 | #endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED 334 | -------------------------------------------------------------------------------- /lib/libbinacpp/include/binacpp.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Author: tensaix2j 4 | Date : 2017/10/15 5 | 6 | C++ library for Binance API. 7 | */ 8 | 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | 26 | 27 | #define BINANCE_HOST "https://api.binance.com" 28 | 29 | 30 | using namespace std; 31 | 32 | class BinaCPP { 33 | 34 | static string api_key; 35 | static string secret_key; 36 | 37 | public: 38 | 39 | static void curl_api( string &url, string &result_json ); 40 | static void curl_api_with_header( string &url, string &result_json , vector &extra_http_header, string &post_data, string &action ); 41 | static size_t curl_cb( void *content, size_t size, size_t nmemb, string *buffer ) ; 42 | 43 | static void init( string &api_key, string &secret_key); 44 | 45 | 46 | // Public API 47 | static void get_serverTime( Json::Value &json_result); 48 | 49 | static void get_allPrices( Json::Value &json_result ); 50 | static double get_price( const char *symbol ); 51 | 52 | static void get_allBookTickers( Json::Value &json_result ); 53 | static void get_bookTicker( const char *symbol, Json::Value &json_result ) ; 54 | 55 | static void get_depth( const char *symbol, int limit, Json::Value &json_result ); 56 | static void get_aggTrades( const char *symbol, int fromId, time_t startTime, time_t endTime, int limit, Json::Value &json_result ); 57 | static void get_24hr( const char *symbol, Json::Value &json_result ); 58 | static void get_klines( const char *symbol, const char *interval, int limit, time_t startTime, time_t endTime, Json::Value &json_result ); 59 | 60 | 61 | // API + Secret keys required 62 | static void get_account( long recvWindow , Json::Value &json_result ); 63 | 64 | static void get_myTrades( 65 | const char *symbol, 66 | int limit, 67 | long fromId, 68 | long recvWindow, 69 | Json::Value &json_result 70 | ); 71 | 72 | static void get_openOrders( 73 | const char *symbol, 74 | long recvWindow, 75 | Json::Value &json_result 76 | ) ; 77 | 78 | 79 | static void get_allOrders( 80 | const char *symbol, 81 | long orderId, 82 | int limit, 83 | long recvWindow, 84 | Json::Value &json_result 85 | ); 86 | 87 | 88 | static void send_order( 89 | const char *symbol, 90 | const char *side, 91 | const char *type, 92 | const char *timeInForce, 93 | double quantity, 94 | double price, 95 | const char *newClientOrderId, 96 | double stopPrice, 97 | double icebergQty, 98 | long recvWindow, 99 | Json::Value &json_result ) ; 100 | 101 | 102 | static void get_order( 103 | const char *symbol, 104 | long orderId, 105 | const char *origClientOrderId, 106 | long recvWindow, 107 | Json::Value &json_result ); 108 | 109 | 110 | static void cancel_order( 111 | const char *symbol, 112 | long orderId, 113 | const char *origClientOrderId, 114 | const char *newClientOrderId, 115 | long recvWindow, 116 | Json::Value &json_result 117 | ); 118 | 119 | // API key required 120 | static void start_userDataStream( Json::Value &json_result ); 121 | static void keep_userDataStream( const char *listenKey ); 122 | static void close_userDataStream( const char *listenKey ); 123 | 124 | 125 | // WAPI 126 | static void withdraw( 127 | const char *asset, 128 | const char *address, 129 | const char *addressTag, 130 | double amount, 131 | const char *name, 132 | long recvWindow, 133 | Json::Value &json_result ); 134 | 135 | static void get_depositHistory( 136 | const char *asset, 137 | int status, 138 | long startTime, 139 | long endTime, 140 | long recvWindow, 141 | Json::Value &json_result ); 142 | 143 | static void get_withdrawHistory( 144 | const char *asset, 145 | int status, 146 | long startTime, 147 | long endTime, 148 | long recvWindow, 149 | Json::Value &json_result ); 150 | 151 | static void get_depositAddress( 152 | const char *asset, 153 | long recvWindow, 154 | Json::Value &json_result ); 155 | 156 | 157 | }; 158 | 159 | 160 | -------------------------------------------------------------------------------- /lib/libbinacpp/include/binacpp_logger.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | 23 | class BinaCPP_logger { 24 | 25 | static int debug_level ; 26 | static string debug_log_file; 27 | static int debug_log_file_enable ; 28 | static FILE *log_fp; 29 | 30 | 31 | static void open_logfp_if_not_opened(); 32 | 33 | public: 34 | static void write_log( const char *fmt, ... ); 35 | static void write_log_clean( const char *fmt, ... ); 36 | static void set_debug_level( int level ); 37 | static void set_debug_logfile( string &pDebug_log_file ) ; 38 | static void enable_logfile( int pDebug_log_file_enable ); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /lib/libbinacpp/include/binacpp_utils.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef BINACPP_UTILS 4 | #define BINACPP_UTILS 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | void split_string( string &s, char delim, vector &result); 18 | bool replace_string( string& str, const char *from, const char *to); 19 | int replace_string_once( string& str, const char *from, const char *to , int offset); 20 | 21 | 22 | string b2a_hex( char *byte_arr, int n ); 23 | time_t get_current_epoch(); 24 | unsigned long get_current_ms_epoch(); 25 | 26 | //-------------------- 27 | template 28 | inline string to_string (const T& t) 29 | { 30 | stringstream ss; 31 | ss << t; 32 | return ss.str(); 33 | } 34 | 35 | //-------------------- 36 | inline bool file_exists (const std::string& name) { 37 | return ( access( name.c_str(), F_OK ) != -1 ); 38 | } 39 | 40 | string hmac_sha256( const char *key, const char *data); 41 | string sha256( const char *data ); 42 | void string_toupper( string &src); 43 | string string_toupper( const char *cstr ); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /lib/libbinacpp/include/binacpp_websocket.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | 19 | #define BINANCE_WS_HOST "stream.binance.com" 20 | #define BINANCE_WS_PORT 9443 21 | 22 | 23 | using namespace std; 24 | 25 | typedef int (*CB)(Json::Value &json_value ); 26 | 27 | 28 | class BinaCPP_websocket { 29 | 30 | 31 | static struct lws_context *context; 32 | static struct lws_protocols protocols[]; 33 | 34 | static map handles ; 35 | 36 | public: 37 | static int event_cb( struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len ); 38 | static void connect_endpoint( 39 | CB user_cb, 40 | const char* path 41 | ); 42 | static void init(); 43 | static void enter_event_loop(); 44 | 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /lib/libbinacpp/lib/binacpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libbinacpp/lib/binacpp.o -------------------------------------------------------------------------------- /lib/libbinacpp/lib/binacpp_logger.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libbinacpp/lib/binacpp_logger.o -------------------------------------------------------------------------------- /lib/libbinacpp/lib/binacpp_utils.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libbinacpp/lib/binacpp_utils.o -------------------------------------------------------------------------------- /lib/libbinacpp/lib/binacpp_websocket.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libbinacpp/lib/binacpp_websocket.o -------------------------------------------------------------------------------- /lib/libbinacpp/lib/jsoncpp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libbinacpp/lib/jsoncpp.o -------------------------------------------------------------------------------- /lib/libbinacpp/lib/libbinacpp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libbinacpp/lib/libbinacpp.so -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/curlver.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_CURLVER_H 2 | #define __CURL_CURLVER_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* This header file contains nothing but libcurl version info, generated by 26 | a script at release-time. This was made its own header file in 7.11.2 */ 27 | 28 | /* This is the global package copyright */ 29 | #define LIBCURL_COPYRIGHT "1996 - 2017 Daniel Stenberg, ." 30 | 31 | /* This is the version number of the libcurl package from which this header 32 | file origins: */ 33 | #define LIBCURL_VERSION "7.56.0" 34 | 35 | /* The numeric version number is also available "in parts" by using these 36 | defines: */ 37 | #define LIBCURL_VERSION_MAJOR 7 38 | #define LIBCURL_VERSION_MINOR 56 39 | #define LIBCURL_VERSION_PATCH 0 40 | 41 | /* This is the numeric version of the libcurl version number, meant for easier 42 | parsing and comparions by programs. The LIBCURL_VERSION_NUM define will 43 | always follow this syntax: 44 | 45 | 0xXXYYZZ 46 | 47 | Where XX, YY and ZZ are the main version, release and patch numbers in 48 | hexadecimal (using 8 bits each). All three numbers are always represented 49 | using two digits. 1.2 would appear as "0x010200" while version 9.11.7 50 | appears as "0x090b07". 51 | 52 | This 6-digit (24 bits) hexadecimal number does not show pre-release number, 53 | and it is always a greater number in a more recent release. It makes 54 | comparisons with greater than and less than work. 55 | 56 | Note: This define is the full hex number and _does not_ use the 57 | CURL_VERSION_BITS() macro since curl's own configure script greps for it 58 | and needs it to contain the full number. 59 | */ 60 | #define LIBCURL_VERSION_NUM 0x073800 61 | 62 | /* 63 | * This is the date and time when the full source package was created. The 64 | * timestamp is not stored in git, as the timestamp is properly set in the 65 | * tarballs by the maketgz script. 66 | * 67 | * The format of the date follows this template: 68 | * 69 | * "2007-11-23" 70 | */ 71 | #define LIBCURL_TIMESTAMP "2017-10-04" 72 | 73 | #define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z) 74 | #define CURL_AT_LEAST_VERSION(x,y,z) \ 75 | (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z)) 76 | 77 | #endif /* __CURL_CURLVER_H */ 78 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/easy.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_EASY_H 2 | #define __CURL_EASY_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | CURL_EXTERN CURL *curl_easy_init(void); 29 | CURL_EXTERN CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...); 30 | CURL_EXTERN CURLcode curl_easy_perform(CURL *curl); 31 | CURL_EXTERN void curl_easy_cleanup(CURL *curl); 32 | 33 | /* 34 | * NAME curl_easy_getinfo() 35 | * 36 | * DESCRIPTION 37 | * 38 | * Request internal information from the curl session with this function. The 39 | * third argument MUST be a pointer to a long, a pointer to a char * or a 40 | * pointer to a double (as the documentation describes elsewhere). The data 41 | * pointed to will be filled in accordingly and can be relied upon only if the 42 | * function returns CURLE_OK. This function is intended to get used *AFTER* a 43 | * performed transfer, all results from this function are undefined until the 44 | * transfer is completed. 45 | */ 46 | CURL_EXTERN CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...); 47 | 48 | 49 | /* 50 | * NAME curl_easy_duphandle() 51 | * 52 | * DESCRIPTION 53 | * 54 | * Creates a new curl session handle with the same options set for the handle 55 | * passed in. Duplicating a handle could only be a matter of cloning data and 56 | * options, internal state info and things like persistent connections cannot 57 | * be transferred. It is useful in multithreaded applications when you can run 58 | * curl_easy_duphandle() for each new thread to avoid a series of identical 59 | * curl_easy_setopt() invokes in every thread. 60 | */ 61 | CURL_EXTERN CURL *curl_easy_duphandle(CURL *curl); 62 | 63 | /* 64 | * NAME curl_easy_reset() 65 | * 66 | * DESCRIPTION 67 | * 68 | * Re-initializes a CURL handle to the default values. This puts back the 69 | * handle to the same state as it was in when it was just created. 70 | * 71 | * It does keep: live connections, the Session ID cache, the DNS cache and the 72 | * cookies. 73 | */ 74 | CURL_EXTERN void curl_easy_reset(CURL *curl); 75 | 76 | /* 77 | * NAME curl_easy_recv() 78 | * 79 | * DESCRIPTION 80 | * 81 | * Receives data from the connected socket. Use after successful 82 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 83 | */ 84 | CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, 85 | size_t *n); 86 | 87 | /* 88 | * NAME curl_easy_send() 89 | * 90 | * DESCRIPTION 91 | * 92 | * Sends data over the connected socket. Use after successful 93 | * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. 94 | */ 95 | CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, 96 | size_t buflen, size_t *n); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/mprintf.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_MPRINTF_H 2 | #define __CURL_MPRINTF_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | #include /* needed for FILE */ 27 | #include "curl.h" /* for CURL_EXTERN */ 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | CURL_EXTERN int curl_mprintf(const char *format, ...); 34 | CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...); 35 | CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...); 36 | CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength, 37 | const char *format, ...); 38 | CURL_EXTERN int curl_mvprintf(const char *format, va_list args); 39 | CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args); 40 | CURL_EXTERN int curl_mvsprintf(char *buffer, const char *format, va_list args); 41 | CURL_EXTERN int curl_mvsnprintf(char *buffer, size_t maxlength, 42 | const char *format, va_list args); 43 | CURL_EXTERN char *curl_maprintf(const char *format, ...); 44 | CURL_EXTERN char *curl_mvaprintf(const char *format, va_list args); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __CURL_MPRINTF_H */ 51 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/multi.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_MULTI_H 2 | #define __CURL_MULTI_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | /* 25 | This is an "external" header file. Don't give away any internals here! 26 | 27 | GOALS 28 | 29 | o Enable a "pull" interface. The application that uses libcurl decides where 30 | and when to ask libcurl to get/send data. 31 | 32 | o Enable multiple simultaneous transfers in the same thread without making it 33 | complicated for the application. 34 | 35 | o Enable the application to select() on its own file descriptors and curl's 36 | file descriptors simultaneous easily. 37 | 38 | */ 39 | 40 | /* 41 | * This header file should not really need to include "curl.h" since curl.h 42 | * itself includes this file and we expect user applications to do #include 43 | * without the need for especially including multi.h. 44 | * 45 | * For some reason we added this include here at one point, and rather than to 46 | * break existing (wrongly written) libcurl applications, we leave it as-is 47 | * but with this warning attached. 48 | */ 49 | #include "curl.h" 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | #if defined(BUILDING_LIBCURL) || defined(CURL_STRICTER) 56 | typedef struct Curl_multi CURLM; 57 | #else 58 | typedef void CURLM; 59 | #endif 60 | 61 | typedef enum { 62 | CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or 63 | curl_multi_socket*() soon */ 64 | CURLM_OK, 65 | CURLM_BAD_HANDLE, /* the passed-in handle is not a valid CURLM handle */ 66 | CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */ 67 | CURLM_OUT_OF_MEMORY, /* if you ever get this, you're in deep sh*t */ 68 | CURLM_INTERNAL_ERROR, /* this is a libcurl bug */ 69 | CURLM_BAD_SOCKET, /* the passed in socket argument did not match */ 70 | CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */ 71 | CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was 72 | attempted to get added - again */ 73 | CURLM_LAST 74 | } CURLMcode; 75 | 76 | /* just to make code nicer when using curl_multi_socket() you can now check 77 | for CURLM_CALL_MULTI_SOCKET too in the same style it works for 78 | curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ 79 | #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM 80 | 81 | /* bitmask bits for CURLMOPT_PIPELINING */ 82 | #define CURLPIPE_NOTHING 0L 83 | #define CURLPIPE_HTTP1 1L 84 | #define CURLPIPE_MULTIPLEX 2L 85 | 86 | typedef enum { 87 | CURLMSG_NONE, /* first, not used */ 88 | CURLMSG_DONE, /* This easy handle has completed. 'result' contains 89 | the CURLcode of the transfer */ 90 | CURLMSG_LAST /* last, not used */ 91 | } CURLMSG; 92 | 93 | struct CURLMsg { 94 | CURLMSG msg; /* what this message means */ 95 | CURL *easy_handle; /* the handle it concerns */ 96 | union { 97 | void *whatever; /* message-specific data */ 98 | CURLcode result; /* return code for transfer */ 99 | } data; 100 | }; 101 | typedef struct CURLMsg CURLMsg; 102 | 103 | /* Based on poll(2) structure and values. 104 | * We don't use pollfd and POLL* constants explicitly 105 | * to cover platforms without poll(). */ 106 | #define CURL_WAIT_POLLIN 0x0001 107 | #define CURL_WAIT_POLLPRI 0x0002 108 | #define CURL_WAIT_POLLOUT 0x0004 109 | 110 | struct curl_waitfd { 111 | curl_socket_t fd; 112 | short events; 113 | short revents; /* not supported yet */ 114 | }; 115 | 116 | /* 117 | * Name: curl_multi_init() 118 | * 119 | * Desc: inititalize multi-style curl usage 120 | * 121 | * Returns: a new CURLM handle to use in all 'curl_multi' functions. 122 | */ 123 | CURL_EXTERN CURLM *curl_multi_init(void); 124 | 125 | /* 126 | * Name: curl_multi_add_handle() 127 | * 128 | * Desc: add a standard curl handle to the multi stack 129 | * 130 | * Returns: CURLMcode type, general multi error code. 131 | */ 132 | CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle, 133 | CURL *curl_handle); 134 | 135 | /* 136 | * Name: curl_multi_remove_handle() 137 | * 138 | * Desc: removes a curl handle from the multi stack again 139 | * 140 | * Returns: CURLMcode type, general multi error code. 141 | */ 142 | CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle, 143 | CURL *curl_handle); 144 | 145 | /* 146 | * Name: curl_multi_fdset() 147 | * 148 | * Desc: Ask curl for its fd_set sets. The app can use these to select() or 149 | * poll() on. We want curl_multi_perform() called as soon as one of 150 | * them are ready. 151 | * 152 | * Returns: CURLMcode type, general multi error code. 153 | */ 154 | CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle, 155 | fd_set *read_fd_set, 156 | fd_set *write_fd_set, 157 | fd_set *exc_fd_set, 158 | int *max_fd); 159 | 160 | /* 161 | * Name: curl_multi_wait() 162 | * 163 | * Desc: Poll on all fds within a CURLM set as well as any 164 | * additional fds passed to the function. 165 | * 166 | * Returns: CURLMcode type, general multi error code. 167 | */ 168 | CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle, 169 | struct curl_waitfd extra_fds[], 170 | unsigned int extra_nfds, 171 | int timeout_ms, 172 | int *ret); 173 | 174 | /* 175 | * Name: curl_multi_perform() 176 | * 177 | * Desc: When the app thinks there's data available for curl it calls this 178 | * function to read/write whatever there is right now. This returns 179 | * as soon as the reads and writes are done. This function does not 180 | * require that there actually is data available for reading or that 181 | * data can be written, it can be called just in case. It returns 182 | * the number of handles that still transfer data in the second 183 | * argument's integer-pointer. 184 | * 185 | * Returns: CURLMcode type, general multi error code. *NOTE* that this only 186 | * returns errors etc regarding the whole multi stack. There might 187 | * still have occurred problems on invidual transfers even when this 188 | * returns OK. 189 | */ 190 | CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle, 191 | int *running_handles); 192 | 193 | /* 194 | * Name: curl_multi_cleanup() 195 | * 196 | * Desc: Cleans up and removes a whole multi stack. It does not free or 197 | * touch any individual easy handles in any way. We need to define 198 | * in what state those handles will be if this function is called 199 | * in the middle of a transfer. 200 | * 201 | * Returns: CURLMcode type, general multi error code. 202 | */ 203 | CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle); 204 | 205 | /* 206 | * Name: curl_multi_info_read() 207 | * 208 | * Desc: Ask the multi handle if there's any messages/informationals from 209 | * the individual transfers. Messages include informationals such as 210 | * error code from the transfer or just the fact that a transfer is 211 | * completed. More details on these should be written down as well. 212 | * 213 | * Repeated calls to this function will return a new struct each 214 | * time, until a special "end of msgs" struct is returned as a signal 215 | * that there is no more to get at this point. 216 | * 217 | * The data the returned pointer points to will not survive calling 218 | * curl_multi_cleanup(). 219 | * 220 | * The 'CURLMsg' struct is meant to be very simple and only contain 221 | * very basic information. If more involved information is wanted, 222 | * we will provide the particular "transfer handle" in that struct 223 | * and that should/could/would be used in subsequent 224 | * curl_easy_getinfo() calls (or similar). The point being that we 225 | * must never expose complex structs to applications, as then we'll 226 | * undoubtably get backwards compatibility problems in the future. 227 | * 228 | * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out 229 | * of structs. It also writes the number of messages left in the 230 | * queue (after this read) in the integer the second argument points 231 | * to. 232 | */ 233 | CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle, 234 | int *msgs_in_queue); 235 | 236 | /* 237 | * Name: curl_multi_strerror() 238 | * 239 | * Desc: The curl_multi_strerror function may be used to turn a CURLMcode 240 | * value into the equivalent human readable error string. This is 241 | * useful for printing meaningful error messages. 242 | * 243 | * Returns: A pointer to a zero-terminated error message. 244 | */ 245 | CURL_EXTERN const char *curl_multi_strerror(CURLMcode); 246 | 247 | /* 248 | * Name: curl_multi_socket() and 249 | * curl_multi_socket_all() 250 | * 251 | * Desc: An alternative version of curl_multi_perform() that allows the 252 | * application to pass in one of the file descriptors that have been 253 | * detected to have "action" on them and let libcurl perform. 254 | * See man page for details. 255 | */ 256 | #define CURL_POLL_NONE 0 257 | #define CURL_POLL_IN 1 258 | #define CURL_POLL_OUT 2 259 | #define CURL_POLL_INOUT 3 260 | #define CURL_POLL_REMOVE 4 261 | 262 | #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD 263 | 264 | #define CURL_CSELECT_IN 0x01 265 | #define CURL_CSELECT_OUT 0x02 266 | #define CURL_CSELECT_ERR 0x04 267 | 268 | typedef int (*curl_socket_callback)(CURL *easy, /* easy handle */ 269 | curl_socket_t s, /* socket */ 270 | int what, /* see above */ 271 | void *userp, /* private callback 272 | pointer */ 273 | void *socketp); /* private socket 274 | pointer */ 275 | /* 276 | * Name: curl_multi_timer_callback 277 | * 278 | * Desc: Called by libcurl whenever the library detects a change in the 279 | * maximum number of milliseconds the app is allowed to wait before 280 | * curl_multi_socket() or curl_multi_perform() must be called 281 | * (to allow libcurl's timed events to take place). 282 | * 283 | * Returns: The callback should return zero. 284 | */ 285 | typedef int (*curl_multi_timer_callback)(CURLM *multi, /* multi handle */ 286 | long timeout_ms, /* see above */ 287 | void *userp); /* private callback 288 | pointer */ 289 | 290 | CURL_EXTERN CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, 291 | int *running_handles); 292 | 293 | CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle, 294 | curl_socket_t s, 295 | int ev_bitmask, 296 | int *running_handles); 297 | 298 | CURL_EXTERN CURLMcode curl_multi_socket_all(CURLM *multi_handle, 299 | int *running_handles); 300 | 301 | #ifndef CURL_ALLOW_OLD_MULTI_SOCKET 302 | /* This macro below was added in 7.16.3 to push users who recompile to use 303 | the new curl_multi_socket_action() instead of the old curl_multi_socket() 304 | */ 305 | #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z) 306 | #endif 307 | 308 | /* 309 | * Name: curl_multi_timeout() 310 | * 311 | * Desc: Returns the maximum number of milliseconds the app is allowed to 312 | * wait before curl_multi_socket() or curl_multi_perform() must be 313 | * called (to allow libcurl's timed events to take place). 314 | * 315 | * Returns: CURLM error code. 316 | */ 317 | CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle, 318 | long *milliseconds); 319 | 320 | #undef CINIT /* re-using the same name as in curl.h */ 321 | 322 | #ifdef CURL_ISOCPP 323 | #define CINIT(name,type,num) CURLMOPT_ ## name = CURLOPTTYPE_ ## type + num 324 | #else 325 | /* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ 326 | #define LONG CURLOPTTYPE_LONG 327 | #define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT 328 | #define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT 329 | #define OFF_T CURLOPTTYPE_OFF_T 330 | #define CINIT(name,type,number) CURLMOPT_/**/name = type + number 331 | #endif 332 | 333 | typedef enum { 334 | /* This is the socket callback function pointer */ 335 | CINIT(SOCKETFUNCTION, FUNCTIONPOINT, 1), 336 | 337 | /* This is the argument passed to the socket callback */ 338 | CINIT(SOCKETDATA, OBJECTPOINT, 2), 339 | 340 | /* set to 1 to enable pipelining for this multi handle */ 341 | CINIT(PIPELINING, LONG, 3), 342 | 343 | /* This is the timer callback function pointer */ 344 | CINIT(TIMERFUNCTION, FUNCTIONPOINT, 4), 345 | 346 | /* This is the argument passed to the timer callback */ 347 | CINIT(TIMERDATA, OBJECTPOINT, 5), 348 | 349 | /* maximum number of entries in the connection cache */ 350 | CINIT(MAXCONNECTS, LONG, 6), 351 | 352 | /* maximum number of (pipelining) connections to one host */ 353 | CINIT(MAX_HOST_CONNECTIONS, LONG, 7), 354 | 355 | /* maximum number of requests in a pipeline */ 356 | CINIT(MAX_PIPELINE_LENGTH, LONG, 8), 357 | 358 | /* a connection with a content-length longer than this 359 | will not be considered for pipelining */ 360 | CINIT(CONTENT_LENGTH_PENALTY_SIZE, OFF_T, 9), 361 | 362 | /* a connection with a chunk length longer than this 363 | will not be considered for pipelining */ 364 | CINIT(CHUNK_LENGTH_PENALTY_SIZE, OFF_T, 10), 365 | 366 | /* a list of site names(+port) that are blacklisted from 367 | pipelining */ 368 | CINIT(PIPELINING_SITE_BL, OBJECTPOINT, 11), 369 | 370 | /* a list of server types that are blacklisted from 371 | pipelining */ 372 | CINIT(PIPELINING_SERVER_BL, OBJECTPOINT, 12), 373 | 374 | /* maximum number of open connections in total */ 375 | CINIT(MAX_TOTAL_CONNECTIONS, LONG, 13), 376 | 377 | /* This is the server push callback function pointer */ 378 | CINIT(PUSHFUNCTION, FUNCTIONPOINT, 14), 379 | 380 | /* This is the argument passed to the server push callback */ 381 | CINIT(PUSHDATA, OBJECTPOINT, 15), 382 | 383 | CURLMOPT_LASTENTRY /* the last unused */ 384 | } CURLMoption; 385 | 386 | 387 | /* 388 | * Name: curl_multi_setopt() 389 | * 390 | * Desc: Sets options for the multi handle. 391 | * 392 | * Returns: CURLM error code. 393 | */ 394 | CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle, 395 | CURLMoption option, ...); 396 | 397 | 398 | /* 399 | * Name: curl_multi_assign() 400 | * 401 | * Desc: This function sets an association in the multi handle between the 402 | * given socket and a private pointer of the application. This is 403 | * (only) useful for curl_multi_socket uses. 404 | * 405 | * Returns: CURLM error code. 406 | */ 407 | CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle, 408 | curl_socket_t sockfd, void *sockp); 409 | 410 | 411 | /* 412 | * Name: curl_push_callback 413 | * 414 | * Desc: This callback gets called when a new stream is being pushed by the 415 | * server. It approves or denies the new stream. 416 | * 417 | * Returns: CURL_PUSH_OK or CURL_PUSH_DENY. 418 | */ 419 | #define CURL_PUSH_OK 0 420 | #define CURL_PUSH_DENY 1 421 | 422 | struct curl_pushheaders; /* forward declaration only */ 423 | 424 | CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h, 425 | size_t num); 426 | CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h, 427 | const char *name); 428 | 429 | typedef int (*curl_push_callback)(CURL *parent, 430 | CURL *easy, 431 | size_t num_headers, 432 | struct curl_pushheaders *headers, 433 | void *userp); 434 | 435 | #ifdef __cplusplus 436 | } /* end of extern "C" */ 437 | #endif 438 | 439 | #endif 440 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/stdcheaders.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDC_HEADERS_H 2 | #define __STDC_HEADERS_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2016, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | #include 26 | 27 | size_t fread(void *, size_t, size_t, FILE *); 28 | size_t fwrite(const void *, size_t, size_t, FILE *); 29 | 30 | int strcasecmp(const char *, const char *); 31 | int strncasecmp(const char *, const char *, size_t); 32 | 33 | #endif /* __STDC_HEADERS_H */ 34 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/system.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_SYSTEM_H 2 | #define __CURL_SYSTEM_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* 26 | * Try to keep one section per platform, compiler and architecture, otherwise, 27 | * if an existing section is reused for a different one and later on the 28 | * original is adjusted, probably the piggybacking one can be adversely 29 | * changed. 30 | * 31 | * In order to differentiate between platforms/compilers/architectures use 32 | * only compiler built in predefined preprocessor symbols. 33 | * 34 | * curl_off_t 35 | * ---------- 36 | * 37 | * For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit 38 | * wide signed integral data type. The width of this data type must remain 39 | * constant and independent of any possible large file support settings. 40 | * 41 | * As an exception to the above, curl_off_t shall be typedef'ed to a 32-bit 42 | * wide signed integral data type if there is no 64-bit type. 43 | * 44 | * As a general rule, curl_off_t shall not be mapped to off_t. This rule shall 45 | * only be violated if off_t is the only 64-bit data type available and the 46 | * size of off_t is independent of large file support settings. Keep your 47 | * build on the safe side avoiding an off_t gating. If you have a 64-bit 48 | * off_t then take for sure that another 64-bit data type exists, dig deeper 49 | * and you will find it. 50 | * 51 | */ 52 | 53 | #if defined(__DJGPP__) || defined(__GO32__) 54 | # if defined(__DJGPP__) && (__DJGPP__ > 1) 55 | # define CURL_TYPEOF_CURL_OFF_T long long 56 | # define CURL_FORMAT_CURL_OFF_T "lld" 57 | # define CURL_FORMAT_CURL_OFF_TU "llu" 58 | # define CURL_SUFFIX_CURL_OFF_T LL 59 | # define CURL_SUFFIX_CURL_OFF_TU ULL 60 | # else 61 | # define CURL_TYPEOF_CURL_OFF_T long 62 | # define CURL_FORMAT_CURL_OFF_T "ld" 63 | # define CURL_FORMAT_CURL_OFF_TU "lu" 64 | # define CURL_SUFFIX_CURL_OFF_T L 65 | # define CURL_SUFFIX_CURL_OFF_TU UL 66 | # endif 67 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 68 | 69 | #elif defined(__SALFORDC__) 70 | # define CURL_TYPEOF_CURL_OFF_T long 71 | # define CURL_FORMAT_CURL_OFF_T "ld" 72 | # define CURL_FORMAT_CURL_OFF_TU "lu" 73 | # define CURL_SUFFIX_CURL_OFF_T L 74 | # define CURL_SUFFIX_CURL_OFF_TU UL 75 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 76 | 77 | #elif defined(__BORLANDC__) 78 | # if (__BORLANDC__ < 0x520) 79 | # define CURL_TYPEOF_CURL_OFF_T long 80 | # define CURL_FORMAT_CURL_OFF_T "ld" 81 | # define CURL_FORMAT_CURL_OFF_TU "lu" 82 | # define CURL_SUFFIX_CURL_OFF_T L 83 | # define CURL_SUFFIX_CURL_OFF_TU UL 84 | # else 85 | # define CURL_TYPEOF_CURL_OFF_T __int64 86 | # define CURL_FORMAT_CURL_OFF_T "I64d" 87 | # define CURL_FORMAT_CURL_OFF_TU "I64u" 88 | # define CURL_SUFFIX_CURL_OFF_T i64 89 | # define CURL_SUFFIX_CURL_OFF_TU ui64 90 | # endif 91 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 92 | 93 | #elif defined(__TURBOC__) 94 | # define CURL_TYPEOF_CURL_OFF_T long 95 | # define CURL_FORMAT_CURL_OFF_T "ld" 96 | # define CURL_FORMAT_CURL_OFF_TU "lu" 97 | # define CURL_SUFFIX_CURL_OFF_T L 98 | # define CURL_SUFFIX_CURL_OFF_TU UL 99 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 100 | 101 | #elif defined(__WATCOMC__) 102 | # if defined(__386__) 103 | # define CURL_TYPEOF_CURL_OFF_T __int64 104 | # define CURL_FORMAT_CURL_OFF_T "I64d" 105 | # define CURL_FORMAT_CURL_OFF_TU "I64u" 106 | # define CURL_SUFFIX_CURL_OFF_T i64 107 | # define CURL_SUFFIX_CURL_OFF_TU ui64 108 | # else 109 | # define CURL_TYPEOF_CURL_OFF_T long 110 | # define CURL_FORMAT_CURL_OFF_T "ld" 111 | # define CURL_FORMAT_CURL_OFF_TU "lu" 112 | # define CURL_SUFFIX_CURL_OFF_T L 113 | # define CURL_SUFFIX_CURL_OFF_TU UL 114 | # endif 115 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 116 | 117 | #elif defined(__POCC__) 118 | # if (__POCC__ < 280) 119 | # define CURL_TYPEOF_CURL_OFF_T long 120 | # define CURL_FORMAT_CURL_OFF_T "ld" 121 | # define CURL_FORMAT_CURL_OFF_TU "lu" 122 | # define CURL_SUFFIX_CURL_OFF_T L 123 | # define CURL_SUFFIX_CURL_OFF_TU UL 124 | # elif defined(_MSC_VER) 125 | # define CURL_TYPEOF_CURL_OFF_T __int64 126 | # define CURL_FORMAT_CURL_OFF_T "I64d" 127 | # define CURL_FORMAT_CURL_OFF_TU "I64u" 128 | # define CURL_SUFFIX_CURL_OFF_T i64 129 | # define CURL_SUFFIX_CURL_OFF_TU ui64 130 | # else 131 | # define CURL_TYPEOF_CURL_OFF_T long long 132 | # define CURL_FORMAT_CURL_OFF_T "lld" 133 | # define CURL_FORMAT_CURL_OFF_TU "llu" 134 | # define CURL_SUFFIX_CURL_OFF_T LL 135 | # define CURL_SUFFIX_CURL_OFF_TU ULL 136 | # endif 137 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 138 | 139 | #elif defined(__LCC__) 140 | # define CURL_TYPEOF_CURL_OFF_T long 141 | # define CURL_FORMAT_CURL_OFF_T "ld" 142 | # define CURL_FORMAT_CURL_OFF_TU "lu" 143 | # define CURL_SUFFIX_CURL_OFF_T L 144 | # define CURL_SUFFIX_CURL_OFF_TU UL 145 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 146 | 147 | #elif defined(__SYMBIAN32__) 148 | # if defined(__EABI__) /* Treat all ARM compilers equally */ 149 | # define CURL_TYPEOF_CURL_OFF_T long long 150 | # define CURL_FORMAT_CURL_OFF_T "lld" 151 | # define CURL_FORMAT_CURL_OFF_TU "llu" 152 | # define CURL_SUFFIX_CURL_OFF_T LL 153 | # define CURL_SUFFIX_CURL_OFF_TU ULL 154 | # elif defined(__CW32__) 155 | # pragma longlong on 156 | # define CURL_TYPEOF_CURL_OFF_T long long 157 | # define CURL_FORMAT_CURL_OFF_T "lld" 158 | # define CURL_FORMAT_CURL_OFF_TU "llu" 159 | # define CURL_SUFFIX_CURL_OFF_T LL 160 | # define CURL_SUFFIX_CURL_OFF_TU ULL 161 | # elif defined(__VC32__) 162 | # define CURL_TYPEOF_CURL_OFF_T __int64 163 | # define CURL_FORMAT_CURL_OFF_T "lld" 164 | # define CURL_FORMAT_CURL_OFF_TU "llu" 165 | # define CURL_SUFFIX_CURL_OFF_T LL 166 | # define CURL_SUFFIX_CURL_OFF_TU ULL 167 | # endif 168 | # define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int 169 | 170 | #elif defined(__MWERKS__) 171 | # define CURL_TYPEOF_CURL_OFF_T long long 172 | # define CURL_FORMAT_CURL_OFF_T "lld" 173 | # define CURL_FORMAT_CURL_OFF_TU "llu" 174 | # define CURL_SUFFIX_CURL_OFF_T LL 175 | # define CURL_SUFFIX_CURL_OFF_TU ULL 176 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 177 | 178 | #elif defined(_WIN32_WCE) 179 | # define CURL_TYPEOF_CURL_OFF_T __int64 180 | # define CURL_FORMAT_CURL_OFF_T "I64d" 181 | # define CURL_FORMAT_CURL_OFF_TU "I64u" 182 | # define CURL_SUFFIX_CURL_OFF_T i64 183 | # define CURL_SUFFIX_CURL_OFF_TU ui64 184 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 185 | 186 | #elif defined(__MINGW32__) 187 | # define CURL_TYPEOF_CURL_OFF_T long long 188 | # define CURL_FORMAT_CURL_OFF_T "I64d" 189 | # define CURL_FORMAT_CURL_OFF_TU "I64u" 190 | # define CURL_SUFFIX_CURL_OFF_T LL 191 | # define CURL_SUFFIX_CURL_OFF_TU ULL 192 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 193 | # define CURL_PULL_SYS_TYPES_H 1 194 | # define CURL_PULL_WS2TCPIP_H 1 195 | 196 | #elif defined(__VMS) 197 | # if defined(__VAX) 198 | # define CURL_TYPEOF_CURL_OFF_T long 199 | # define CURL_FORMAT_CURL_OFF_T "ld" 200 | # define CURL_FORMAT_CURL_OFF_TU "lu" 201 | # define CURL_SUFFIX_CURL_OFF_T L 202 | # define CURL_SUFFIX_CURL_OFF_TU UL 203 | # else 204 | # define CURL_TYPEOF_CURL_OFF_T long long 205 | # define CURL_FORMAT_CURL_OFF_T "lld" 206 | # define CURL_FORMAT_CURL_OFF_TU "llu" 207 | # define CURL_SUFFIX_CURL_OFF_T LL 208 | # define CURL_SUFFIX_CURL_OFF_TU ULL 209 | # endif 210 | # define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int 211 | 212 | #elif defined(__OS400__) 213 | # if defined(__ILEC400__) 214 | # define CURL_TYPEOF_CURL_OFF_T long long 215 | # define CURL_FORMAT_CURL_OFF_T "lld" 216 | # define CURL_FORMAT_CURL_OFF_TU "llu" 217 | # define CURL_SUFFIX_CURL_OFF_T LL 218 | # define CURL_SUFFIX_CURL_OFF_TU ULL 219 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 220 | # define CURL_PULL_SYS_TYPES_H 1 221 | # define CURL_PULL_SYS_SOCKET_H 1 222 | # endif 223 | 224 | #elif defined(__MVS__) 225 | # if defined(__IBMC__) || defined(__IBMCPP__) 226 | # if defined(_ILP32) 227 | # elif defined(_LP64) 228 | # endif 229 | # if defined(_LONG_LONG) 230 | # define CURL_TYPEOF_CURL_OFF_T long long 231 | # define CURL_FORMAT_CURL_OFF_T "lld" 232 | # define CURL_FORMAT_CURL_OFF_TU "llu" 233 | # define CURL_SUFFIX_CURL_OFF_T LL 234 | # define CURL_SUFFIX_CURL_OFF_TU ULL 235 | # elif defined(_LP64) 236 | # define CURL_TYPEOF_CURL_OFF_T long 237 | # define CURL_FORMAT_CURL_OFF_T "ld" 238 | # define CURL_FORMAT_CURL_OFF_TU "lu" 239 | # define CURL_SUFFIX_CURL_OFF_T L 240 | # define CURL_SUFFIX_CURL_OFF_TU UL 241 | # else 242 | # define CURL_TYPEOF_CURL_OFF_T long 243 | # define CURL_FORMAT_CURL_OFF_T "ld" 244 | # define CURL_FORMAT_CURL_OFF_TU "lu" 245 | # define CURL_SUFFIX_CURL_OFF_T L 246 | # define CURL_SUFFIX_CURL_OFF_TU UL 247 | # endif 248 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 249 | # define CURL_PULL_SYS_TYPES_H 1 250 | # define CURL_PULL_SYS_SOCKET_H 1 251 | # endif 252 | 253 | #elif defined(__370__) 254 | # if defined(__IBMC__) || defined(__IBMCPP__) 255 | # if defined(_ILP32) 256 | # elif defined(_LP64) 257 | # endif 258 | # if defined(_LONG_LONG) 259 | # define CURL_TYPEOF_CURL_OFF_T long long 260 | # define CURL_FORMAT_CURL_OFF_T "lld" 261 | # define CURL_FORMAT_CURL_OFF_TU "llu" 262 | # define CURL_SUFFIX_CURL_OFF_T LL 263 | # define CURL_SUFFIX_CURL_OFF_TU ULL 264 | # elif defined(_LP64) 265 | # define CURL_TYPEOF_CURL_OFF_T long 266 | # define CURL_FORMAT_CURL_OFF_T "ld" 267 | # define CURL_FORMAT_CURL_OFF_TU "lu" 268 | # define CURL_SUFFIX_CURL_OFF_T L 269 | # define CURL_SUFFIX_CURL_OFF_TU UL 270 | # else 271 | # define CURL_TYPEOF_CURL_OFF_T long 272 | # define CURL_FORMAT_CURL_OFF_T "ld" 273 | # define CURL_FORMAT_CURL_OFF_TU "lu" 274 | # define CURL_SUFFIX_CURL_OFF_T L 275 | # define CURL_SUFFIX_CURL_OFF_TU UL 276 | # endif 277 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 278 | # define CURL_PULL_SYS_TYPES_H 1 279 | # define CURL_PULL_SYS_SOCKET_H 1 280 | # endif 281 | 282 | #elif defined(TPF) 283 | # define CURL_TYPEOF_CURL_OFF_T long 284 | # define CURL_FORMAT_CURL_OFF_T "ld" 285 | # define CURL_FORMAT_CURL_OFF_TU "lu" 286 | # define CURL_SUFFIX_CURL_OFF_T L 287 | # define CURL_SUFFIX_CURL_OFF_TU UL 288 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 289 | 290 | #elif defined(__TINYC__) /* also known as tcc */ 291 | 292 | # define CURL_TYPEOF_CURL_OFF_T long long 293 | # define CURL_FORMAT_CURL_OFF_T "lld" 294 | # define CURL_FORMAT_CURL_OFF_TU "llu" 295 | # define CURL_SUFFIX_CURL_OFF_T LL 296 | # define CURL_SUFFIX_CURL_OFF_TU ULL 297 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 298 | # define CURL_PULL_SYS_TYPES_H 1 299 | # define CURL_PULL_SYS_SOCKET_H 1 300 | 301 | #elif defined(__SUNPRO_C) /* Oracle Solaris Studio */ 302 | # if !defined(__LP64) && (defined(__ILP32) || \ 303 | defined(__i386) || defined(__sparcv8)) 304 | # define CURL_TYPEOF_CURL_OFF_T long long 305 | # define CURL_FORMAT_CURL_OFF_T "lld" 306 | # define CURL_FORMAT_CURL_OFF_TU "llu" 307 | # define CURL_SUFFIX_CURL_OFF_T LL 308 | # define CURL_SUFFIX_CURL_OFF_TU ULL 309 | # elif defined(__LP64) || \ 310 | defined(__amd64) || defined(__sparcv9) 311 | # define CURL_TYPEOF_CURL_OFF_T long 312 | # define CURL_FORMAT_CURL_OFF_T "ld" 313 | # define CURL_FORMAT_CURL_OFF_TU "lu" 314 | # define CURL_SUFFIX_CURL_OFF_T L 315 | # define CURL_SUFFIX_CURL_OFF_TU UL 316 | # endif 317 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 318 | # define CURL_PULL_SYS_TYPES_H 1 319 | # define CURL_PULL_SYS_SOCKET_H 1 320 | 321 | /* ===================================== */ 322 | /* KEEP MSVC THE PENULTIMATE ENTRY */ 323 | /* ===================================== */ 324 | 325 | #elif defined(_MSC_VER) 326 | # if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64) 327 | # define CURL_TYPEOF_CURL_OFF_T __int64 328 | # define CURL_FORMAT_CURL_OFF_T "I64d" 329 | # define CURL_FORMAT_CURL_OFF_TU "I64u" 330 | # define CURL_SUFFIX_CURL_OFF_T i64 331 | # define CURL_SUFFIX_CURL_OFF_TU ui64 332 | # else 333 | # define CURL_TYPEOF_CURL_OFF_T long 334 | # define CURL_FORMAT_CURL_OFF_T "ld" 335 | # define CURL_FORMAT_CURL_OFF_TU "lu" 336 | # define CURL_SUFFIX_CURL_OFF_T L 337 | # define CURL_SUFFIX_CURL_OFF_TU UL 338 | # endif 339 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 340 | 341 | /* ===================================== */ 342 | /* KEEP GENERIC GCC THE LAST ENTRY */ 343 | /* ===================================== */ 344 | 345 | #elif defined(__GNUC__) 346 | # if !defined(__LP64__) && \ 347 | (defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \ 348 | defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \ 349 | defined(__sparc__) || defined(__mips__) || defined(__sh__) || \ 350 | defined(__XTENSA__) || \ 351 | (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4)) 352 | # define CURL_TYPEOF_CURL_OFF_T long long 353 | # define CURL_FORMAT_CURL_OFF_T "lld" 354 | # define CURL_FORMAT_CURL_OFF_TU "llu" 355 | # define CURL_SUFFIX_CURL_OFF_T LL 356 | # define CURL_SUFFIX_CURL_OFF_TU ULL 357 | # elif defined(__LP64__) || \ 358 | defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \ 359 | (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) 360 | # define CURL_TYPEOF_CURL_OFF_T long 361 | # define CURL_FORMAT_CURL_OFF_T "ld" 362 | # define CURL_FORMAT_CURL_OFF_TU "lu" 363 | # define CURL_SUFFIX_CURL_OFF_T L 364 | # define CURL_SUFFIX_CURL_OFF_TU UL 365 | # endif 366 | # define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t 367 | # define CURL_PULL_SYS_TYPES_H 1 368 | # define CURL_PULL_SYS_SOCKET_H 1 369 | 370 | #else 371 | /* generic "safe guess" on old 32 bit style */ 372 | # define CURL_TYPEOF_CURL_OFF_T long 373 | # define CURL_FORMAT_CURL_OFF_T "ld" 374 | # define CURL_FORMAT_CURL_OFF_TU "lu" 375 | # define CURL_SUFFIX_CURL_OFF_T L 376 | # define CURL_SUFFIX_CURL_OFF_TU UL 377 | # define CURL_TYPEOF_CURL_SOCKLEN_T int 378 | #endif 379 | 380 | #ifdef _AIX 381 | /* AIX needs */ 382 | #define CURL_PULL_SYS_POLL_H 383 | #endif 384 | 385 | 386 | /* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */ 387 | /* ws2tcpip.h is required here to properly make type definitions below. */ 388 | #ifdef CURL_PULL_WS2TCPIP_H 389 | # include 390 | # include 391 | # include 392 | #endif 393 | 394 | /* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */ 395 | /* sys/types.h is required here to properly make type definitions below. */ 396 | #ifdef CURL_PULL_SYS_TYPES_H 397 | # include 398 | #endif 399 | 400 | /* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */ 401 | /* sys/socket.h is required here to properly make type definitions below. */ 402 | #ifdef CURL_PULL_SYS_SOCKET_H 403 | # include 404 | #endif 405 | 406 | /* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */ 407 | /* sys/poll.h is required here to properly make type definitions below. */ 408 | #ifdef CURL_PULL_SYS_POLL_H 409 | # include 410 | #endif 411 | 412 | /* Data type definition of curl_socklen_t. */ 413 | #ifdef CURL_TYPEOF_CURL_SOCKLEN_T 414 | typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t; 415 | #endif 416 | 417 | /* Data type definition of curl_off_t. */ 418 | 419 | #ifdef CURL_TYPEOF_CURL_OFF_T 420 | typedef CURL_TYPEOF_CURL_OFF_T curl_off_t; 421 | #endif 422 | 423 | /* 424 | * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow 425 | * these to be visible and exported by the external libcurl interface API, 426 | * while also making them visible to the library internals, simply including 427 | * curl_setup.h, without actually needing to include curl.h internally. 428 | * If some day this section would grow big enough, all this should be moved 429 | * to its own header file. 430 | */ 431 | 432 | /* 433 | * Figure out if we can use the ## preprocessor operator, which is supported 434 | * by ISO/ANSI C and C++. Some compilers support it without setting __STDC__ 435 | * or __cplusplus so we need to carefully check for them too. 436 | */ 437 | 438 | #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \ 439 | defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \ 440 | defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \ 441 | defined(__ILEC400__) 442 | /* This compiler is believed to have an ISO compatible preprocessor */ 443 | #define CURL_ISOCPP 444 | #else 445 | /* This compiler is believed NOT to have an ISO compatible preprocessor */ 446 | #undef CURL_ISOCPP 447 | #endif 448 | 449 | /* 450 | * Macros for minimum-width signed and unsigned curl_off_t integer constants. 451 | */ 452 | 453 | #if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551) 454 | # define __CURL_OFF_T_C_HLPR2(x) x 455 | # define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x) 456 | # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ 457 | __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T) 458 | # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \ 459 | __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU) 460 | #else 461 | # ifdef CURL_ISOCPP 462 | # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix 463 | # else 464 | # define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix 465 | # endif 466 | # define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix) 467 | # define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T) 468 | # define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU) 469 | #endif 470 | 471 | #endif /* __CURL_SYSTEM_H */ 472 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/include/curl/typecheck-gcc.h: -------------------------------------------------------------------------------- 1 | #ifndef __CURL_TYPECHECK_GCC_H 2 | #define __CURL_TYPECHECK_GCC_H 3 | /*************************************************************************** 4 | * _ _ ____ _ 5 | * Project ___| | | | _ \| | 6 | * / __| | | | |_) | | 7 | * | (__| |_| | _ <| |___ 8 | * \___|\___/|_| \_\_____| 9 | * 10 | * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. 11 | * 12 | * This software is licensed as described in the file COPYING, which 13 | * you should have received as part of this distribution. The terms 14 | * are also available at https://curl.haxx.se/docs/copyright.html. 15 | * 16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 | * copies of the Software, and permit persons to whom the Software is 18 | * furnished to do so, under the terms of the COPYING file. 19 | * 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 | * KIND, either express or implied. 22 | * 23 | ***************************************************************************/ 24 | 25 | /* wraps curl_easy_setopt() with typechecking */ 26 | 27 | /* To add a new kind of warning, add an 28 | * if(_curl_is_sometype_option(_curl_opt)) 29 | * if(!_curl_is_sometype(value)) 30 | * _curl_easy_setopt_err_sometype(); 31 | * block and define _curl_is_sometype_option, _curl_is_sometype and 32 | * _curl_easy_setopt_err_sometype below 33 | * 34 | * NOTE: We use two nested 'if' statements here instead of the && operator, in 35 | * order to work around gcc bug #32061. It affects only gcc 4.3.x/4.4.x 36 | * when compiling with -Wlogical-op. 37 | * 38 | * To add an option that uses the same type as an existing option, you'll just 39 | * need to extend the appropriate _curl_*_option macro 40 | */ 41 | #define curl_easy_setopt(handle, option, value) \ 42 | __extension__ ({ \ 43 | __typeof__(option) _curl_opt = option; \ 44 | if(__builtin_constant_p(_curl_opt)) { \ 45 | if(_curl_is_long_option(_curl_opt)) \ 46 | if(!_curl_is_long(value)) \ 47 | _curl_easy_setopt_err_long(); \ 48 | if(_curl_is_off_t_option(_curl_opt)) \ 49 | if(!_curl_is_off_t(value)) \ 50 | _curl_easy_setopt_err_curl_off_t(); \ 51 | if(_curl_is_string_option(_curl_opt)) \ 52 | if(!_curl_is_string(value)) \ 53 | _curl_easy_setopt_err_string(); \ 54 | if(_curl_is_write_cb_option(_curl_opt)) \ 55 | if(!_curl_is_write_cb(value)) \ 56 | _curl_easy_setopt_err_write_callback(); \ 57 | if((_curl_opt) == CURLOPT_READFUNCTION) \ 58 | if(!_curl_is_read_cb(value)) \ 59 | _curl_easy_setopt_err_read_cb(); \ 60 | if((_curl_opt) == CURLOPT_IOCTLFUNCTION) \ 61 | if(!_curl_is_ioctl_cb(value)) \ 62 | _curl_easy_setopt_err_ioctl_cb(); \ 63 | if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION) \ 64 | if(!_curl_is_sockopt_cb(value)) \ 65 | _curl_easy_setopt_err_sockopt_cb(); \ 66 | if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION) \ 67 | if(!_curl_is_opensocket_cb(value)) \ 68 | _curl_easy_setopt_err_opensocket_cb(); \ 69 | if((_curl_opt) == CURLOPT_PROGRESSFUNCTION) \ 70 | if(!_curl_is_progress_cb(value)) \ 71 | _curl_easy_setopt_err_progress_cb(); \ 72 | if((_curl_opt) == CURLOPT_DEBUGFUNCTION) \ 73 | if(!_curl_is_debug_cb(value)) \ 74 | _curl_easy_setopt_err_debug_cb(); \ 75 | if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION) \ 76 | if(!_curl_is_ssl_ctx_cb(value)) \ 77 | _curl_easy_setopt_err_ssl_ctx_cb(); \ 78 | if(_curl_is_conv_cb_option(_curl_opt)) \ 79 | if(!_curl_is_conv_cb(value)) \ 80 | _curl_easy_setopt_err_conv_cb(); \ 81 | if((_curl_opt) == CURLOPT_SEEKFUNCTION) \ 82 | if(!_curl_is_seek_cb(value)) \ 83 | _curl_easy_setopt_err_seek_cb(); \ 84 | if(_curl_is_cb_data_option(_curl_opt)) \ 85 | if(!_curl_is_cb_data(value)) \ 86 | _curl_easy_setopt_err_cb_data(); \ 87 | if((_curl_opt) == CURLOPT_ERRORBUFFER) \ 88 | if(!_curl_is_error_buffer(value)) \ 89 | _curl_easy_setopt_err_error_buffer(); \ 90 | if((_curl_opt) == CURLOPT_STDERR) \ 91 | if(!_curl_is_FILE(value)) \ 92 | _curl_easy_setopt_err_FILE(); \ 93 | if(_curl_is_postfields_option(_curl_opt)) \ 94 | if(!_curl_is_postfields(value)) \ 95 | _curl_easy_setopt_err_postfields(); \ 96 | if((_curl_opt) == CURLOPT_HTTPPOST) \ 97 | if(!_curl_is_arr((value), struct curl_httppost)) \ 98 | _curl_easy_setopt_err_curl_httpost(); \ 99 | if((_curl_opt) == CURLOPT_MIMEPOST) \ 100 | if(!_curl_is_ptr((value), curl_mime)) \ 101 | _curl_easy_setopt_err_curl_mimepost(); \ 102 | if(_curl_is_slist_option(_curl_opt)) \ 103 | if(!_curl_is_arr((value), struct curl_slist)) \ 104 | _curl_easy_setopt_err_curl_slist(); \ 105 | if((_curl_opt) == CURLOPT_SHARE) \ 106 | if(!_curl_is_ptr((value), CURLSH)) \ 107 | _curl_easy_setopt_err_CURLSH(); \ 108 | } \ 109 | curl_easy_setopt(handle, _curl_opt, value); \ 110 | }) 111 | 112 | /* wraps curl_easy_getinfo() with typechecking */ 113 | /* FIXME: don't allow const pointers */ 114 | #define curl_easy_getinfo(handle, info, arg) \ 115 | __extension__ ({ \ 116 | __typeof__(info) _curl_info = info; \ 117 | if(__builtin_constant_p(_curl_info)) { \ 118 | if(_curl_is_string_info(_curl_info)) \ 119 | if(!_curl_is_arr((arg), char *)) \ 120 | _curl_easy_getinfo_err_string(); \ 121 | if(_curl_is_long_info(_curl_info)) \ 122 | if(!_curl_is_arr((arg), long)) \ 123 | _curl_easy_getinfo_err_long(); \ 124 | if(_curl_is_double_info(_curl_info)) \ 125 | if(!_curl_is_arr((arg), double)) \ 126 | _curl_easy_getinfo_err_double(); \ 127 | if(_curl_is_slist_info(_curl_info)) \ 128 | if(!_curl_is_arr((arg), struct curl_slist *)) \ 129 | _curl_easy_getinfo_err_curl_slist(); \ 130 | if(_curl_is_tlssessioninfo_info(_curl_info)) \ 131 | if(!_curl_is_arr((arg), struct curl_tlssessioninfo *)) \ 132 | _curl_easy_getinfo_err_curl_tlssesssioninfo(); \ 133 | if(_curl_is_certinfo_info(_curl_info)) \ 134 | if(!_curl_is_arr((arg), struct curl_certinfo *)) \ 135 | _curl_easy_getinfo_err_curl_certinfo(); \ 136 | if(_curl_is_socket_info(_curl_info)) \ 137 | if(!_curl_is_arr((arg), curl_socket_t)) \ 138 | _curl_easy_getinfo_err_curl_socket(); \ 139 | if(_curl_is_off_t_info(_curl_info)) \ 140 | if(!_curl_is_arr((arg), curl_off_t)) \ 141 | _curl_easy_getinfo_err_curl_off_t(); \ 142 | } \ 143 | curl_easy_getinfo(handle, _curl_info, arg); \ 144 | }) 145 | 146 | /* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(), 147 | * for now just make sure that the functions are called with three 148 | * arguments 149 | */ 150 | #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param) 151 | #define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param) 152 | 153 | 154 | /* the actual warnings, triggered by calling the _curl_easy_setopt_err* 155 | * functions */ 156 | 157 | /* To define a new warning, use _CURL_WARNING(identifier, "message") */ 158 | #define _CURL_WARNING(id, message) \ 159 | static void __attribute__((__warning__(message))) \ 160 | __attribute__((__unused__)) __attribute__((__noinline__)) \ 161 | id(void) { __asm__(""); } 162 | 163 | _CURL_WARNING(_curl_easy_setopt_err_long, 164 | "curl_easy_setopt expects a long argument for this option") 165 | _CURL_WARNING(_curl_easy_setopt_err_curl_off_t, 166 | "curl_easy_setopt expects a curl_off_t argument for this option") 167 | _CURL_WARNING(_curl_easy_setopt_err_string, 168 | "curl_easy_setopt expects a " 169 | "string ('char *' or char[]) argument for this option" 170 | ) 171 | _CURL_WARNING(_curl_easy_setopt_err_write_callback, 172 | "curl_easy_setopt expects a curl_write_callback argument for this option") 173 | _CURL_WARNING(_curl_easy_setopt_err_read_cb, 174 | "curl_easy_setopt expects a curl_read_callback argument for this option") 175 | _CURL_WARNING(_curl_easy_setopt_err_ioctl_cb, 176 | "curl_easy_setopt expects a curl_ioctl_callback argument for this option") 177 | _CURL_WARNING(_curl_easy_setopt_err_sockopt_cb, 178 | "curl_easy_setopt expects a curl_sockopt_callback argument for this option") 179 | _CURL_WARNING(_curl_easy_setopt_err_opensocket_cb, 180 | "curl_easy_setopt expects a " 181 | "curl_opensocket_callback argument for this option" 182 | ) 183 | _CURL_WARNING(_curl_easy_setopt_err_progress_cb, 184 | "curl_easy_setopt expects a curl_progress_callback argument for this option") 185 | _CURL_WARNING(_curl_easy_setopt_err_debug_cb, 186 | "curl_easy_setopt expects a curl_debug_callback argument for this option") 187 | _CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb, 188 | "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option") 189 | _CURL_WARNING(_curl_easy_setopt_err_conv_cb, 190 | "curl_easy_setopt expects a curl_conv_callback argument for this option") 191 | _CURL_WARNING(_curl_easy_setopt_err_seek_cb, 192 | "curl_easy_setopt expects a curl_seek_callback argument for this option") 193 | _CURL_WARNING(_curl_easy_setopt_err_cb_data, 194 | "curl_easy_setopt expects a " 195 | "private data pointer as argument for this option") 196 | _CURL_WARNING(_curl_easy_setopt_err_error_buffer, 197 | "curl_easy_setopt expects a " 198 | "char buffer of CURL_ERROR_SIZE as argument for this option") 199 | _CURL_WARNING(_curl_easy_setopt_err_FILE, 200 | "curl_easy_setopt expects a 'FILE *' argument for this option") 201 | _CURL_WARNING(_curl_easy_setopt_err_postfields, 202 | "curl_easy_setopt expects a 'void *' or 'char *' argument for this option") 203 | _CURL_WARNING(_curl_easy_setopt_err_curl_httpost, 204 | "curl_easy_setopt expects a 'struct curl_httppost *' " 205 | "argument for this option") 206 | _CURL_WARNING(_curl_easy_setopt_err_curl_mimepost, 207 | "curl_easy_setopt expects a 'curl_mime *' " 208 | "argument for this option") 209 | _CURL_WARNING(_curl_easy_setopt_err_curl_slist, 210 | "curl_easy_setopt expects a 'struct curl_slist *' argument for this option") 211 | _CURL_WARNING(_curl_easy_setopt_err_CURLSH, 212 | "curl_easy_setopt expects a CURLSH* argument for this option") 213 | 214 | _CURL_WARNING(_curl_easy_getinfo_err_string, 215 | "curl_easy_getinfo expects a pointer to 'char *' for this info") 216 | _CURL_WARNING(_curl_easy_getinfo_err_long, 217 | "curl_easy_getinfo expects a pointer to long for this info") 218 | _CURL_WARNING(_curl_easy_getinfo_err_double, 219 | "curl_easy_getinfo expects a pointer to double for this info") 220 | _CURL_WARNING(_curl_easy_getinfo_err_curl_slist, 221 | "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info") 222 | _CURL_WARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo, 223 | "curl_easy_getinfo expects a pointer to " 224 | "'struct curl_tlssessioninfo *' for this info") 225 | _CURL_WARNING(_curl_easy_getinfo_err_curl_certinfo, 226 | "curl_easy_getinfo expects a pointer to " 227 | "'struct curl_certinfo *' for this info") 228 | _CURL_WARNING(_curl_easy_getinfo_err_curl_socket, 229 | "curl_easy_getinfo expects a pointer to curl_socket_t for this info") 230 | _CURL_WARNING(_curl_easy_getinfo_err_curl_off_t, 231 | "curl_easy_getinfo expects a pointer to curl_off_t for this info") 232 | 233 | /* groups of curl_easy_setops options that take the same type of argument */ 234 | 235 | /* To add a new option to one of the groups, just add 236 | * (option) == CURLOPT_SOMETHING 237 | * to the or-expression. If the option takes a long or curl_off_t, you don't 238 | * have to do anything 239 | */ 240 | 241 | /* evaluates to true if option takes a long argument */ 242 | #define _curl_is_long_option(option) \ 243 | (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT) 244 | 245 | #define _curl_is_off_t_option(option) \ 246 | ((option) > CURLOPTTYPE_OFF_T) 247 | 248 | /* evaluates to true if option takes a char* argument */ 249 | #define _curl_is_string_option(option) \ 250 | ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \ 251 | (option) == CURLOPT_ACCEPT_ENCODING || \ 252 | (option) == CURLOPT_CAINFO || \ 253 | (option) == CURLOPT_CAPATH || \ 254 | (option) == CURLOPT_COOKIE || \ 255 | (option) == CURLOPT_COOKIEFILE || \ 256 | (option) == CURLOPT_COOKIEJAR || \ 257 | (option) == CURLOPT_COOKIELIST || \ 258 | (option) == CURLOPT_CRLFILE || \ 259 | (option) == CURLOPT_CUSTOMREQUEST || \ 260 | (option) == CURLOPT_DEFAULT_PROTOCOL || \ 261 | (option) == CURLOPT_DNS_INTERFACE || \ 262 | (option) == CURLOPT_DNS_LOCAL_IP4 || \ 263 | (option) == CURLOPT_DNS_LOCAL_IP6 || \ 264 | (option) == CURLOPT_DNS_SERVERS || \ 265 | (option) == CURLOPT_EGDSOCKET || \ 266 | (option) == CURLOPT_FTPPORT || \ 267 | (option) == CURLOPT_FTP_ACCOUNT || \ 268 | (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ 269 | (option) == CURLOPT_INTERFACE || \ 270 | (option) == CURLOPT_ISSUERCERT || \ 271 | (option) == CURLOPT_KEYPASSWD || \ 272 | (option) == CURLOPT_KRBLEVEL || \ 273 | (option) == CURLOPT_LOGIN_OPTIONS || \ 274 | (option) == CURLOPT_MAIL_AUTH || \ 275 | (option) == CURLOPT_MAIL_FROM || \ 276 | (option) == CURLOPT_NETRC_FILE || \ 277 | (option) == CURLOPT_NOPROXY || \ 278 | (option) == CURLOPT_PASSWORD || \ 279 | (option) == CURLOPT_PINNEDPUBLICKEY || \ 280 | (option) == CURLOPT_PRE_PROXY || \ 281 | (option) == CURLOPT_PROXY || \ 282 | (option) == CURLOPT_PROXYPASSWORD || \ 283 | (option) == CURLOPT_PROXYUSERNAME || \ 284 | (option) == CURLOPT_PROXYUSERPWD || \ 285 | (option) == CURLOPT_PROXY_CAINFO || \ 286 | (option) == CURLOPT_PROXY_CAPATH || \ 287 | (option) == CURLOPT_PROXY_CRLFILE || \ 288 | (option) == CURLOPT_PROXY_KEYPASSWD || \ 289 | (option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \ 290 | (option) == CURLOPT_PROXY_SERVICE_NAME || \ 291 | (option) == CURLOPT_PROXY_SSLCERT || \ 292 | (option) == CURLOPT_PROXY_SSLCERTTYPE || \ 293 | (option) == CURLOPT_PROXY_SSLKEY || \ 294 | (option) == CURLOPT_PROXY_SSLKEYTYPE || \ 295 | (option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \ 296 | (option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \ 297 | (option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \ 298 | (option) == CURLOPT_PROXY_TLSAUTH_TYPE || \ 299 | (option) == CURLOPT_RANDOM_FILE || \ 300 | (option) == CURLOPT_RANGE || \ 301 | (option) == CURLOPT_REFERER || \ 302 | (option) == CURLOPT_RTSP_SESSION_ID || \ 303 | (option) == CURLOPT_RTSP_STREAM_URI || \ 304 | (option) == CURLOPT_RTSP_TRANSPORT || \ 305 | (option) == CURLOPT_SERVICE_NAME || \ 306 | (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ 307 | (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ 308 | (option) == CURLOPT_SSH_KNOWNHOSTS || \ 309 | (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ 310 | (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ 311 | (option) == CURLOPT_SSLCERT || \ 312 | (option) == CURLOPT_SSLCERTTYPE || \ 313 | (option) == CURLOPT_SSLENGINE || \ 314 | (option) == CURLOPT_SSLKEY || \ 315 | (option) == CURLOPT_SSLKEYTYPE || \ 316 | (option) == CURLOPT_SSL_CIPHER_LIST || \ 317 | (option) == CURLOPT_TLSAUTH_PASSWORD || \ 318 | (option) == CURLOPT_TLSAUTH_TYPE || \ 319 | (option) == CURLOPT_TLSAUTH_USERNAME || \ 320 | (option) == CURLOPT_UNIX_SOCKET_PATH || \ 321 | (option) == CURLOPT_URL || \ 322 | (option) == CURLOPT_USERAGENT || \ 323 | (option) == CURLOPT_USERNAME || \ 324 | (option) == CURLOPT_USERPWD || \ 325 | (option) == CURLOPT_XOAUTH2_BEARER || \ 326 | 0) 327 | 328 | /* evaluates to true if option takes a curl_write_callback argument */ 329 | #define _curl_is_write_cb_option(option) \ 330 | ((option) == CURLOPT_HEADERFUNCTION || \ 331 | (option) == CURLOPT_WRITEFUNCTION) 332 | 333 | /* evaluates to true if option takes a curl_conv_callback argument */ 334 | #define _curl_is_conv_cb_option(option) \ 335 | ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ 336 | (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ 337 | (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) 338 | 339 | /* evaluates to true if option takes a data argument to pass to a callback */ 340 | #define _curl_is_cb_data_option(option) \ 341 | ((option) == CURLOPT_CHUNK_DATA || \ 342 | (option) == CURLOPT_CLOSESOCKETDATA || \ 343 | (option) == CURLOPT_DEBUGDATA || \ 344 | (option) == CURLOPT_FNMATCH_DATA || \ 345 | (option) == CURLOPT_HEADERDATA || \ 346 | (option) == CURLOPT_INTERLEAVEDATA || \ 347 | (option) == CURLOPT_IOCTLDATA || \ 348 | (option) == CURLOPT_OPENSOCKETDATA || \ 349 | (option) == CURLOPT_PRIVATE || \ 350 | (option) == CURLOPT_PROGRESSDATA || \ 351 | (option) == CURLOPT_READDATA || \ 352 | (option) == CURLOPT_SEEKDATA || \ 353 | (option) == CURLOPT_SOCKOPTDATA || \ 354 | (option) == CURLOPT_SSH_KEYDATA || \ 355 | (option) == CURLOPT_SSL_CTX_DATA || \ 356 | (option) == CURLOPT_WRITEDATA || \ 357 | 0) 358 | 359 | /* evaluates to true if option takes a POST data argument (void* or char*) */ 360 | #define _curl_is_postfields_option(option) \ 361 | ((option) == CURLOPT_POSTFIELDS || \ 362 | (option) == CURLOPT_COPYPOSTFIELDS || \ 363 | 0) 364 | 365 | /* evaluates to true if option takes a struct curl_slist * argument */ 366 | #define _curl_is_slist_option(option) \ 367 | ((option) == CURLOPT_HTTP200ALIASES || \ 368 | (option) == CURLOPT_HTTPHEADER || \ 369 | (option) == CURLOPT_MAIL_RCPT || \ 370 | (option) == CURLOPT_POSTQUOTE || \ 371 | (option) == CURLOPT_PREQUOTE || \ 372 | (option) == CURLOPT_PROXYHEADER || \ 373 | (option) == CURLOPT_QUOTE || \ 374 | (option) == CURLOPT_RESOLVE || \ 375 | (option) == CURLOPT_TELNETOPTIONS || \ 376 | 0) 377 | 378 | /* groups of curl_easy_getinfo infos that take the same type of argument */ 379 | 380 | /* evaluates to true if info expects a pointer to char * argument */ 381 | #define _curl_is_string_info(info) \ 382 | (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG) 383 | 384 | /* evaluates to true if info expects a pointer to long argument */ 385 | #define _curl_is_long_info(info) \ 386 | (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) 387 | 388 | /* evaluates to true if info expects a pointer to double argument */ 389 | #define _curl_is_double_info(info) \ 390 | (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) 391 | 392 | /* true if info expects a pointer to struct curl_slist * argument */ 393 | #define _curl_is_slist_info(info) \ 394 | (((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST)) 395 | 396 | /* true if info expects a pointer to struct curl_tlssessioninfo * argument */ 397 | #define _curl_is_tlssessioninfo_info(info) \ 398 | (((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION)) 399 | 400 | /* true if info expects a pointer to struct curl_certinfo * argument */ 401 | #define _curl_is_certinfo_info(info) ((info) == CURLINFO_CERTINFO) 402 | 403 | /* true if info expects a pointer to struct curl_socket_t argument */ 404 | #define _curl_is_socket_info(info) \ 405 | (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T) 406 | 407 | /* true if info expects a pointer to curl_off_t argument */ 408 | #define _curl_is_off_t_info(info) \ 409 | (CURLINFO_OFF_T < (info)) 410 | 411 | 412 | /* typecheck helpers -- check whether given expression has requested type*/ 413 | 414 | /* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros, 415 | * otherwise define a new macro. Search for __builtin_types_compatible_p 416 | * in the GCC manual. 417 | * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is 418 | * the actual expression passed to the curl_easy_setopt macro. This 419 | * means that you can only apply the sizeof and __typeof__ operators, no 420 | * == or whatsoever. 421 | */ 422 | 423 | /* XXX: should evaluate to true iff expr is a pointer */ 424 | #define _curl_is_any_ptr(expr) \ 425 | (sizeof(expr) == sizeof(void *)) 426 | 427 | /* evaluates to true if expr is NULL */ 428 | /* XXX: must not evaluate expr, so this check is not accurate */ 429 | #define _curl_is_NULL(expr) \ 430 | (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) 431 | 432 | /* evaluates to true if expr is type*, const type* or NULL */ 433 | #define _curl_is_ptr(expr, type) \ 434 | (_curl_is_NULL(expr) || \ 435 | __builtin_types_compatible_p(__typeof__(expr), type *) || \ 436 | __builtin_types_compatible_p(__typeof__(expr), const type *)) 437 | 438 | /* evaluates to true if expr is one of type[], type*, NULL or const type* */ 439 | #define _curl_is_arr(expr, type) \ 440 | (_curl_is_ptr((expr), type) || \ 441 | __builtin_types_compatible_p(__typeof__(expr), type [])) 442 | 443 | /* evaluates to true if expr is a string */ 444 | #define _curl_is_string(expr) \ 445 | (_curl_is_arr((expr), char) || \ 446 | _curl_is_arr((expr), signed char) || \ 447 | _curl_is_arr((expr), unsigned char)) 448 | 449 | /* evaluates to true if expr is a long (no matter the signedness) 450 | * XXX: for now, int is also accepted (and therefore short and char, which 451 | * are promoted to int when passed to a variadic function) */ 452 | #define _curl_is_long(expr) \ 453 | (__builtin_types_compatible_p(__typeof__(expr), long) || \ 454 | __builtin_types_compatible_p(__typeof__(expr), signed long) || \ 455 | __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ 456 | __builtin_types_compatible_p(__typeof__(expr), int) || \ 457 | __builtin_types_compatible_p(__typeof__(expr), signed int) || \ 458 | __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ 459 | __builtin_types_compatible_p(__typeof__(expr), short) || \ 460 | __builtin_types_compatible_p(__typeof__(expr), signed short) || \ 461 | __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ 462 | __builtin_types_compatible_p(__typeof__(expr), char) || \ 463 | __builtin_types_compatible_p(__typeof__(expr), signed char) || \ 464 | __builtin_types_compatible_p(__typeof__(expr), unsigned char)) 465 | 466 | /* evaluates to true if expr is of type curl_off_t */ 467 | #define _curl_is_off_t(expr) \ 468 | (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) 469 | 470 | /* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ 471 | /* XXX: also check size of an char[] array? */ 472 | #define _curl_is_error_buffer(expr) \ 473 | (_curl_is_NULL(expr) || \ 474 | __builtin_types_compatible_p(__typeof__(expr), char *) || \ 475 | __builtin_types_compatible_p(__typeof__(expr), char[])) 476 | 477 | /* evaluates to true if expr is of type (const) void* or (const) FILE* */ 478 | #if 0 479 | #define _curl_is_cb_data(expr) \ 480 | (_curl_is_ptr((expr), void) || \ 481 | _curl_is_ptr((expr), FILE)) 482 | #else /* be less strict */ 483 | #define _curl_is_cb_data(expr) \ 484 | _curl_is_any_ptr(expr) 485 | #endif 486 | 487 | /* evaluates to true if expr is of type FILE* */ 488 | #define _curl_is_FILE(expr) \ 489 | (_curl_is_NULL(expr) || \ 490 | (__builtin_types_compatible_p(__typeof__(expr), FILE *))) 491 | 492 | /* evaluates to true if expr can be passed as POST data (void* or char*) */ 493 | #define _curl_is_postfields(expr) \ 494 | (_curl_is_ptr((expr), void) || \ 495 | _curl_is_arr((expr), char)) 496 | 497 | /* FIXME: the whole callback checking is messy... 498 | * The idea is to tolerate char vs. void and const vs. not const 499 | * pointers in arguments at least 500 | */ 501 | /* helper: __builtin_types_compatible_p distinguishes between functions and 502 | * function pointers, hide it */ 503 | #define _curl_callback_compatible(func, type) \ 504 | (__builtin_types_compatible_p(__typeof__(func), type) || \ 505 | __builtin_types_compatible_p(__typeof__(func) *, type)) 506 | 507 | /* evaluates to true if expr is of type curl_read_callback or "similar" */ 508 | #define _curl_is_read_cb(expr) \ 509 | (_curl_is_NULL(expr) || \ 510 | _curl_callback_compatible((expr), __typeof__(fread) *) || \ 511 | _curl_callback_compatible((expr), curl_read_callback) || \ 512 | _curl_callback_compatible((expr), _curl_read_callback1) || \ 513 | _curl_callback_compatible((expr), _curl_read_callback2) || \ 514 | _curl_callback_compatible((expr), _curl_read_callback3) || \ 515 | _curl_callback_compatible((expr), _curl_read_callback4) || \ 516 | _curl_callback_compatible((expr), _curl_read_callback5) || \ 517 | _curl_callback_compatible((expr), _curl_read_callback6)) 518 | typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *); 519 | typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *); 520 | typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *); 521 | typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *); 522 | typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *); 523 | typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *); 524 | 525 | /* evaluates to true if expr is of type curl_write_callback or "similar" */ 526 | #define _curl_is_write_cb(expr) \ 527 | (_curl_is_read_cb(expr) || \ 528 | _curl_callback_compatible((expr), __typeof__(fwrite) *) || \ 529 | _curl_callback_compatible((expr), curl_write_callback) || \ 530 | _curl_callback_compatible((expr), _curl_write_callback1) || \ 531 | _curl_callback_compatible((expr), _curl_write_callback2) || \ 532 | _curl_callback_compatible((expr), _curl_write_callback3) || \ 533 | _curl_callback_compatible((expr), _curl_write_callback4) || \ 534 | _curl_callback_compatible((expr), _curl_write_callback5) || \ 535 | _curl_callback_compatible((expr), _curl_write_callback6)) 536 | typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *); 537 | typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t, 538 | const void *); 539 | typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *); 540 | typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *); 541 | typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t, 542 | const void *); 543 | typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *); 544 | 545 | /* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ 546 | #define _curl_is_ioctl_cb(expr) \ 547 | (_curl_is_NULL(expr) || \ 548 | _curl_callback_compatible((expr), curl_ioctl_callback) || \ 549 | _curl_callback_compatible((expr), _curl_ioctl_callback1) || \ 550 | _curl_callback_compatible((expr), _curl_ioctl_callback2) || \ 551 | _curl_callback_compatible((expr), _curl_ioctl_callback3) || \ 552 | _curl_callback_compatible((expr), _curl_ioctl_callback4)) 553 | typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *); 554 | typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *); 555 | typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *); 556 | typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *); 557 | 558 | /* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ 559 | #define _curl_is_sockopt_cb(expr) \ 560 | (_curl_is_NULL(expr) || \ 561 | _curl_callback_compatible((expr), curl_sockopt_callback) || \ 562 | _curl_callback_compatible((expr), _curl_sockopt_callback1) || \ 563 | _curl_callback_compatible((expr), _curl_sockopt_callback2)) 564 | typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); 565 | typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t, 566 | curlsocktype); 567 | 568 | /* evaluates to true if expr is of type curl_opensocket_callback or 569 | "similar" */ 570 | #define _curl_is_opensocket_cb(expr) \ 571 | (_curl_is_NULL(expr) || \ 572 | _curl_callback_compatible((expr), curl_opensocket_callback) || \ 573 | _curl_callback_compatible((expr), _curl_opensocket_callback1) || \ 574 | _curl_callback_compatible((expr), _curl_opensocket_callback2) || \ 575 | _curl_callback_compatible((expr), _curl_opensocket_callback3) || \ 576 | _curl_callback_compatible((expr), _curl_opensocket_callback4)) 577 | typedef curl_socket_t (*_curl_opensocket_callback1) 578 | (void *, curlsocktype, struct curl_sockaddr *); 579 | typedef curl_socket_t (*_curl_opensocket_callback2) 580 | (void *, curlsocktype, const struct curl_sockaddr *); 581 | typedef curl_socket_t (*_curl_opensocket_callback3) 582 | (const void *, curlsocktype, struct curl_sockaddr *); 583 | typedef curl_socket_t (*_curl_opensocket_callback4) 584 | (const void *, curlsocktype, const struct curl_sockaddr *); 585 | 586 | /* evaluates to true if expr is of type curl_progress_callback or "similar" */ 587 | #define _curl_is_progress_cb(expr) \ 588 | (_curl_is_NULL(expr) || \ 589 | _curl_callback_compatible((expr), curl_progress_callback) || \ 590 | _curl_callback_compatible((expr), _curl_progress_callback1) || \ 591 | _curl_callback_compatible((expr), _curl_progress_callback2)) 592 | typedef int (*_curl_progress_callback1)(void *, 593 | double, double, double, double); 594 | typedef int (*_curl_progress_callback2)(const void *, 595 | double, double, double, double); 596 | 597 | /* evaluates to true if expr is of type curl_debug_callback or "similar" */ 598 | #define _curl_is_debug_cb(expr) \ 599 | (_curl_is_NULL(expr) || \ 600 | _curl_callback_compatible((expr), curl_debug_callback) || \ 601 | _curl_callback_compatible((expr), _curl_debug_callback1) || \ 602 | _curl_callback_compatible((expr), _curl_debug_callback2) || \ 603 | _curl_callback_compatible((expr), _curl_debug_callback3) || \ 604 | _curl_callback_compatible((expr), _curl_debug_callback4) || \ 605 | _curl_callback_compatible((expr), _curl_debug_callback5) || \ 606 | _curl_callback_compatible((expr), _curl_debug_callback6) || \ 607 | _curl_callback_compatible((expr), _curl_debug_callback7) || \ 608 | _curl_callback_compatible((expr), _curl_debug_callback8)) 609 | typedef int (*_curl_debug_callback1) (CURL *, 610 | curl_infotype, char *, size_t, void *); 611 | typedef int (*_curl_debug_callback2) (CURL *, 612 | curl_infotype, char *, size_t, const void *); 613 | typedef int (*_curl_debug_callback3) (CURL *, 614 | curl_infotype, const char *, size_t, void *); 615 | typedef int (*_curl_debug_callback4) (CURL *, 616 | curl_infotype, const char *, size_t, const void *); 617 | typedef int (*_curl_debug_callback5) (CURL *, 618 | curl_infotype, unsigned char *, size_t, void *); 619 | typedef int (*_curl_debug_callback6) (CURL *, 620 | curl_infotype, unsigned char *, size_t, const void *); 621 | typedef int (*_curl_debug_callback7) (CURL *, 622 | curl_infotype, const unsigned char *, size_t, void *); 623 | typedef int (*_curl_debug_callback8) (CURL *, 624 | curl_infotype, const unsigned char *, size_t, const void *); 625 | 626 | /* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ 627 | /* this is getting even messier... */ 628 | #define _curl_is_ssl_ctx_cb(expr) \ 629 | (_curl_is_NULL(expr) || \ 630 | _curl_callback_compatible((expr), curl_ssl_ctx_callback) || \ 631 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \ 632 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \ 633 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \ 634 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \ 635 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \ 636 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \ 637 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \ 638 | _curl_callback_compatible((expr), _curl_ssl_ctx_callback8)) 639 | typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *); 640 | typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *); 641 | typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *); 642 | typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *, 643 | const void *); 644 | #ifdef HEADER_SSL_H 645 | /* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX 646 | * this will of course break if we're included before OpenSSL headers... 647 | */ 648 | typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *); 649 | typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *); 650 | typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *); 651 | typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, 652 | const void *); 653 | #else 654 | typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; 655 | typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; 656 | typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; 657 | typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; 658 | #endif 659 | 660 | /* evaluates to true if expr is of type curl_conv_callback or "similar" */ 661 | #define _curl_is_conv_cb(expr) \ 662 | (_curl_is_NULL(expr) || \ 663 | _curl_callback_compatible((expr), curl_conv_callback) || \ 664 | _curl_callback_compatible((expr), _curl_conv_callback1) || \ 665 | _curl_callback_compatible((expr), _curl_conv_callback2) || \ 666 | _curl_callback_compatible((expr), _curl_conv_callback3) || \ 667 | _curl_callback_compatible((expr), _curl_conv_callback4)) 668 | typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); 669 | typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); 670 | typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); 671 | typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); 672 | 673 | /* evaluates to true if expr is of type curl_seek_callback or "similar" */ 674 | #define _curl_is_seek_cb(expr) \ 675 | (_curl_is_NULL(expr) || \ 676 | _curl_callback_compatible((expr), curl_seek_callback) || \ 677 | _curl_callback_compatible((expr), _curl_seek_callback1) || \ 678 | _curl_callback_compatible((expr), _curl_seek_callback2)) 679 | typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); 680 | typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); 681 | 682 | 683 | #endif /* __CURL_TYPECHECK_GCC_H */ 684 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/lib/libcurl.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libcurl-7.56.0/lib/libcurl.a -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/lib/libcurl.la: -------------------------------------------------------------------------------- 1 | # libcurl.la - a libtool library file 2 | # Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-2 3 | # 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # The name that we can dlopen(3). 8 | dlname='libcurl.so.4' 9 | 10 | # Names of this library. 11 | library_names='libcurl.so.4.5.0 libcurl.so.4 libcurl.so' 12 | 13 | # The name of the static archive. 14 | old_library='libcurl.a' 15 | 16 | # Linker flags that cannot go in dependency_libs. 17 | inherited_linker_flags=' -pthread' 18 | 19 | # Libraries that this one depends upon. 20 | dependency_libs=' -lrtmp -lssl -lcrypto -lldap -lz -lrt' 21 | 22 | # Names of additional weak libraries provided by this library 23 | weak_library_names='' 24 | 25 | # Version information for libcurl. 26 | current=9 27 | age=5 28 | revision=0 29 | 30 | # Is this an already installed library? 31 | installed=yes 32 | 33 | # Should we warn about portability when linking against -modules? 34 | shouldnotlink=no 35 | 36 | # Files to dlopen/dlpreopen 37 | dlopen='' 38 | dlpreopen='' 39 | 40 | # Directory that this library needs to be installed in: 41 | libdir='/home/tensaix2j/Programming/libcurl/curl-7.56.0/bin/lib' 42 | -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/lib/libcurl.so: -------------------------------------------------------------------------------- 1 | libcurl.so.4.5.0 -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/lib/libcurl.so.4: -------------------------------------------------------------------------------- 1 | libcurl.so.4.5.0 -------------------------------------------------------------------------------- /lib/libcurl-7.56.0/lib/libcurl.so.4.5.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libcurl-7.56.0/lib/libcurl.so.4.5.0 -------------------------------------------------------------------------------- /lib/libwebsockets-2.4.0/include/lws-plugin-ssh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libwebsockets - lws-plugin-ssh-base 3 | * 4 | * Copyright (C) 2017 Andy Green 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation: 9 | * version 2.1 of the License. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 | * MA 02110-1301 USA 20 | */ 21 | 22 | #if !defined(__LWS_PLUGIN_SSH_H__) 23 | #define __LWS_PLUGIN_SSH_H__ 24 | 25 | #define LWS_CALLBACK_SSH_UART_SET_RXFLOW (LWS_CALLBACK_USER + 800) 26 | 27 | #define LWS_SSH_OPS_VERSION 1 28 | 29 | struct lws_ssh_pty { 30 | char term[16]; 31 | char *modes; 32 | uint32_t width_ch; 33 | uint32_t height_ch; 34 | uint32_t width_px; 35 | uint32_t height_px; 36 | uint32_t modes_len; 37 | }; 38 | 39 | #define SSHMO_TTY_OP_END 0 /* Indicates end of options. */ 40 | #define SSHMO_VINTR 1 /* Interrupt character; 255 if none. Similarly 41 | * for the other characters. Not all of these 42 | * characters are supported on all systems. */ 43 | #define SSHMO_VQUIT 2 /* The quit character (sends SIGQUIT signal on 44 | * POSIX systems). */ 45 | #define SSHMO_VERASE 3 /* Erase the character to left of the cursor. */ 46 | #define SSHMO_VKILL 4 /* Kill the current input line. */ 47 | #define SSHMO_VEOF 5 /* End-of-file character (sends EOF from the 48 | * terminal). */ 49 | #define SSHMO_VEOL 6 /* End-of-line character in addition to 50 | * carriage return and/or linefeed. */ 51 | #define SSHMO_VEOL2 7 /* Additional end-of-line character. */ 52 | #define SSHMO_VSTART 8 /* Continues paused output (normally 53 | * control-Q). */ 54 | #define SSHMO_VSTOP 9 /* Pauses output (normally control-S). */ 55 | #define SSHMO_VSUSP 10 /* Suspends the current program. */ 56 | #define SSHMO_VDSUSP 11 /* Another suspend character. */ 57 | #define SSHMO_VREPRINT 12 /* Reprints the current input line. */ 58 | #define SSHMO_VWERASE 13 /* Erases a word left of cursor. */ 59 | #define SSHMO_VLNEXT 14 /* Enter the next character typed literally, 60 | * even if it is a special character */ 61 | #define SSHMO_VFLUSH 15 /* Character to flush output. */ 62 | #define SSHMO_VSWTCH 16 /* Switch to a different shell layer. */ 63 | #define SSHMO_VSTATUS 17 /* Prints system status line (load, command, 64 | * pid, etc). */ 65 | #define SSHMO_VDISCARD 18 /* Toggles the flushing of terminal output. */ 66 | #define SSHMO_IGNPAR 30 /* The ignore parity flag. The parameter 67 | * SHOULD be 0 if this flag is FALSE, 68 | * and 1 if it is TRUE. */ 69 | #define SSHMO_PARMRK 31 /* Mark parity and framing errors. */ 70 | #define SSHMO_INPCK 32 /* Enable checking of parity errors. */ 71 | #define SSHMO_ISTRIP 33 /* Strip 8th bit off characters. */ 72 | #define SSHMO_INLCR 34 /* Map NL into CR on input. */ 73 | #define SSHMO_IGNCR 35 /* Ignore CR on input. */ 74 | #define SSHMO_ICRNL 36 /* Map CR to NL on input. */ 75 | #define SSHMO_IUCLC 37 /* Translate uppercase characters to lowercase. */ 76 | #define SSHMO_IXON 38 /* Enable output flow control. */ 77 | #define SSHMO_IXANY 39 /* Any char will restart after stop. */ 78 | #define SSHMO_IXOFF 40 /* Enable input flow control. */ 79 | #define SSHMO_IMAXBEL 41 /* Ring bell on input queue full. */ 80 | #define SSHMO_ISIG 50 /* Enable signals INTR, QUIT, [D]SUSP. */ 81 | #define SSHMO_ICANON 51 /* Canonicalize input lines. */ 82 | #define SSHMO_XCASE 52 /* Enable input and output of uppercase 83 | * characters by preceding their lowercase 84 | * equivalents with "\". */ 85 | #define SSHMO_ECHO 53 /* Enable echoing. */ 86 | #define SSHMO_ECHOE 54 /* Visually erase chars. */ 87 | #define SSHMO_ECHOK 55 /* Kill character discards current line. */ 88 | #define SSHMO_ECHONL 56 /* Echo NL even if ECHO is off. */ 89 | #define SSHMO_NOFLSH 57 /* Don't flush after interrupt. */ 90 | #define SSHMO_TOSTOP 58 /* Stop background jobs from output. */ 91 | #define SSHMO_IEXTEN 59 /* Enable extensions. */ 92 | #define SSHMO_ECHOCTL 60 /* Echo control characters as ^(Char). */ 93 | #define SSHMO_ECHOKE 61 /* Visual erase for line kill. */ 94 | #define SSHMO_PENDIN 62 /* Retype pending input. */ 95 | #define SSHMO_OPOST 70 /* Enable output processing. */ 96 | #define SSHMO_OLCUC 71 /* Convert lowercase to uppercase. */ 97 | #define SSHMO_ONLCR 72 /* Map NL to CR-NL. */ 98 | #define SSHMO_OCRNL 73 /* Translate carriage return to newline (out). */ 99 | #define SSHMO_ONOCR 74 /* Translate newline to CR-newline (out). */ 100 | #define SSHMO_ONLRET 75 /* Newline performs a carriage return (out). */ 101 | #define SSHMO_CS7 90 /* 7 bit mode. */ 102 | #define SSHMO_CS8 91 /* 8 bit mode. */ 103 | #define SSHMO_PARENB 92 /* Parity enable. */ 104 | #define SSHMO_PARODD 93 /* Odd parity, else even. */ 105 | #define SSHMO_TTY_OP_ISPEED 128 /* Specifies the input baud rate in 106 | * bits per second. */ 107 | #define SSHMO_TTY_OP_OSPEED 129 /* Specifies the output baud rate in 108 | * bits per second. */ 109 | 110 | /*! \defgroup ssh-base plugin: lws-ssh-base 111 | * \ingroup Protocols-and-Plugins 112 | * 113 | * ##Plugin lws-ssh-base 114 | * 115 | * This is the interface to customize the ssh server per-vhost. A pointer 116 | * to your struct lws_ssh_ops with the members initialized is passed in using 117 | * pvo when you create the vhost. The pvo is attached to the protocol name 118 | * 119 | * - "lws-ssh-base" - the ssh serving part 120 | * 121 | * - "lws-telnetd-base" - the telnet serving part 122 | * 123 | * This way you can have different instances of ssh servers wired up to 124 | * different IO and server keys per-vhost. 125 | * 126 | * See also ./READMEs/README-plugin-sshd-base.md 127 | */ 128 | ///@{ 129 | 130 | struct lws_ssh_ops { 131 | /** 132 | * channel_create() - Channel created 133 | * 134 | * \param wsi: raw wsi representing this connection 135 | * \param priv: pointer to void * you can allocate and attach to the 136 | * channel 137 | * 138 | * Called when new channel created, *priv should be set to any 139 | * allocation your implementation needs 140 | * 141 | * You probably want to save the wsi inside your priv struct. Calling 142 | * lws_callback_on_writable() on this wsi causes your ssh server 143 | * instance to call .tx_waiting() next time you can write something 144 | * to the client. 145 | */ 146 | int (*channel_create)(struct lws *wsi, void **priv); 147 | 148 | /** 149 | * channel_destroy() - Channel is being destroyed 150 | * 151 | * \param priv: void * you set when channel was created (or NULL) 152 | * 153 | * Called when channel destroyed, priv should be freed if you allocated 154 | * into it. 155 | */ 156 | int (*channel_destroy)(void *priv); 157 | 158 | /** 159 | * rx() - receive payload from peer 160 | * 161 | * \param priv: void * you set when this channel was created 162 | * \param wsi: struct lws * for the ssh connection 163 | * \param buf: pointer to start of received data 164 | * \param len: bytes of received data available at buf 165 | * 166 | * len bytes of payload from the peer arrived and is available at buf 167 | */ 168 | int (*rx)(void *priv, struct lws *wsi, const uint8_t *buf, uint32_t len); 169 | 170 | /** 171 | * tx_waiting() - report if data waiting to transmit on the channel 172 | * 173 | * \param priv: void * you set when this channel was created 174 | * 175 | * returns a bitmask of LWS_STDOUT and LWS_STDERR, with the bits set 176 | * if they have tx waiting to send, else 0 if nothing to send 177 | * 178 | * You should use one of the lws_callback_on_writable() family to 179 | * trigger the ssh protocol to ask if you have any tx waiting. 180 | * 181 | * Returning -1 from here will close the tcp connection to the client. 182 | */ 183 | int (*tx_waiting)(void *priv); 184 | 185 | /** 186 | * tx() - provide data to send on the channel 187 | * 188 | * \param priv: void * you set when this channel was created 189 | * \param stdch: LWS_STDOUT or LWS_STDERR 190 | * \param buf: start of the buffer to copy the transmit data into 191 | * \param len: max length of the buffer in bytes 192 | * 193 | * copy and consume up to len bytes into *buf, 194 | * return the actual copied count. 195 | * 196 | * You should use one of the lws_callback_on_writable() family to 197 | * trigger the ssh protocol to ask if you have any tx waiting. If you 198 | * do you will get calls here to fetch it, for each of LWS_STDOUT or 199 | * LWS_STDERR that were reported to be waiting by tx_waiting(). 200 | */ 201 | size_t (*tx)(void *priv, int stdch, uint8_t *buf, size_t len); 202 | 203 | /** 204 | * get_server_key() - retreive the secret keypair for this server 205 | * 206 | * \param wsi: the wsi representing the connection to the client 207 | * \param buf: start of the buffer to copy the keypair into 208 | * \param len: length of the buffer in bytes 209 | * 210 | * load the server key into buf, max len len. Returns length of buf 211 | * set to key, or 0 if no key or other error. If there is no key, 212 | * the error isn't fatal... the plugin will generate a random key and 213 | * store it using *get_server_key() for subsequent times. 214 | */ 215 | size_t (*get_server_key)(struct lws *wsi, uint8_t *buf, size_t len); 216 | 217 | /** 218 | * set_server_key() - store the secret keypair of this server 219 | * 220 | * \param wsi: the wsi representing the connection to the client 221 | * \param buf: start of the buffer containing the keypair 222 | * \param len: length of the keypair in bytes 223 | * 224 | * store the server key in buf, length len, to nonvolatile stg. 225 | * Return length stored, 0 for fail. 226 | */ 227 | size_t (*set_server_key)(struct lws *wsi, uint8_t *buf, size_t len); 228 | 229 | /** 230 | * set_env() - Set environment variable 231 | * 232 | * \param priv: void * you set when this channel was created 233 | * \param name: env var name 234 | * \param value: value to set env var to 235 | * 236 | * Client requested to set environment var. Return nonzero to fail. 237 | */ 238 | int (*set_env)(void *priv, const char *name, const char *value); 239 | 240 | /** 241 | * exec() - spawn command and wire up stdin/out/err to ssh channel 242 | * 243 | * \param priv: void * you set when this channel was created 244 | * \param wsi: the struct lws the connection belongs to 245 | * \param command: string containing path to app and arguments 246 | * 247 | * Client requested to exec something. Return nonzero to fail. 248 | */ 249 | int (*exec)(void *priv, struct lws *wsi, const char *command); 250 | 251 | /** 252 | * shell() - Spawn shell that is appropriate for user 253 | * 254 | * \param priv: void * you set when this channel was created 255 | * \param wsi: the struct lws the connection belongs to 256 | * 257 | * Spawn the appropriate shell for this user. Return 0 for OK 258 | * or nonzero to fail. 259 | */ 260 | int (*shell)(void *priv, struct lws *wsi); 261 | 262 | /** 263 | * pty_req() - Create a Pseudo-TTY as described in pty 264 | * 265 | * \param priv: void * you set when this channel was created 266 | * \param pty: pointer to struct describing the desired pty 267 | * 268 | * Client requested a pty. Return nonzero to fail. 269 | */ 270 | int (*pty_req)(void *priv, struct lws_ssh_pty *pty); 271 | 272 | /** 273 | * child_process_io() - Child process has IO 274 | * 275 | * \param priv: void * you set when this channel was created 276 | * \param wsi: the struct lws the connection belongs to 277 | * \param args: information related to the cgi IO events 278 | * 279 | * Child process has IO 280 | */ 281 | int (*child_process_io)(void *priv, struct lws *wsi, 282 | struct lws_cgi_args *args); 283 | 284 | /** 285 | * child_process_io() - Child process has terminated 286 | * 287 | * \param priv: void * you set when this channel was created 288 | * \param wsi: the struct lws the connection belongs to 289 | * 290 | * Child process has terminated 291 | */ 292 | int (*child_process_terminated)(void *priv, struct lws *wsi); 293 | 294 | /** 295 | * disconnect_reason() - Optional notification why connection is lost 296 | * 297 | * \param reason: one of the SSH_DISCONNECT_ constants 298 | * \param desc: UTF-8 description of reason 299 | * \param desc_lang: RFC3066 language for description 300 | * 301 | * The remote peer may tell us why it's going to disconnect. Handling 302 | * this is optional. 303 | */ 304 | void (*disconnect_reason)(uint32_t reason, const char *desc, 305 | const char *desc_lang); 306 | 307 | /** 308 | * is_pubkey_authorized() - check if auth pubkey is valid for user 309 | * 310 | * \param username: username the key attempted to authenticate 311 | * \param type: "ssh-rsa" 312 | * \param peer: start of Public key peer used to authenticate 313 | * \param peer_len: length of Public key at peer 314 | * 315 | * We confirmed the client has the private key for this public key... 316 | * but is that keypair something authorized for this username on this 317 | * server? 0 = OK, 1 = fail 318 | * 319 | * Normally this checks for a copy of the same public key stored 320 | * somewhere out of band, it's the same procedure as openssh does 321 | * when looking in ~/.ssh/authorized_keys 322 | */ 323 | int (*is_pubkey_authorized)(const char *username, 324 | const char *type, const uint8_t *peer, int peer_len); 325 | 326 | /** 327 | * banner() - copy the connection banner to buffer 328 | * 329 | * \param buf: start of the buffer to copy to 330 | * \param max_len: maximum number of bytes the buffer can hold 331 | * \param lang: start of the buffer to copy language descriptor to 332 | * \param max_lang_len: maximum number of bytes lang can hold 333 | * 334 | * Copy the text banner to be returned to client on connect, 335 | * before auth, into buf. The text should be in UTF-8. 336 | * if none wanted then leave .banner as NULL. 337 | * 338 | * lang should have a RFC3066 language descriptor like "en/US" 339 | * copied to it. 340 | * 341 | * Returns the number of bytes copies to buf. 342 | */ 343 | size_t (*banner)(char *buf, size_t max_len, char *lang, 344 | size_t max_lang_len); 345 | 346 | /** 347 | * SSH version string sent to client (required) 348 | * By convention a string like "SSH-2.0-Libwebsockets" 349 | */ 350 | const char *server_string; 351 | 352 | /** 353 | * set to the API version you support (current is in 354 | * LWS_SSH_OPS_VERSION) You should set it to an integer like 1, 355 | * that reflects the latest api at the time your code was written. If 356 | * the ops api_version is not equal to the LWS_SSH_OPS_VERSION of the 357 | * plugin, it will error out at runtime. 358 | */ 359 | char api_version; 360 | }; 361 | ///@} 362 | 363 | #endif 364 | 365 | -------------------------------------------------------------------------------- /lib/libwebsockets-2.4.0/include/lws_config.h: -------------------------------------------------------------------------------- 1 | /* lws_config.h Generated from lws_config.h.in */ 2 | 3 | #ifndef NDEBUG 4 | #ifndef _DEBUG 5 | #define _DEBUG 6 | #endif 7 | #endif 8 | 9 | #define LWS_INSTALL_DATADIR "/export/home/invantest/programming/libwebsockets/libwebsockets-2.4.0/bin/share" 10 | 11 | /* Define to 1 to use wolfSSL/CyaSSL as a replacement for OpenSSL. 12 | * LWS_OPENSSL_SUPPORT needs to be set also for this to work. */ 13 | /* #undef USE_WOLFSSL */ 14 | 15 | /* Also define to 1 (in addition to USE_WOLFSSL) when using the 16 | (older) CyaSSL library */ 17 | /* #undef USE_OLD_CYASSL */ 18 | /* #undef LWS_WITH_BORINGSSL */ 19 | 20 | /* #undef LWS_WITH_MBEDTLS */ 21 | /* #undef LWS_WITH_POLARSSL */ 22 | /* #undef LWS_WITH_ESP8266 */ 23 | /* #undef LWS_WITH_ESP32 */ 24 | 25 | /* #undef LWS_WITH_PLUGINS */ 26 | /* #undef LWS_WITH_NO_LOGS */ 27 | 28 | /* The Libwebsocket version */ 29 | #define LWS_LIBRARY_VERSION "2.4.0" 30 | 31 | #define LWS_LIBRARY_VERSION_MAJOR 2 32 | #define LWS_LIBRARY_VERSION_MINOR 4 33 | #define LWS_LIBRARY_VERSION_PATCH 0 34 | /* LWS_LIBRARY_VERSION_NUMBER looks like 1005001 for e.g. version 1.5.1 */ 35 | #define LWS_LIBRARY_VERSION_NUMBER (LWS_LIBRARY_VERSION_MAJOR*1000000)+(LWS_LIBRARY_VERSION_MINOR*1000)+LWS_LIBRARY_VERSION_PATCH 36 | 37 | /* The current git commit hash that we're building from */ 38 | #define LWS_BUILD_HASH "scadmin@jjubuntu64-v2.0.0-586-gd002162" 39 | 40 | /* Build with OpenSSL support */ 41 | #define LWS_OPENSSL_SUPPORT 42 | 43 | /* The client should load and trust CA root certs it finds in the OS */ 44 | #define LWS_SSL_CLIENT_USE_OS_CA_CERTS 45 | 46 | /* Sets the path where the client certs should be installed. */ 47 | #define LWS_OPENSSL_CLIENT_CERTS "../share" 48 | 49 | /* Turn off websocket extensions */ 50 | /* #undef LWS_NO_EXTENSIONS */ 51 | 52 | /* Enable libev io loop */ 53 | /* #undef LWS_WITH_LIBEV */ 54 | 55 | /* Enable libuv io loop */ 56 | /* #undef LWS_WITH_LIBUV */ 57 | 58 | /* Enable libevent io loop */ 59 | /* #undef LWS_WITH_LIBEVENT */ 60 | 61 | /* Build with support for ipv6 */ 62 | /* #undef LWS_WITH_IPV6 */ 63 | 64 | /* Build with support for UNIX domain socket */ 65 | /* #undef LWS_WITH_UNIX_SOCK */ 66 | 67 | /* Build with support for HTTP2 */ 68 | /* #undef LWS_WITH_HTTP2 */ 69 | 70 | /* Turn on latency measuring code */ 71 | /* #undef LWS_LATENCY */ 72 | 73 | /* Don't build the daemonizeation api */ 74 | #define LWS_NO_DAEMONIZE 75 | 76 | /* Build without server support */ 77 | /* #undef LWS_NO_SERVER */ 78 | 79 | /* Build without client support */ 80 | /* #undef LWS_NO_CLIENT */ 81 | 82 | /* If we should compile with MinGW support */ 83 | /* #undef LWS_MINGW_SUPPORT */ 84 | 85 | /* Use the BSD getifaddrs that comes with libwebsocket, for uclibc support */ 86 | /* #undef LWS_BUILTIN_GETIFADDRS */ 87 | 88 | /* use SHA1() not internal libwebsockets_SHA1 */ 89 | /* #undef LWS_SHA1_USE_OPENSSL_NAME */ 90 | 91 | /* SSL server using ECDH certificate */ 92 | /* #undef LWS_SSL_SERVER_WITH_ECDH_CERT */ 93 | #define LWS_HAVE_SSL_CTX_set1_param 94 | /* #undef LWS_HAVE_X509_VERIFY_PARAM_set1_host */ 95 | /* #undef LWS_HAVE_RSA_SET0_KEY */ 96 | 97 | /* #undef LWS_HAVE_UV_VERSION_H */ 98 | 99 | /* CGI apis */ 100 | /* #undef LWS_WITH_CGI */ 101 | 102 | /* whether the Openssl is recent enough, and / or built with, ecdh */ 103 | #define LWS_HAVE_OPENSSL_ECDH_H 104 | 105 | /* HTTP Proxy support */ 106 | /* #undef LWS_WITH_HTTP_PROXY */ 107 | 108 | /* HTTP Ranges support */ 109 | #define LWS_WITH_RANGES 110 | 111 | /* Http access log support */ 112 | /* #undef LWS_WITH_ACCESS_LOG */ 113 | /* #undef LWS_WITH_SERVER_STATUS */ 114 | 115 | /* #undef LWS_WITH_STATEFUL_URLDECODE */ 116 | /* #undef LWS_WITH_PEER_LIMITS */ 117 | 118 | /* Maximum supported service threads */ 119 | #define LWS_MAX_SMP 1 120 | 121 | /* Lightweight JSON Parser */ 122 | /* #undef LWS_WITH_LEJP */ 123 | 124 | /* SMTP */ 125 | /* #undef LWS_WITH_SMTP */ 126 | 127 | /* OPTEE */ 128 | /* #undef LWS_PLAT_OPTEE */ 129 | 130 | /* ZIP FOPS */ 131 | #define LWS_WITH_ZIP_FOPS 132 | #define LWS_HAVE_STDINT_H 133 | 134 | /* #undef LWS_AVOID_SIGPIPE_IGN */ 135 | 136 | /* #undef LWS_FALLBACK_GETHOSTBYNAME */ 137 | 138 | /* #undef LWS_WITH_STATS */ 139 | /* #undef LWS_WITH_SOCKS5 */ 140 | 141 | /* #undef LWS_HAVE_SYS_CAPABILITY_H */ 142 | /* #undef LWS_HAVE_LIBCAP */ 143 | 144 | #define LWS_HAVE_ATOLL 145 | /* #undef LWS_HAVE__ATOI64 */ 146 | /* #undef LWS_HAVE__STAT32I64 */ 147 | 148 | /* OpenSSL various APIs */ 149 | 150 | /* #undef LWS_HAVE_TLS_CLIENT_METHOD */ 151 | #define LWS_HAVE_TLSV1_2_CLIENT_METHOD 152 | #define LWS_HAVE_SSL_SET_INFO_CALLBACK 153 | 154 | #define LWS_HAS_INTPTR_T 155 | 156 | 157 | -------------------------------------------------------------------------------- /lib/libwebsockets-2.4.0/lib/libwebsockets.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libwebsockets-2.4.0/lib/libwebsockets.a -------------------------------------------------------------------------------- /lib/libwebsockets-2.4.0/lib/libwebsockets.so: -------------------------------------------------------------------------------- 1 | libwebsockets.so.11 -------------------------------------------------------------------------------- /lib/libwebsockets-2.4.0/lib/libwebsockets.so.11: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tensaix2j/binacpp/0e47f73870be92f7b564c6c3eebaa560b3a48ff5/lib/libwebsockets-2.4.0/lib/libwebsockets.so.11 -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | libcurl_dir=../lib/libcurl-7.56.0 4 | libcurl_include=${libcurl_dir}/include 5 | libcurl_lib=${libcurl_dir}/lib 6 | 7 | jsoncpp_dir=../lib/jsoncpp-1.8.3 8 | jsoncpp_include=${jsoncpp_dir}/include 9 | jsoncpp_src=${jsoncpp_dir}/src 10 | 11 | 12 | libwebsockets_dir=../lib/libwebsockets-2.4.0 13 | libwebsockets_include=${libwebsockets_dir}/include 14 | libwebsockets_lib=${libwebsockets_dir}/lib 15 | 16 | 17 | build_dir=../lib/libbinacpp/lib 18 | objects=$(build_dir)/jsoncpp.o $(build_dir)/binacpp_utils.o $(build_dir)/binacpp_logger.o $(build_dir)/binacpp.o $(build_dir)/binacpp_websocket.o 19 | 20 | build_include=../lib/libbinacpp/include 21 | 22 | 23 | $(build_dir)/libbinacpp.so: $(objects) 24 | g++ -I$(libcurl_include) -I$(jsoncpp_include) -I$(libwebsockets_include) \ 25 | -L$(libcurl_lib) \ 26 | -L$(libwebsockets_lib) \ 27 | $(objects) \ 28 | -shared \ 29 | -lcurl -lcrypto -lwebsockets -fPIC -o $@ 30 | 31 | # Make a new copy of the header too 32 | cp *.h $(build_include) 33 | 34 | 35 | 36 | 37 | $(build_dir)/binacpp.o: binacpp.cpp binacpp.h 38 | g++ -I$(libcurl_include) -I$(jsoncpp_include) -c binacpp.cpp -fPIC -o $(build_dir)/binacpp.o 39 | 40 | 41 | $(build_dir)/binacpp_websocket.o: binacpp_websocket.cpp binacpp_websocket.h 42 | g++ -I$(libwebsockets_include) -I$(jsoncpp_include) -c binacpp_websocket.cpp -fPIC -o $(build_dir)/binacpp_websocket.o 43 | 44 | 45 | $(build_dir)/binacpp_logger.o: binacpp_logger.cpp binacpp_logger.h 46 | g++ -c binacpp_logger.cpp -fPIC -o $(build_dir)/binacpp_logger.o 47 | 48 | 49 | 50 | $(build_dir)/binacpp_utils.o: binacpp_utils.cpp binacpp_utils.h 51 | g++ -c binacpp_utils.cpp -fPIC -o $(build_dir)/binacpp_utils.o 52 | 53 | 54 | $(build_dir)/jsoncpp.o: $(jsoncpp_src)/jsoncpp.cpp 55 | g++ -I$(jsoncpp_include) -c $(jsoncpp_src)/jsoncpp.cpp -fPIC -o $(build_dir)/jsoncpp.o 56 | 57 | clean: 58 | rm $(build_dir)/*.o 59 | rm $(build_dir)/*.so 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/binacpp.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Author: tensaix2j 4 | Date : 2017/10/15 5 | 6 | C++ library for Binance API. 7 | */ 8 | 9 | 10 | #ifndef BINACPP_H 11 | #define BINACPP_H 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | 30 | 31 | #define BINANCE_HOST "https://api.binance.com" 32 | 33 | 34 | using namespace std; 35 | 36 | class BinaCPP { 37 | 38 | static string api_key; 39 | static string secret_key; 40 | static CURL* curl; 41 | 42 | 43 | 44 | public: 45 | 46 | 47 | 48 | static void curl_api( string &url, string &result_json ); 49 | static void curl_api_with_header( string &url, string &result_json , vector &extra_http_header, string &post_data, string &action ); 50 | static size_t curl_cb( void *content, size_t size, size_t nmemb, string *buffer ) ; 51 | 52 | static void init( string &api_key, string &secret_key); 53 | static void cleanup(); 54 | 55 | 56 | // Public API 57 | static void get_serverTime( Json::Value &json_result); 58 | 59 | static void get_allPrices( Json::Value &json_result ); 60 | static double get_price( const char *symbol ); 61 | 62 | static void get_allBookTickers( Json::Value &json_result ); 63 | static void get_bookTicker( const char *symbol, Json::Value &json_result ) ; 64 | 65 | static void get_depth( const char *symbol, int limit, Json::Value &json_result ); 66 | static void get_aggTrades( const char *symbol, int fromId, time_t startTime, time_t endTime, int limit, Json::Value &json_result ); 67 | static void get_24hr( const char *symbol, Json::Value &json_result ); 68 | static void get_klines( const char *symbol, const char *interval, int limit, time_t startTime, time_t endTime, Json::Value &json_result ); 69 | 70 | 71 | // API + Secret keys required 72 | static void get_account( long recvWindow , Json::Value &json_result ); 73 | 74 | static void get_myTrades( 75 | const char *symbol, 76 | int limit, 77 | long fromId, 78 | long recvWindow, 79 | Json::Value &json_result 80 | ); 81 | 82 | static void get_openOrders( 83 | const char *symbol, 84 | long recvWindow, 85 | Json::Value &json_result 86 | ) ; 87 | 88 | 89 | static void get_allOrders( 90 | const char *symbol, 91 | long orderId, 92 | int limit, 93 | long recvWindow, 94 | Json::Value &json_result 95 | ); 96 | 97 | 98 | static void send_order( 99 | const char *symbol, 100 | const char *side, 101 | const char *type, 102 | const char *timeInForce, 103 | double quantity, 104 | double price, 105 | const char *newClientOrderId, 106 | double stopPrice, 107 | double icebergQty, 108 | long recvWindow, 109 | Json::Value &json_result ) ; 110 | 111 | 112 | static void get_order( 113 | const char *symbol, 114 | long orderId, 115 | const char *origClientOrderId, 116 | long recvWindow, 117 | Json::Value &json_result ); 118 | 119 | 120 | static void cancel_order( 121 | const char *symbol, 122 | long orderId, 123 | const char *origClientOrderId, 124 | const char *newClientOrderId, 125 | long recvWindow, 126 | Json::Value &json_result 127 | ); 128 | 129 | // API key required 130 | static void start_userDataStream( Json::Value &json_result ); 131 | static void keep_userDataStream( const char *listenKey ); 132 | static void close_userDataStream( const char *listenKey ); 133 | 134 | 135 | // WAPI 136 | static void withdraw( 137 | const char *asset, 138 | const char *address, 139 | const char *addressTag, 140 | double amount, 141 | const char *name, 142 | long recvWindow, 143 | Json::Value &json_result ); 144 | 145 | static void get_depositHistory( 146 | const char *asset, 147 | int status, 148 | long startTime, 149 | long endTime, 150 | long recvWindow, 151 | Json::Value &json_result ); 152 | 153 | static void get_withdrawHistory( 154 | const char *asset, 155 | int status, 156 | long startTime, 157 | long endTime, 158 | long recvWindow, 159 | Json::Value &json_result ); 160 | 161 | static void get_depositAddress( 162 | const char *asset, 163 | long recvWindow, 164 | Json::Value &json_result ); 165 | 166 | 167 | }; 168 | 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /src/binacpp_logger.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "binacpp_logger.h" 3 | 4 | int BinaCPP_logger::debug_level = 1; 5 | string BinaCPP_logger::debug_log_file = "/tmp/binawatch.log"; 6 | int BinaCPP_logger::debug_log_file_enable = 0; 7 | FILE *BinaCPP_logger::log_fp = NULL; 8 | 9 | 10 | 11 | //----------------------------------------------- 12 | void 13 | BinaCPP_logger::write_log( const char *fmt, ... ) 14 | { 15 | if ( debug_level == 0 ) { 16 | return; 17 | } 18 | if ( debug_log_file_enable == 1 ) { 19 | open_logfp_if_not_opened(); 20 | } 21 | 22 | va_list arg; 23 | 24 | char new_fmt[1024]; 25 | 26 | struct timeval tv; 27 | gettimeofday(&tv, NULL); 28 | time_t t = tv.tv_sec; 29 | struct tm * now = localtime( &t ); 30 | 31 | 32 | sprintf( new_fmt , "%04d-%02d-%02d %02d:%02d:%02d %06ld :%s\n" , now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec , tv.tv_usec , fmt ); 33 | 34 | va_start (arg, fmt); 35 | 36 | if ( debug_log_file_enable && log_fp ) { 37 | vfprintf( log_fp , new_fmt ,arg ); 38 | fflush(log_fp); 39 | } else { 40 | vfprintf ( stdout, new_fmt, arg); 41 | fflush(stdout); 42 | } 43 | 44 | va_end (arg); 45 | 46 | 47 | } 48 | 49 | 50 | 51 | //----------------------------------------------- 52 | // Write log to channel without any timestamp nor new line 53 | void 54 | BinaCPP_logger::write_log_clean( const char *fmt, ... ) 55 | { 56 | if ( debug_level == 0 ) { 57 | return; 58 | } 59 | if ( debug_log_file_enable == 1 ) { 60 | open_logfp_if_not_opened(); 61 | } 62 | 63 | va_list arg; 64 | va_start (arg, fmt); 65 | 66 | if ( debug_log_file_enable && log_fp ) { 67 | vfprintf( log_fp , fmt ,arg ); 68 | fflush(log_fp); 69 | } else { 70 | vfprintf ( stdout, fmt, arg); 71 | fflush(stdout); 72 | } 73 | va_end (arg); 74 | 75 | } 76 | 77 | 78 | //--------------------- 79 | void 80 | BinaCPP_logger::open_logfp_if_not_opened() { 81 | 82 | if ( debug_log_file_enable && log_fp == NULL ) { 83 | 84 | log_fp = fopen( debug_log_file.c_str() , "a" ); 85 | 86 | if ( log_fp ) { 87 | printf("log file in %s\n", debug_log_file.c_str()); 88 | } else { 89 | printf("Failed to open log file.\n" ); 90 | } 91 | } 92 | 93 | } 94 | 95 | 96 | //--------------------- 97 | void 98 | BinaCPP_logger::set_debug_level( int level ) 99 | { 100 | debug_level = level; 101 | } 102 | 103 | //-------------------- 104 | void 105 | BinaCPP_logger::set_debug_logfile( string &pDebug_log_file ) 106 | { 107 | debug_log_file = pDebug_log_file; 108 | } 109 | 110 | //-------------------- 111 | void 112 | BinaCPP_logger::enable_logfile( int pDebug_log_file_enable ) 113 | { 114 | debug_log_file_enable = pDebug_log_file_enable; 115 | } 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /src/binacpp_logger.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | 23 | class BinaCPP_logger { 24 | 25 | static int debug_level ; 26 | static string debug_log_file; 27 | static int debug_log_file_enable ; 28 | static FILE *log_fp; 29 | 30 | 31 | static void open_logfp_if_not_opened(); 32 | 33 | public: 34 | static void write_log( const char *fmt, ... ); 35 | static void write_log_clean( const char *fmt, ... ); 36 | static void set_debug_level( int level ); 37 | static void set_debug_logfile( string &pDebug_log_file ) ; 38 | static void enable_logfile( int pDebug_log_file_enable ); 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /src/binacpp_utils.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "binacpp_utils.h" 3 | 4 | //-------------------------------- 5 | void split_string( string &s, char delim, vector &result) { 6 | 7 | std::stringstream ss; 8 | ss.str(s); 9 | std::string item; 10 | while (std::getline(ss, item, delim)) { 11 | result.push_back(item); 12 | } 13 | 14 | } 15 | 16 | 17 | 18 | //-------------------------------- 19 | int replace_string_once( string& str, const char *from, const char *to, int offset) { 20 | 21 | size_t start_pos = str.find(from, offset); 22 | if( start_pos == std::string::npos ) { 23 | return 0; 24 | } 25 | str.replace(start_pos, strlen(from), to); 26 | return start_pos + strlen(to); 27 | } 28 | 29 | 30 | //-------------------------------- 31 | bool replace_string( string& str, const char *from, const char *to) { 32 | 33 | bool found = false; 34 | size_t start_pos = 0; 35 | while((start_pos = str.find(from, start_pos)) != std::string::npos) { 36 | str.replace(start_pos, strlen( from ), to); 37 | found = true; 38 | start_pos += strlen(to); 39 | } 40 | return found; 41 | } 42 | 43 | 44 | //----------------------- 45 | void string_toupper( string &src) { 46 | for ( int i = 0 ; i < src.size() ; i++ ) { 47 | src[i] = toupper(src[i]); 48 | } 49 | } 50 | 51 | //------------------ 52 | string string_toupper( const char *cstr ) { 53 | string ret; 54 | for ( int i = 0 ; i < strlen( cstr ) ; i++ ) { 55 | ret.push_back( toupper(cstr[i]) ); 56 | } 57 | return ret; 58 | } 59 | 60 | 61 | //-------------------------------------- 62 | string b2a_hex( char *byte_arr, int n ) { 63 | 64 | const static std::string HexCodes = "0123456789abcdef"; 65 | string HexString; 66 | for ( int i = 0; i < n ; ++i ) { 67 | unsigned char BinValue = byte_arr[i]; 68 | HexString += HexCodes[( BinValue >> 4 ) & 0x0F]; 69 | HexString += HexCodes[BinValue & 0x0F]; 70 | } 71 | return HexString; 72 | } 73 | 74 | 75 | 76 | //--------------------------------- 77 | time_t get_current_epoch( ) { 78 | 79 | struct timeval tv; 80 | gettimeofday(&tv, NULL); 81 | 82 | return tv.tv_sec ; 83 | } 84 | 85 | //--------------------------------- 86 | unsigned long get_current_ms_epoch( ) { 87 | 88 | struct timeval tv; 89 | gettimeofday(&tv, NULL); 90 | 91 | return tv.tv_sec * 1000 + tv.tv_usec / 1000 ; 92 | 93 | } 94 | 95 | //--------------------------- 96 | string hmac_sha256( const char *key, const char *data) { 97 | 98 | unsigned char* digest; 99 | digest = HMAC(EVP_sha256(), key, strlen(key), (unsigned char*)data, strlen(data), NULL, NULL); 100 | return b2a_hex( (char *)digest, 32 ); 101 | } 102 | 103 | //------------------------------ 104 | string sha256( const char *data ) { 105 | 106 | unsigned char digest[32]; 107 | SHA256_CTX sha256; 108 | SHA256_Init(&sha256); 109 | SHA256_Update(&sha256, data, strlen(data) ); 110 | SHA256_Final(digest, &sha256); 111 | return b2a_hex( (char *)digest, 32 ); 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/binacpp_utils.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef BINACPP_UTILS 4 | #define BINACPP_UTILS 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | void split_string( string &s, char delim, vector &result); 18 | bool replace_string( string& str, const char *from, const char *to); 19 | int replace_string_once( string& str, const char *from, const char *to , int offset); 20 | 21 | 22 | string b2a_hex( char *byte_arr, int n ); 23 | time_t get_current_epoch(); 24 | unsigned long get_current_ms_epoch(); 25 | 26 | 27 | //-------------------- 28 | inline bool file_exists (const std::string& name) { 29 | return ( access( name.c_str(), F_OK ) != -1 ); 30 | } 31 | 32 | string hmac_sha256( const char *key, const char *data); 33 | string sha256( const char *data ); 34 | void string_toupper( string &src); 35 | string string_toupper( const char *cstr ); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/binacpp_websocket.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "binacpp_websocket.h" 4 | #include "binacpp_logger.h" 5 | 6 | 7 | 8 | struct lws_context *BinaCPP_websocket::context = NULL; 9 | struct lws_protocols BinaCPP_websocket::protocols[] = 10 | { 11 | { 12 | "example-protocol", 13 | BinaCPP_websocket::event_cb, 14 | 0, 15 | 65536, 16 | }, 17 | { NULL, NULL, 0, 0 } /* terminator */ 18 | }; 19 | 20 | map BinaCPP_websocket::handles ; 21 | 22 | 23 | 24 | //-------------------------- 25 | int 26 | BinaCPP_websocket::event_cb( struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len ) 27 | { 28 | 29 | switch( reason ) 30 | { 31 | case LWS_CALLBACK_CLIENT_ESTABLISHED: 32 | lws_callback_on_writable( wsi ); 33 | break; 34 | 35 | case LWS_CALLBACK_CLIENT_RECEIVE: 36 | 37 | /* Handle incomming messages here. */ 38 | try { 39 | 40 | //BinaCPP_logger::write_log("%p %s", wsi, (char *)in ); 41 | 42 | string str_result = string( (char*)in ); 43 | Json::Reader reader; 44 | Json::Value json_result; 45 | reader.parse( str_result , json_result ); 46 | 47 | if ( handles.find( wsi ) != handles.end() ) { 48 | handles[wsi]( json_result ); 49 | } 50 | 51 | } catch ( exception &e ) { 52 | BinaCPP_logger::write_log( " Error ! %s", e.what() ); 53 | } 54 | break; 55 | 56 | case LWS_CALLBACK_CLIENT_WRITEABLE: 57 | { 58 | break; 59 | } 60 | 61 | case LWS_CALLBACK_CLOSED: 62 | case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: 63 | if ( handles.find( wsi ) != handles.end() ) { 64 | handles.erase(wsi); 65 | } 66 | break; 67 | 68 | default: 69 | break; 70 | } 71 | 72 | return 0; 73 | } 74 | 75 | 76 | //------------------- 77 | void 78 | BinaCPP_websocket::init( ) 79 | { 80 | struct lws_context_creation_info info; 81 | memset( &info, 0, sizeof(info) ); 82 | 83 | info.port = CONTEXT_PORT_NO_LISTEN; 84 | info.protocols = protocols; 85 | info.gid = -1; 86 | info.uid = -1; 87 | info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; 88 | 89 | context = lws_create_context( &info ); 90 | } 91 | 92 | 93 | //---------------------------- 94 | // Register call backs 95 | void 96 | BinaCPP_websocket::connect_endpoint ( 97 | 98 | CB cb, 99 | const char *path 100 | 101 | ) 102 | { 103 | char ws_path[1024]; 104 | strcpy( ws_path, path ); 105 | 106 | 107 | /* Connect if we are not connected to the server. */ 108 | struct lws_client_connect_info ccinfo = {0}; 109 | ccinfo.context = context; 110 | ccinfo.address = BINANCE_WS_HOST; 111 | ccinfo.port = BINANCE_WS_PORT; 112 | ccinfo.path = ws_path; 113 | ccinfo.host = lws_canonical_hostname( context ); 114 | ccinfo.origin = "origin"; 115 | ccinfo.protocol = protocols[0].name; 116 | ccinfo.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK; 117 | 118 | struct lws* conn = lws_client_connect_via_info(&ccinfo); 119 | handles[conn] = cb; 120 | 121 | 122 | } 123 | 124 | 125 | //---------------------------- 126 | // Entering event loop 127 | void 128 | BinaCPP_websocket::enter_event_loop() 129 | { 130 | while( 1 ) 131 | { 132 | try { 133 | lws_service( context, 500 ); 134 | } catch ( exception &e ) { 135 | BinaCPP_logger::write_log( " Error ! %s", e.what() ); 136 | break; 137 | } 138 | } 139 | lws_context_destroy( context ); 140 | } 141 | 142 | 143 | -------------------------------------------------------------------------------- /src/binacpp_websocket.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | 19 | #define BINANCE_WS_HOST "stream.binance.com" 20 | #define BINANCE_WS_PORT 9443 21 | 22 | 23 | using namespace std; 24 | 25 | typedef int (*CB)(Json::Value &json_value ); 26 | 27 | 28 | class BinaCPP_websocket { 29 | 30 | 31 | static struct lws_context *context; 32 | static struct lws_protocols protocols[]; 33 | 34 | static map handles ; 35 | 36 | public: 37 | static int event_cb( struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len ); 38 | static void connect_endpoint( 39 | CB user_cb, 40 | const char* path 41 | ); 42 | static void init(); 43 | static void enter_event_loop(); 44 | 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /src/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | This is the source of libBinaCPP which is CPP Library for Binance API, running make in this folder will compile libbinacpp.so from source. 6 | 7 | The libbinacpp.so compiled will be generated in ../lib/libbinacpp/lib and the headers in ../lib/libbinacpp/include 8 | 9 | You only need to recompile the src here if you need to modify the source of libBinaCPP. 10 | 11 | 12 | 13 | 14 | 15 | To use the library in your C++ project, just do -I and -L and a -lbinacpp for linker. 16 | 17 | You can view the examples in ../example folder for references on how to use libBinaCPP. 18 | 19 | 20 | 21 | 22 | 23 | --------------------------------------------------------------------------------