![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Embedded C project:18/12/2014
Dependencies: DS1307 TextLCD mbed
NetServices/services/mysql/MySQLClient.cpp@0:8d87bc453349, 2014-12-18 (annotated)
- Committer:
- ninoderkinderen
- Date:
- Thu Dec 18 09:35:49 2014 +0000
- Revision:
- 0:8d87bc453349
Programma embedded C
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ninoderkinderen | 0:8d87bc453349 | 1 | #pragma diag_remark 177 |
ninoderkinderen | 0:8d87bc453349 | 2 | /* |
ninoderkinderen | 0:8d87bc453349 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
ninoderkinderen | 0:8d87bc453349 | 4 | |
ninoderkinderen | 0:8d87bc453349 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
ninoderkinderen | 0:8d87bc453349 | 6 | of this software and associated documentation files (the "Software"), to deal |
ninoderkinderen | 0:8d87bc453349 | 7 | in the Software without restriction, including without limitation the rights |
ninoderkinderen | 0:8d87bc453349 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
ninoderkinderen | 0:8d87bc453349 | 9 | copies of the Software, and to permit persons to whom the Software is |
ninoderkinderen | 0:8d87bc453349 | 10 | furnished to do so, subject to the following conditions: |
ninoderkinderen | 0:8d87bc453349 | 11 | |
ninoderkinderen | 0:8d87bc453349 | 12 | The above copyright notice and this permission notice shall be included in |
ninoderkinderen | 0:8d87bc453349 | 13 | all copies or substantial portions of the Software. |
ninoderkinderen | 0:8d87bc453349 | 14 | |
ninoderkinderen | 0:8d87bc453349 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
ninoderkinderen | 0:8d87bc453349 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
ninoderkinderen | 0:8d87bc453349 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
ninoderkinderen | 0:8d87bc453349 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
ninoderkinderen | 0:8d87bc453349 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ninoderkinderen | 0:8d87bc453349 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
ninoderkinderen | 0:8d87bc453349 | 21 | THE SOFTWARE. |
ninoderkinderen | 0:8d87bc453349 | 22 | */ |
ninoderkinderen | 0:8d87bc453349 | 23 | |
ninoderkinderen | 0:8d87bc453349 | 24 | #include "MySQLClient.h" |
ninoderkinderen | 0:8d87bc453349 | 25 | #include "sha1.h" //For 4.1+ passwords |
ninoderkinderen | 0:8d87bc453349 | 26 | #include "mycrypt.h" //For 4.0- passwords |
ninoderkinderen | 0:8d87bc453349 | 27 | |
ninoderkinderen | 0:8d87bc453349 | 28 | //#define __DEBUG |
ninoderkinderen | 0:8d87bc453349 | 29 | #include "dbg/dbg.h" |
ninoderkinderen | 0:8d87bc453349 | 30 | |
ninoderkinderen | 0:8d87bc453349 | 31 | #define MYSQL_TIMEOUT_MS 45000 |
ninoderkinderen | 0:8d87bc453349 | 32 | #define MYSQL_PORT 3306 |
ninoderkinderen | 0:8d87bc453349 | 33 | |
ninoderkinderen | 0:8d87bc453349 | 34 | #define BUF_SIZE 256 |
ninoderkinderen | 0:8d87bc453349 | 35 | |
ninoderkinderen | 0:8d87bc453349 | 36 | #define CLIENT_LONG_PASSWORD 1 |
ninoderkinderen | 0:8d87bc453349 | 37 | #define CLIENT_CONNECT_WITH_DB 8 |
ninoderkinderen | 0:8d87bc453349 | 38 | #define CLIENT_PROTOCOL_41 512 |
ninoderkinderen | 0:8d87bc453349 | 39 | #define CLIENT_INTERACTIVE 1024 |
ninoderkinderen | 0:8d87bc453349 | 40 | #define CLIENT_SECURE_CONNECTION 32768 |
ninoderkinderen | 0:8d87bc453349 | 41 | |
ninoderkinderen | 0:8d87bc453349 | 42 | #define MIN(a,b) ((a)<(b)?(a):(b)) |
ninoderkinderen | 0:8d87bc453349 | 43 | #define ABS(a) (((a)>0)?(a):0) |
ninoderkinderen | 0:8d87bc453349 | 44 | |
ninoderkinderen | 0:8d87bc453349 | 45 | //MySQL commands |
ninoderkinderen | 0:8d87bc453349 | 46 | #define COM_QUIT 0x01 //Exit |
ninoderkinderen | 0:8d87bc453349 | 47 | #define COM_QUERY 0x03 //Execute an SQL query |
ninoderkinderen | 0:8d87bc453349 | 48 | |
ninoderkinderen | 0:8d87bc453349 | 49 | //#define htons( x ) ( (( x << 8 ) & 0xFF00) | (( x >> 8 ) & 0x00FF) ) |
ninoderkinderen | 0:8d87bc453349 | 50 | #define ntohs( x ) (htons(x)) |
ninoderkinderen | 0:8d87bc453349 | 51 | |
ninoderkinderen | 0:8d87bc453349 | 52 | /*#define htonl( x ) ( (( x << 24 ) & 0xFF000000) \ |
ninoderkinderen | 0:8d87bc453349 | 53 | | (( x << 8 ) & 0x00FF0000) \ |
ninoderkinderen | 0:8d87bc453349 | 54 | | (( x >> 8 ) & 0x0000FF00) \ |
ninoderkinderen | 0:8d87bc453349 | 55 | | (( x >> 24 ) & 0x000000FF) )*/ |
ninoderkinderen | 0:8d87bc453349 | 56 | #define htonl( x ) (x) |
ninoderkinderen | 0:8d87bc453349 | 57 | #define ntohl( x ) (htonl(x)) |
ninoderkinderen | 0:8d87bc453349 | 58 | |
ninoderkinderen | 0:8d87bc453349 | 59 | MySQLClient::MySQLClient() : NetService(false) /*Not owned by the pool*/, m_pCbItem(NULL), m_pCbMeth(NULL), m_pCb(NULL), |
ninoderkinderen | 0:8d87bc453349 | 60 | m_pTCPSocket(NULL), m_watchdog(), m_timeout(MYSQL_TIMEOUT_MS*1000), m_pDnsReq(NULL), m_closed(true), |
ninoderkinderen | 0:8d87bc453349 | 61 | m_host(), m_user(), m_password(), m_db(), m_state(MYSQL_CLOSED) |
ninoderkinderen | 0:8d87bc453349 | 62 | { |
ninoderkinderen | 0:8d87bc453349 | 63 | m_buf = new byte[BUF_SIZE]; |
ninoderkinderen | 0:8d87bc453349 | 64 | m_pPos = m_buf; |
ninoderkinderen | 0:8d87bc453349 | 65 | m_len = 0; |
ninoderkinderen | 0:8d87bc453349 | 66 | m_size = BUF_SIZE; |
ninoderkinderen | 0:8d87bc453349 | 67 | } |
ninoderkinderen | 0:8d87bc453349 | 68 | |
ninoderkinderen | 0:8d87bc453349 | 69 | MySQLClient::~MySQLClient() |
ninoderkinderen | 0:8d87bc453349 | 70 | { |
ninoderkinderen | 0:8d87bc453349 | 71 | close(); |
ninoderkinderen | 0:8d87bc453349 | 72 | delete[] m_buf; |
ninoderkinderen | 0:8d87bc453349 | 73 | } |
ninoderkinderen | 0:8d87bc453349 | 74 | |
ninoderkinderen | 0:8d87bc453349 | 75 | //High Level setup functions |
ninoderkinderen | 0:8d87bc453349 | 76 | MySQLResult MySQLClient::open(Host& host, const string& user, const string& password, const string& db, void (*pMethod)(MySQLResult)) //Non blocking |
ninoderkinderen | 0:8d87bc453349 | 77 | { |
ninoderkinderen | 0:8d87bc453349 | 78 | setOnResult(pMethod); |
ninoderkinderen | 0:8d87bc453349 | 79 | setup(host, user, password, db); |
ninoderkinderen | 0:8d87bc453349 | 80 | return MYSQL_PROCESSING; |
ninoderkinderen | 0:8d87bc453349 | 81 | } |
ninoderkinderen | 0:8d87bc453349 | 82 | |
ninoderkinderen | 0:8d87bc453349 | 83 | #if 0 //Ref only |
ninoderkinderen | 0:8d87bc453349 | 84 | template<class T> |
ninoderkinderen | 0:8d87bc453349 | 85 | MySQLResult MySQLClient::open(Host& host, const string& user, const string& password, const string& db, T* pItem, void (T::*pMethod)(MySQLResult)) //Non blocking |
ninoderkinderen | 0:8d87bc453349 | 86 | { |
ninoderkinderen | 0:8d87bc453349 | 87 | setOnResult(pItem, pMethod); |
ninoderkinderen | 0:8d87bc453349 | 88 | setup(host, user, password, db); |
ninoderkinderen | 0:8d87bc453349 | 89 | return MYSQL_PROCESSING; |
ninoderkinderen | 0:8d87bc453349 | 90 | } |
ninoderkinderen | 0:8d87bc453349 | 91 | #endif |
ninoderkinderen | 0:8d87bc453349 | 92 | |
ninoderkinderen | 0:8d87bc453349 | 93 | MySQLResult MySQLClient::sql(string& sqlCommand) |
ninoderkinderen | 0:8d87bc453349 | 94 | { |
ninoderkinderen | 0:8d87bc453349 | 95 | if(m_state!=MYSQL_COMMANDS) |
ninoderkinderen | 0:8d87bc453349 | 96 | return MYSQL_SETUP; |
ninoderkinderen | 0:8d87bc453349 | 97 | sendCommand(COM_QUERY, (byte*)sqlCommand.data(), sqlCommand.length()); |
ninoderkinderen | 0:8d87bc453349 | 98 | return MYSQL_PROCESSING; |
ninoderkinderen | 0:8d87bc453349 | 99 | } |
ninoderkinderen | 0:8d87bc453349 | 100 | |
ninoderkinderen | 0:8d87bc453349 | 101 | MySQLResult MySQLClient::exit() |
ninoderkinderen | 0:8d87bc453349 | 102 | { |
ninoderkinderen | 0:8d87bc453349 | 103 | sendCommand(COM_QUIT, NULL, 0); |
ninoderkinderen | 0:8d87bc453349 | 104 | close(); |
ninoderkinderen | 0:8d87bc453349 | 105 | return MYSQL_OK; |
ninoderkinderen | 0:8d87bc453349 | 106 | } |
ninoderkinderen | 0:8d87bc453349 | 107 | |
ninoderkinderen | 0:8d87bc453349 | 108 | void MySQLClient::setOnResult( void (*pMethod)(MySQLResult) ) |
ninoderkinderen | 0:8d87bc453349 | 109 | { |
ninoderkinderen | 0:8d87bc453349 | 110 | m_pCb = pMethod; |
ninoderkinderen | 0:8d87bc453349 | 111 | m_pCbItem = NULL; |
ninoderkinderen | 0:8d87bc453349 | 112 | m_pCbMeth = NULL; |
ninoderkinderen | 0:8d87bc453349 | 113 | } |
ninoderkinderen | 0:8d87bc453349 | 114 | |
ninoderkinderen | 0:8d87bc453349 | 115 | #if 0 //Ref only |
ninoderkinderen | 0:8d87bc453349 | 116 | template<class T> |
ninoderkinderen | 0:8d87bc453349 | 117 | void MySQLClient::setOnResult( T* pItem, void (T::*pMethod)(MySQLResult) ) |
ninoderkinderen | 0:8d87bc453349 | 118 | { |
ninoderkinderen | 0:8d87bc453349 | 119 | m_pCb = NULL; |
ninoderkinderen | 0:8d87bc453349 | 120 | m_pCbItem = (CDummy*) pItem; |
ninoderkinderen | 0:8d87bc453349 | 121 | m_pCbMeth = (void (CDummy::*)(MySQLResult)) pMethod; |
ninoderkinderen | 0:8d87bc453349 | 122 | } |
ninoderkinderen | 0:8d87bc453349 | 123 | #endif |
ninoderkinderen | 0:8d87bc453349 | 124 | |
ninoderkinderen | 0:8d87bc453349 | 125 | void MySQLClient::setTimeout(int ms) |
ninoderkinderen | 0:8d87bc453349 | 126 | { |
ninoderkinderen | 0:8d87bc453349 | 127 | m_timeout = 1000*ms; |
ninoderkinderen | 0:8d87bc453349 | 128 | } |
ninoderkinderen | 0:8d87bc453349 | 129 | |
ninoderkinderen | 0:8d87bc453349 | 130 | void MySQLClient::poll() //Called by NetServices |
ninoderkinderen | 0:8d87bc453349 | 131 | { |
ninoderkinderen | 0:8d87bc453349 | 132 | if(m_closed) |
ninoderkinderen | 0:8d87bc453349 | 133 | { |
ninoderkinderen | 0:8d87bc453349 | 134 | return; |
ninoderkinderen | 0:8d87bc453349 | 135 | } |
ninoderkinderen | 0:8d87bc453349 | 136 | if(m_watchdog.read_us()>m_timeout) |
ninoderkinderen | 0:8d87bc453349 | 137 | { |
ninoderkinderen | 0:8d87bc453349 | 138 | onTimeout(); |
ninoderkinderen | 0:8d87bc453349 | 139 | } |
ninoderkinderen | 0:8d87bc453349 | 140 | } |
ninoderkinderen | 0:8d87bc453349 | 141 | |
ninoderkinderen | 0:8d87bc453349 | 142 | void MySQLClient::resetTimeout() |
ninoderkinderen | 0:8d87bc453349 | 143 | { |
ninoderkinderen | 0:8d87bc453349 | 144 | m_watchdog.reset(); |
ninoderkinderen | 0:8d87bc453349 | 145 | m_watchdog.start(); |
ninoderkinderen | 0:8d87bc453349 | 146 | } |
ninoderkinderen | 0:8d87bc453349 | 147 | |
ninoderkinderen | 0:8d87bc453349 | 148 | void MySQLClient::init() |
ninoderkinderen | 0:8d87bc453349 | 149 | { |
ninoderkinderen | 0:8d87bc453349 | 150 | close(); //Remove previous elements |
ninoderkinderen | 0:8d87bc453349 | 151 | if(!m_closed) //Already opened |
ninoderkinderen | 0:8d87bc453349 | 152 | return; |
ninoderkinderen | 0:8d87bc453349 | 153 | m_state = MYSQL_HANDSHAKE; |
ninoderkinderen | 0:8d87bc453349 | 154 | m_pTCPSocket = new TCPSocket; |
ninoderkinderen | 0:8d87bc453349 | 155 | m_pTCPSocket->setOnEvent(this, &MySQLClient::onTCPSocketEvent); |
ninoderkinderen | 0:8d87bc453349 | 156 | m_closed = false; |
ninoderkinderen | 0:8d87bc453349 | 157 | } |
ninoderkinderen | 0:8d87bc453349 | 158 | |
ninoderkinderen | 0:8d87bc453349 | 159 | void MySQLClient::close() |
ninoderkinderen | 0:8d87bc453349 | 160 | { |
ninoderkinderen | 0:8d87bc453349 | 161 | if(m_closed) |
ninoderkinderen | 0:8d87bc453349 | 162 | return; |
ninoderkinderen | 0:8d87bc453349 | 163 | m_state = MYSQL_CLOSED; |
ninoderkinderen | 0:8d87bc453349 | 164 | m_closed = true; //Prevent recursive calling or calling on an object being destructed by someone else |
ninoderkinderen | 0:8d87bc453349 | 165 | m_watchdog.stop(); //Stop timeout |
ninoderkinderen | 0:8d87bc453349 | 166 | m_watchdog.reset(); |
ninoderkinderen | 0:8d87bc453349 | 167 | m_pTCPSocket->resetOnEvent(); |
ninoderkinderen | 0:8d87bc453349 | 168 | m_pTCPSocket->close(); |
ninoderkinderen | 0:8d87bc453349 | 169 | delete m_pTCPSocket; |
ninoderkinderen | 0:8d87bc453349 | 170 | m_pTCPSocket = NULL; |
ninoderkinderen | 0:8d87bc453349 | 171 | if( m_pDnsReq ) |
ninoderkinderen | 0:8d87bc453349 | 172 | { |
ninoderkinderen | 0:8d87bc453349 | 173 | m_pDnsReq->close(); |
ninoderkinderen | 0:8d87bc453349 | 174 | delete m_pDnsReq; |
ninoderkinderen | 0:8d87bc453349 | 175 | m_pDnsReq = NULL; |
ninoderkinderen | 0:8d87bc453349 | 176 | } |
ninoderkinderen | 0:8d87bc453349 | 177 | } |
ninoderkinderen | 0:8d87bc453349 | 178 | |
ninoderkinderen | 0:8d87bc453349 | 179 | void MySQLClient::setup(Host& host, const string& user, const string& password, const string& db) //Setup connection, make DNS Req if necessary |
ninoderkinderen | 0:8d87bc453349 | 180 | { |
ninoderkinderen | 0:8d87bc453349 | 181 | init(); //Initialize client in known state, create socket |
ninoderkinderen | 0:8d87bc453349 | 182 | resetTimeout(); |
ninoderkinderen | 0:8d87bc453349 | 183 | m_host = host; |
ninoderkinderen | 0:8d87bc453349 | 184 | if(!host.getPort()) |
ninoderkinderen | 0:8d87bc453349 | 185 | host.setPort( MYSQL_PORT ); //Default port |
ninoderkinderen | 0:8d87bc453349 | 186 | |
ninoderkinderen | 0:8d87bc453349 | 187 | m_user = user; |
ninoderkinderen | 0:8d87bc453349 | 188 | m_password = password; |
ninoderkinderen | 0:8d87bc453349 | 189 | |
ninoderkinderen | 0:8d87bc453349 | 190 | m_db = db; |
ninoderkinderen | 0:8d87bc453349 | 191 | |
ninoderkinderen | 0:8d87bc453349 | 192 | if( !host.getIp().isNull() ) |
ninoderkinderen | 0:8d87bc453349 | 193 | { |
ninoderkinderen | 0:8d87bc453349 | 194 | connect(); |
ninoderkinderen | 0:8d87bc453349 | 195 | } |
ninoderkinderen | 0:8d87bc453349 | 196 | else //Need to do a DNS Query... |
ninoderkinderen | 0:8d87bc453349 | 197 | { |
ninoderkinderen | 0:8d87bc453349 | 198 | DBG("DNS Query...\n"); |
ninoderkinderen | 0:8d87bc453349 | 199 | m_pDnsReq = new DNSRequest(); |
ninoderkinderen | 0:8d87bc453349 | 200 | m_pDnsReq->setOnReply(this, &MySQLClient::onDNSReply); |
ninoderkinderen | 0:8d87bc453349 | 201 | m_pDnsReq->resolve(&m_host); |
ninoderkinderen | 0:8d87bc453349 | 202 | DBG("MySQLClient : DNSRequest %p\n", m_pDnsReq); |
ninoderkinderen | 0:8d87bc453349 | 203 | } |
ninoderkinderen | 0:8d87bc453349 | 204 | } |
ninoderkinderen | 0:8d87bc453349 | 205 | |
ninoderkinderen | 0:8d87bc453349 | 206 | void MySQLClient::connect() //Start Connection |
ninoderkinderen | 0:8d87bc453349 | 207 | { |
ninoderkinderen | 0:8d87bc453349 | 208 | resetTimeout(); |
ninoderkinderen | 0:8d87bc453349 | 209 | DBG("Connecting...\n"); |
ninoderkinderen | 0:8d87bc453349 | 210 | m_pTCPSocket->connect(m_host); |
ninoderkinderen | 0:8d87bc453349 | 211 | m_packetId = 0; |
ninoderkinderen | 0:8d87bc453349 | 212 | } |
ninoderkinderen | 0:8d87bc453349 | 213 | |
ninoderkinderen | 0:8d87bc453349 | 214 | void MySQLClient::handleHandshake() |
ninoderkinderen | 0:8d87bc453349 | 215 | { |
ninoderkinderen | 0:8d87bc453349 | 216 | readData(); |
ninoderkinderen | 0:8d87bc453349 | 217 | if( ! (( m_len > 1 ) && ( memchr( m_buf + 1, 0, m_len ) != NULL )) ) |
ninoderkinderen | 0:8d87bc453349 | 218 | { |
ninoderkinderen | 0:8d87bc453349 | 219 | DBG("Connected but could not find pcsz...\n"); |
ninoderkinderen | 0:8d87bc453349 | 220 | onResult(MYSQL_PRTCL); |
ninoderkinderen | 0:8d87bc453349 | 221 | return; |
ninoderkinderen | 0:8d87bc453349 | 222 | } |
ninoderkinderen | 0:8d87bc453349 | 223 | |
ninoderkinderen | 0:8d87bc453349 | 224 | DBG("Connected to server: %d bytes read ; Protocol version %d, mysql-%s.\n", m_len, m_buf[0], &m_buf[1]); |
ninoderkinderen | 0:8d87bc453349 | 225 | |
ninoderkinderen | 0:8d87bc453349 | 226 | m_pPos = (byte*) memchr( (char*)(m_buf + 1), 0, m_len ) + 1; |
ninoderkinderen | 0:8d87bc453349 | 227 | |
ninoderkinderen | 0:8d87bc453349 | 228 | sendAuth(); |
ninoderkinderen | 0:8d87bc453349 | 229 | } |
ninoderkinderen | 0:8d87bc453349 | 230 | |
ninoderkinderen | 0:8d87bc453349 | 231 | void MySQLClient::sendAuth() |
ninoderkinderen | 0:8d87bc453349 | 232 | { |
ninoderkinderen | 0:8d87bc453349 | 233 | if( m_len - (m_pPos - m_buf) != 44) |
ninoderkinderen | 0:8d87bc453349 | 234 | { |
ninoderkinderen | 0:8d87bc453349 | 235 | //We only support protocol >= mysql-4.1 |
ninoderkinderen | 0:8d87bc453349 | 236 | DBG("Message after pcsz has wrong len (%d != 44)...\n", m_len - (m_pPos - m_buf)); |
ninoderkinderen | 0:8d87bc453349 | 237 | onResult(MYSQL_PRTCL); |
ninoderkinderen | 0:8d87bc453349 | 238 | return; |
ninoderkinderen | 0:8d87bc453349 | 239 | } |
ninoderkinderen | 0:8d87bc453349 | 240 | |
ninoderkinderen | 0:8d87bc453349 | 241 | uint16_t serverFlags = *((uint16_t*)&m_pPos[13]); |
ninoderkinderen | 0:8d87bc453349 | 242 | DBG("Server capabilities are %04X.\n", serverFlags); |
ninoderkinderen | 0:8d87bc453349 | 243 | |
ninoderkinderen | 0:8d87bc453349 | 244 | uint32_t clientFlags = CLIENT_CONNECT_WITH_DB | CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | CLIENT_INTERACTIVE;; |
ninoderkinderen | 0:8d87bc453349 | 245 | |
ninoderkinderen | 0:8d87bc453349 | 246 | //if(serverFlags & CLIENT_LONG_PASSWORD) |
ninoderkinderen | 0:8d87bc453349 | 247 | |
ninoderkinderen | 0:8d87bc453349 | 248 | DBG("Using auth 4.1+\n"); |
ninoderkinderen | 0:8d87bc453349 | 249 | //Encrypt pw using scramble |
ninoderkinderen | 0:8d87bc453349 | 250 | byte scramble[20+20]={0}; |
ninoderkinderen | 0:8d87bc453349 | 251 | memcpy(scramble, m_pPos+4, 8); |
ninoderkinderen | 0:8d87bc453349 | 252 | memcpy(scramble+8, m_pPos+31, 12); // *(m_pPos+43) == 0 (zero-terminated char*) |
ninoderkinderen | 0:8d87bc453349 | 253 | |
ninoderkinderen | 0:8d87bc453349 | 254 | byte stage1_hash[20] = {0}; |
ninoderkinderen | 0:8d87bc453349 | 255 | sha1( (byte*)m_password.data(), m_password.length(), stage1_hash ); |
ninoderkinderen | 0:8d87bc453349 | 256 | |
ninoderkinderen | 0:8d87bc453349 | 257 | sha1( stage1_hash, 20, ((byte*)scramble + 20) ); |
ninoderkinderen | 0:8d87bc453349 | 258 | |
ninoderkinderen | 0:8d87bc453349 | 259 | byte token[20] = {0}; |
ninoderkinderen | 0:8d87bc453349 | 260 | sha1( scramble, 40, token ); |
ninoderkinderen | 0:8d87bc453349 | 261 | |
ninoderkinderen | 0:8d87bc453349 | 262 | for(int i=0;i<20;i++) |
ninoderkinderen | 0:8d87bc453349 | 263 | token[i] = token[i] ^ stage1_hash[i]; |
ninoderkinderen | 0:8d87bc453349 | 264 | |
ninoderkinderen | 0:8d87bc453349 | 265 | clientFlags |= CLIENT_LONG_PASSWORD; |
ninoderkinderen | 0:8d87bc453349 | 266 | |
ninoderkinderen | 0:8d87bc453349 | 267 | DBG("Building response\n"); |
ninoderkinderen | 0:8d87bc453349 | 268 | //Build response |
ninoderkinderen | 0:8d87bc453349 | 269 | |
ninoderkinderen | 0:8d87bc453349 | 270 | //BE |
ninoderkinderen | 0:8d87bc453349 | 271 | *((uint32_t*)&m_buf[0]) = htonl(clientFlags); |
ninoderkinderen | 0:8d87bc453349 | 272 | *((uint32_t*)&m_buf[4]) = BUF_SIZE; //Max packets size |
ninoderkinderen | 0:8d87bc453349 | 273 | m_buf[8] = 8; //latin1 charset |
ninoderkinderen | 0:8d87bc453349 | 274 | memset((char*)(m_buf+9),0,23); |
ninoderkinderen | 0:8d87bc453349 | 275 | strcpy((char*)(m_buf+32),m_user.c_str()); |
ninoderkinderen | 0:8d87bc453349 | 276 | m_pPos = m_buf + 32 + m_user.length() + 1; |
ninoderkinderen | 0:8d87bc453349 | 277 | m_pPos[0] = 20; |
ninoderkinderen | 0:8d87bc453349 | 278 | memcpy((char*)&m_pPos[1],token,20); |
ninoderkinderen | 0:8d87bc453349 | 279 | strcpy((char*)(m_pPos+21),m_db.c_str()); |
ninoderkinderen | 0:8d87bc453349 | 280 | m_len = 32 + m_user.length() + 1 + 21 + m_db.length() + 1; |
ninoderkinderen | 0:8d87bc453349 | 281 | |
ninoderkinderen | 0:8d87bc453349 | 282 | //Save first part of scramble in case we need it again |
ninoderkinderen | 0:8d87bc453349 | 283 | memcpy(&m_buf[BUF_SIZE-8], scramble, 8); |
ninoderkinderen | 0:8d87bc453349 | 284 | |
ninoderkinderen | 0:8d87bc453349 | 285 | m_state = MYSQL_AUTH; |
ninoderkinderen | 0:8d87bc453349 | 286 | |
ninoderkinderen | 0:8d87bc453349 | 287 | DBG("Writing data\n"); |
ninoderkinderen | 0:8d87bc453349 | 288 | writeData(); |
ninoderkinderen | 0:8d87bc453349 | 289 | } |
ninoderkinderen | 0:8d87bc453349 | 290 | |
ninoderkinderen | 0:8d87bc453349 | 291 | void MySQLClient::handleAuthResult() |
ninoderkinderen | 0:8d87bc453349 | 292 | { |
ninoderkinderen | 0:8d87bc453349 | 293 | readData(); |
ninoderkinderen | 0:8d87bc453349 | 294 | if(m_len==1 && *m_buf==0xfe) |
ninoderkinderen | 0:8d87bc453349 | 295 | { |
ninoderkinderen | 0:8d87bc453349 | 296 | //Re-send auth using 4.0- auth |
ninoderkinderen | 0:8d87bc453349 | 297 | sendAuth323(); |
ninoderkinderen | 0:8d87bc453349 | 298 | return; |
ninoderkinderen | 0:8d87bc453349 | 299 | } |
ninoderkinderen | 0:8d87bc453349 | 300 | m_watchdog.stop(); //Stop timeout |
ninoderkinderen | 0:8d87bc453349 | 301 | m_watchdog.reset(); |
ninoderkinderen | 0:8d87bc453349 | 302 | if(m_len<2) |
ninoderkinderen | 0:8d87bc453349 | 303 | { |
ninoderkinderen | 0:8d87bc453349 | 304 | DBG("Response too short..\n"); |
ninoderkinderen | 0:8d87bc453349 | 305 | onResult(MYSQL_PRTCL); |
ninoderkinderen | 0:8d87bc453349 | 306 | return; |
ninoderkinderen | 0:8d87bc453349 | 307 | } |
ninoderkinderen | 0:8d87bc453349 | 308 | DBG("RC=%d ",m_buf[0]); |
ninoderkinderen | 0:8d87bc453349 | 309 | if(m_buf[0]==0) |
ninoderkinderen | 0:8d87bc453349 | 310 | { |
ninoderkinderen | 0:8d87bc453349 | 311 | m_buf[m_len] = 0; |
ninoderkinderen | 0:8d87bc453349 | 312 | m_pPos = m_buf + 1; |
ninoderkinderen | 0:8d87bc453349 | 313 | m_pPos += m_buf[1] +1; |
ninoderkinderen | 0:8d87bc453349 | 314 | m_pPos += m_pPos[0]; |
ninoderkinderen | 0:8d87bc453349 | 315 | m_pPos += 1; |
ninoderkinderen | 0:8d87bc453349 | 316 | DBG("(OK) : Server status %d, Message : %s\n", *((uint16_t*)&m_pPos[0]), m_pPos+4); |
ninoderkinderen | 0:8d87bc453349 | 317 | onResult(MYSQL_OK); |
ninoderkinderen | 0:8d87bc453349 | 318 | } |
ninoderkinderen | 0:8d87bc453349 | 319 | else |
ninoderkinderen | 0:8d87bc453349 | 320 | { |
ninoderkinderen | 0:8d87bc453349 | 321 | m_buf[m_len] = 0; |
ninoderkinderen | 0:8d87bc453349 | 322 | DBG("(Error %d) : %s\n", *((uint16_t*)&m_buf[1]), &m_buf[9]); //LE |
ninoderkinderen | 0:8d87bc453349 | 323 | onResult(MYSQL_AUTHFAILED); |
ninoderkinderen | 0:8d87bc453349 | 324 | return; |
ninoderkinderen | 0:8d87bc453349 | 325 | } |
ninoderkinderen | 0:8d87bc453349 | 326 | m_state = MYSQL_COMMANDS; |
ninoderkinderen | 0:8d87bc453349 | 327 | } |
ninoderkinderen | 0:8d87bc453349 | 328 | |
ninoderkinderen | 0:8d87bc453349 | 329 | void MySQLClient::sendAuth323() |
ninoderkinderen | 0:8d87bc453349 | 330 | { |
ninoderkinderen | 0:8d87bc453349 | 331 | DBG("Using auth 4.0-\n"); |
ninoderkinderen | 0:8d87bc453349 | 332 | byte scramble[8]={0}; |
ninoderkinderen | 0:8d87bc453349 | 333 | |
ninoderkinderen | 0:8d87bc453349 | 334 | memcpy(scramble, &m_buf[BUF_SIZE-8], 8); //Recover scramble |
ninoderkinderen | 0:8d87bc453349 | 335 | |
ninoderkinderen | 0:8d87bc453349 | 336 | //memcpy(scramble+8, m_pPos+31, 12); // *(m_pPos+43) == 0 (zero-terminated char*) |
ninoderkinderen | 0:8d87bc453349 | 337 | |
ninoderkinderen | 0:8d87bc453349 | 338 | byte token[9]={0}; |
ninoderkinderen | 0:8d87bc453349 | 339 | |
ninoderkinderen | 0:8d87bc453349 | 340 | scramble_323((char*)token, (const char*)scramble, m_password.c_str()); |
ninoderkinderen | 0:8d87bc453349 | 341 | |
ninoderkinderen | 0:8d87bc453349 | 342 | DBG("Building response\n"); |
ninoderkinderen | 0:8d87bc453349 | 343 | //Build response |
ninoderkinderen | 0:8d87bc453349 | 344 | |
ninoderkinderen | 0:8d87bc453349 | 345 | memcpy((char*)m_buf,token,9); |
ninoderkinderen | 0:8d87bc453349 | 346 | m_len = 9; |
ninoderkinderen | 0:8d87bc453349 | 347 | |
ninoderkinderen | 0:8d87bc453349 | 348 | #if 0 |
ninoderkinderen | 0:8d87bc453349 | 349 | *((uint32_t*)&m_buf[0]) = htonl(clientFlags); |
ninoderkinderen | 0:8d87bc453349 | 350 | *((uint32_t*)&m_buf[4]) = BUF_SIZE; //Max packets size |
ninoderkinderen | 0:8d87bc453349 | 351 | m_buf[8] = 8; //latin1 charset |
ninoderkinderen | 0:8d87bc453349 | 352 | memset((char*)(m_buf+9),0,23); |
ninoderkinderen | 0:8d87bc453349 | 353 | strcpy((char*)(m_buf+32),m_user.c_str()); |
ninoderkinderen | 0:8d87bc453349 | 354 | m_pPos = m_buf + 32 + m_user.length() + 1; |
ninoderkinderen | 0:8d87bc453349 | 355 | m_pPos[0] = 8; |
ninoderkinderen | 0:8d87bc453349 | 356 | memcpy((char*)&m_pPos[1],token+1,8); |
ninoderkinderen | 0:8d87bc453349 | 357 | strcpy((char*)(m_pPos+9),m_db.c_str()); |
ninoderkinderen | 0:8d87bc453349 | 358 | m_len = 32 + m_user.length() + 1 + 9 + m_db.length() + 1; |
ninoderkinderen | 0:8d87bc453349 | 359 | #endif |
ninoderkinderen | 0:8d87bc453349 | 360 | |
ninoderkinderen | 0:8d87bc453349 | 361 | DBG("Writing data\n"); |
ninoderkinderen | 0:8d87bc453349 | 362 | writeData(); |
ninoderkinderen | 0:8d87bc453349 | 363 | } |
ninoderkinderen | 0:8d87bc453349 | 364 | |
ninoderkinderen | 0:8d87bc453349 | 365 | void MySQLClient::sendCommand(byte command, byte* arg, int len) |
ninoderkinderen | 0:8d87bc453349 | 366 | { |
ninoderkinderen | 0:8d87bc453349 | 367 | DBG("Sending command %d, payload of len %d\n", command, len); |
ninoderkinderen | 0:8d87bc453349 | 368 | m_packetId=0;//Reset packet ID (New sequence) |
ninoderkinderen | 0:8d87bc453349 | 369 | m_buf[0] = command; |
ninoderkinderen | 0:8d87bc453349 | 370 | memcpy(&m_buf[1], arg, len); |
ninoderkinderen | 0:8d87bc453349 | 371 | m_len = 1 + len; |
ninoderkinderen | 0:8d87bc453349 | 372 | writeData(); |
ninoderkinderen | 0:8d87bc453349 | 373 | m_watchdog.start(); |
ninoderkinderen | 0:8d87bc453349 | 374 | } |
ninoderkinderen | 0:8d87bc453349 | 375 | |
ninoderkinderen | 0:8d87bc453349 | 376 | void MySQLClient::handleCommandResult() |
ninoderkinderen | 0:8d87bc453349 | 377 | { |
ninoderkinderen | 0:8d87bc453349 | 378 | readData(); |
ninoderkinderen | 0:8d87bc453349 | 379 | m_watchdog.stop(); //Stop timeout |
ninoderkinderen | 0:8d87bc453349 | 380 | m_watchdog.reset(); |
ninoderkinderen | 0:8d87bc453349 | 381 | if(m_len<2) |
ninoderkinderen | 0:8d87bc453349 | 382 | { |
ninoderkinderen | 0:8d87bc453349 | 383 | DBG("Response too short..\n"); |
ninoderkinderen | 0:8d87bc453349 | 384 | onResult(MYSQL_PRTCL); |
ninoderkinderen | 0:8d87bc453349 | 385 | return; |
ninoderkinderen | 0:8d87bc453349 | 386 | } |
ninoderkinderen | 0:8d87bc453349 | 387 | DBG("RC=%d ",m_buf[0]); |
ninoderkinderen | 0:8d87bc453349 | 388 | if(m_buf[0]==0) |
ninoderkinderen | 0:8d87bc453349 | 389 | { |
ninoderkinderen | 0:8d87bc453349 | 390 | DBG("(OK)\n"); |
ninoderkinderen | 0:8d87bc453349 | 391 | onResult(MYSQL_OK); |
ninoderkinderen | 0:8d87bc453349 | 392 | } |
ninoderkinderen | 0:8d87bc453349 | 393 | else |
ninoderkinderen | 0:8d87bc453349 | 394 | { |
ninoderkinderen | 0:8d87bc453349 | 395 | m_buf[m_len] = 0; |
ninoderkinderen | 0:8d87bc453349 | 396 | DBG("(SQL Error %d) : %s\n", *((uint16_t*)&m_buf[1]), &m_buf[9]); //LE |
ninoderkinderen | 0:8d87bc453349 | 397 | onResult(MYSQL_SQL); |
ninoderkinderen | 0:8d87bc453349 | 398 | return; |
ninoderkinderen | 0:8d87bc453349 | 399 | } |
ninoderkinderen | 0:8d87bc453349 | 400 | } |
ninoderkinderen | 0:8d87bc453349 | 401 | |
ninoderkinderen | 0:8d87bc453349 | 402 | void MySQLClient::readData() //Copy to buf |
ninoderkinderen | 0:8d87bc453349 | 403 | { |
ninoderkinderen | 0:8d87bc453349 | 404 | byte head[4]; |
ninoderkinderen | 0:8d87bc453349 | 405 | int ret = m_pTCPSocket->recv((char*)head, 4); //Packet header |
ninoderkinderen | 0:8d87bc453349 | 406 | m_len = *((uint16_t*)&head[0]); |
ninoderkinderen | 0:8d87bc453349 | 407 | m_packetId = head[3]; |
ninoderkinderen | 0:8d87bc453349 | 408 | DBG("Packet Id %d of length %d\n", head[3], m_len); |
ninoderkinderen | 0:8d87bc453349 | 409 | m_packetId++; |
ninoderkinderen | 0:8d87bc453349 | 410 | if(ret>0) |
ninoderkinderen | 0:8d87bc453349 | 411 | ret = m_pTCPSocket->recv((char*)m_buf, m_len); |
ninoderkinderen | 0:8d87bc453349 | 412 | if(ret < 0)//Error |
ninoderkinderen | 0:8d87bc453349 | 413 | { |
ninoderkinderen | 0:8d87bc453349 | 414 | onResult(MYSQL_CONN); |
ninoderkinderen | 0:8d87bc453349 | 415 | return; |
ninoderkinderen | 0:8d87bc453349 | 416 | } |
ninoderkinderen | 0:8d87bc453349 | 417 | if(ret < m_len) |
ninoderkinderen | 0:8d87bc453349 | 418 | { |
ninoderkinderen | 0:8d87bc453349 | 419 | DBG("WARN: Incomplete packet\n"); |
ninoderkinderen | 0:8d87bc453349 | 420 | } |
ninoderkinderen | 0:8d87bc453349 | 421 | m_len = ret; |
ninoderkinderen | 0:8d87bc453349 | 422 | } |
ninoderkinderen | 0:8d87bc453349 | 423 | |
ninoderkinderen | 0:8d87bc453349 | 424 | void MySQLClient::writeData() //Copy from buf |
ninoderkinderen | 0:8d87bc453349 | 425 | { |
ninoderkinderen | 0:8d87bc453349 | 426 | byte head[4] = { 0 }; |
ninoderkinderen | 0:8d87bc453349 | 427 | *((uint16_t*)&head[0]) = m_len; |
ninoderkinderen | 0:8d87bc453349 | 428 | head[3] = m_packetId; |
ninoderkinderen | 0:8d87bc453349 | 429 | DBG("Packet Id %d\n", head[3]); |
ninoderkinderen | 0:8d87bc453349 | 430 | m_packetId++; |
ninoderkinderen | 0:8d87bc453349 | 431 | int ret = m_pTCPSocket->send((char*)head, 4); //Packet header |
ninoderkinderen | 0:8d87bc453349 | 432 | if(ret>0) |
ninoderkinderen | 0:8d87bc453349 | 433 | ret = m_pTCPSocket->send((char*)m_buf, m_len); |
ninoderkinderen | 0:8d87bc453349 | 434 | if(ret < 0)//Error |
ninoderkinderen | 0:8d87bc453349 | 435 | { |
ninoderkinderen | 0:8d87bc453349 | 436 | onResult(MYSQL_CONN); |
ninoderkinderen | 0:8d87bc453349 | 437 | return; |
ninoderkinderen | 0:8d87bc453349 | 438 | } |
ninoderkinderen | 0:8d87bc453349 | 439 | m_len = 0;//FIXME... incomplete packets handling |
ninoderkinderen | 0:8d87bc453349 | 440 | } |
ninoderkinderen | 0:8d87bc453349 | 441 | |
ninoderkinderen | 0:8d87bc453349 | 442 | void MySQLClient::onTCPSocketEvent(TCPSocketEvent e) |
ninoderkinderen | 0:8d87bc453349 | 443 | { |
ninoderkinderen | 0:8d87bc453349 | 444 | DBG("Event %d in MySQLClient::onTCPSocketEvent()\n", e); |
ninoderkinderen | 0:8d87bc453349 | 445 | |
ninoderkinderen | 0:8d87bc453349 | 446 | if(m_closed) |
ninoderkinderen | 0:8d87bc453349 | 447 | { |
ninoderkinderen | 0:8d87bc453349 | 448 | DBG("WARN: Discarded\n"); |
ninoderkinderen | 0:8d87bc453349 | 449 | return; |
ninoderkinderen | 0:8d87bc453349 | 450 | } |
ninoderkinderen | 0:8d87bc453349 | 451 | |
ninoderkinderen | 0:8d87bc453349 | 452 | switch(e) |
ninoderkinderen | 0:8d87bc453349 | 453 | { |
ninoderkinderen | 0:8d87bc453349 | 454 | case TCPSOCKET_READABLE: //Incoming data |
ninoderkinderen | 0:8d87bc453349 | 455 | resetTimeout(); |
ninoderkinderen | 0:8d87bc453349 | 456 | if(m_state == MYSQL_HANDSHAKE) |
ninoderkinderen | 0:8d87bc453349 | 457 | handleHandshake(); |
ninoderkinderen | 0:8d87bc453349 | 458 | else if(m_state == MYSQL_AUTH) |
ninoderkinderen | 0:8d87bc453349 | 459 | handleAuthResult(); |
ninoderkinderen | 0:8d87bc453349 | 460 | else if(m_state == MYSQL_COMMANDS) |
ninoderkinderen | 0:8d87bc453349 | 461 | handleCommandResult(); |
ninoderkinderen | 0:8d87bc453349 | 462 | break; |
ninoderkinderen | 0:8d87bc453349 | 463 | case TCPSOCKET_WRITEABLE: //We can send data |
ninoderkinderen | 0:8d87bc453349 | 464 | resetTimeout(); |
ninoderkinderen | 0:8d87bc453349 | 465 | break; |
ninoderkinderen | 0:8d87bc453349 | 466 | case TCPSOCKET_CONNECTED: //Connected, wait for handshake packet |
ninoderkinderen | 0:8d87bc453349 | 467 | resetTimeout(); |
ninoderkinderen | 0:8d87bc453349 | 468 | break; |
ninoderkinderen | 0:8d87bc453349 | 469 | case TCPSOCKET_CONTIMEOUT: |
ninoderkinderen | 0:8d87bc453349 | 470 | case TCPSOCKET_CONRST: |
ninoderkinderen | 0:8d87bc453349 | 471 | case TCPSOCKET_CONABRT: |
ninoderkinderen | 0:8d87bc453349 | 472 | case TCPSOCKET_ERROR: |
ninoderkinderen | 0:8d87bc453349 | 473 | DBG("Connection error.\n"); |
ninoderkinderen | 0:8d87bc453349 | 474 | onResult(MYSQL_CONN); |
ninoderkinderen | 0:8d87bc453349 | 475 | case TCPSOCKET_DISCONNECTED: |
ninoderkinderen | 0:8d87bc453349 | 476 | //There might still be some data available for reading |
ninoderkinderen | 0:8d87bc453349 | 477 | //So if we are in a reading state, do not close the socket yet |
ninoderkinderen | 0:8d87bc453349 | 478 | if(m_state != MYSQL_CLOSED) |
ninoderkinderen | 0:8d87bc453349 | 479 | { |
ninoderkinderen | 0:8d87bc453349 | 480 | onResult(MYSQL_CONN); |
ninoderkinderen | 0:8d87bc453349 | 481 | } |
ninoderkinderen | 0:8d87bc453349 | 482 | DBG("Connection closed by remote host.\n"); |
ninoderkinderen | 0:8d87bc453349 | 483 | break; |
ninoderkinderen | 0:8d87bc453349 | 484 | } |
ninoderkinderen | 0:8d87bc453349 | 485 | } |
ninoderkinderen | 0:8d87bc453349 | 486 | |
ninoderkinderen | 0:8d87bc453349 | 487 | void MySQLClient::onDNSReply(DNSReply r) |
ninoderkinderen | 0:8d87bc453349 | 488 | { |
ninoderkinderen | 0:8d87bc453349 | 489 | if(m_closed) |
ninoderkinderen | 0:8d87bc453349 | 490 | { |
ninoderkinderen | 0:8d87bc453349 | 491 | DBG("WARN: Discarded\n"); |
ninoderkinderen | 0:8d87bc453349 | 492 | return; |
ninoderkinderen | 0:8d87bc453349 | 493 | } |
ninoderkinderen | 0:8d87bc453349 | 494 | |
ninoderkinderen | 0:8d87bc453349 | 495 | if( r != DNS_FOUND ) |
ninoderkinderen | 0:8d87bc453349 | 496 | { |
ninoderkinderen | 0:8d87bc453349 | 497 | DBG("Could not resolve hostname.\n"); |
ninoderkinderen | 0:8d87bc453349 | 498 | onResult(MYSQL_DNS); |
ninoderkinderen | 0:8d87bc453349 | 499 | return; |
ninoderkinderen | 0:8d87bc453349 | 500 | } |
ninoderkinderen | 0:8d87bc453349 | 501 | |
ninoderkinderen | 0:8d87bc453349 | 502 | DBG("DNS Resolved to %d.%d.%d.%d.\n",m_host.getIp()[0],m_host.getIp()[1],m_host.getIp()[2],m_host.getIp()[3]); |
ninoderkinderen | 0:8d87bc453349 | 503 | //If no error, m_host has been updated by m_pDnsReq so we're set to go ! |
ninoderkinderen | 0:8d87bc453349 | 504 | m_pDnsReq->close(); |
ninoderkinderen | 0:8d87bc453349 | 505 | delete m_pDnsReq; |
ninoderkinderen | 0:8d87bc453349 | 506 | m_pDnsReq = NULL; |
ninoderkinderen | 0:8d87bc453349 | 507 | connect(); |
ninoderkinderen | 0:8d87bc453349 | 508 | } |
ninoderkinderen | 0:8d87bc453349 | 509 | |
ninoderkinderen | 0:8d87bc453349 | 510 | void MySQLClient::onResult(MySQLResult r) //Called when exchange completed or on failure |
ninoderkinderen | 0:8d87bc453349 | 511 | { |
ninoderkinderen | 0:8d87bc453349 | 512 | if(m_pCbItem && m_pCbMeth) |
ninoderkinderen | 0:8d87bc453349 | 513 | (m_pCbItem->*m_pCbMeth)(r); |
ninoderkinderen | 0:8d87bc453349 | 514 | else if(m_pCb) |
ninoderkinderen | 0:8d87bc453349 | 515 | m_pCb(r); |
ninoderkinderen | 0:8d87bc453349 | 516 | |
ninoderkinderen | 0:8d87bc453349 | 517 | if( (r==MYSQL_DNS) || (r==MYSQL_PRTCL) || (r==MYSQL_AUTHFAILED) || (r==MYSQL_TIMEOUT) || (r==MYSQL_CONN) ) //Fatal error, close connection |
ninoderkinderen | 0:8d87bc453349 | 518 | close(); |
ninoderkinderen | 0:8d87bc453349 | 519 | } |
ninoderkinderen | 0:8d87bc453349 | 520 | |
ninoderkinderen | 0:8d87bc453349 | 521 | void MySQLClient::onTimeout() //Connection has timed out |
ninoderkinderen | 0:8d87bc453349 | 522 | { |
ninoderkinderen | 0:8d87bc453349 | 523 | DBG("Timed out.\n"); |
ninoderkinderen | 0:8d87bc453349 | 524 | onResult(MYSQL_TIMEOUT); |
ninoderkinderen | 0:8d87bc453349 | 525 | close(); |
ninoderkinderen | 0:8d87bc453349 | 526 | } |