Dependents: SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1
Revision 8:65b403c38e41, committed 2010-06-01
- Comitter:
- donatien
- Date:
- Tue Jun 01 12:55:46 2010 +0000
- Parent:
- 7:4f167b49d27c
- Child:
- 9:acb9b7d53771
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/netCfg.h Tue Jun 01 12:55:46 2010 +0000 @@ -0,0 +1,12 @@ +#ifndef NET_CFG_H +#define NET_TELIT_STACK 0 +#define NET_GPRS 0 +#define NET_PPP 0 +#define NET_ZG2100 0 +#define NET_ETH 0 +#define NET_USB_SERIAL 0 +#define NET_TELIT 0 +#define NET_CFG_H 1 +#define NET_USB 0 +#define NET_LWIP_STACK 0 +#endif
Binary file services.ar has changed
--- a/services/http/client/data/HttpMap.h Thu May 27 10:15:14 2010 +0000 +++ b/services/http/client/data/HttpMap.h Tue Jun 01 12:55:46 2010 +0000 @@ -35,7 +35,7 @@ class HttpMap : public HttpData, public Dictionary //Key/Value pairs { public: - HttpMap(); + HttpMap(const string& keyValueSep = "=", const string& pairSep = "&"); virtual ~HttpMap(); /* string& operator[](const string& key); @@ -63,6 +63,9 @@ string m_buf; int m_len; bool m_chunked; + + string m_keyValueSep; + string m_pairSep; }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/services/sql/MySQLClient.h Tue Jun 01 12:55:46 2010 +0000 @@ -0,0 +1,159 @@ + +/* +Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef MYSQL_CLIENT_H +#define MYSQL_CLIENT_H + +#include "if/net/net.h" +#include "api/TcpSocket.h" +#include "api/DnsRequest.h" +#include "mbed.h" + +#include <string> +using std::string; + +#include <map> +using std::map; + +#define MYSQL_TIMEOUT_MS 15000 +#define MYSQL_PORT 3306 + +typedef unsigned char byte; + +enum MySQLResult +{ + MYSQL_OK, + MYSQL_PROCESSING, + MYSQL_PRTCL, + MYSQL_SETUP, //Not properly configured + MYSQL_DNS, //Could not resolve name + MYSQL_AUTHFAILED, //Auth failure + MYSQL_READY, //Ready to send commands + MYSQL_SQL, //SQL Error + MYSQL_TIMEOUT, //Connection timeout + MYSQL_CONN //Connection error +}; + +class MySQLClient : protected NetService +{ +public: + MySQLClient(); + virtual ~MySQLClient(); + + //High Level setup functions + MySQLResult open(Host& host, const string& user, const string& password, const string& db, void (*pMethod)(MySQLResult)); //Non blocking + template<class T> + MySQLResult open(Host& host, const string& user, const string& password, const string& db, T* pItem, void (T::*pMethod)(MySQLResult)) //Non blocking + { + setOnResult(pItem, pMethod); + setup(host, user, password, db); + return MYSQL_PROCESSING; + } + + MySQLResult sql(string& sqlCommand); + + MySQLResult exit(); + + void setOnResult( void (*pMethod)(MySQLResult) ); + class CDummy; + template<class T> + void setOnResult( T* pItem, void (T::*pMethod)(MySQLResult) ) + { + m_pCb = NULL; + m_pCbItem = (CDummy*) pItem; + m_pCbMeth = (void (CDummy::*)(MySQLResult)) pMethod; + } + + void setTimeout(int ms); + + virtual void poll(); //Called by NetServices + +protected: + void resetTimeout(); + + void init(); + void close(); + + void setup(Host& host, const string& user, const string& password, const string& db); //Setup connection, make DNS Req if necessary + void connect(); //Start Connection + + void handleHandshake(); + void sendAuth(); + + void handleAuthResult(); + + void sendCommand(byte command, byte* arg, int len); + void handleCommandResult(); + + void readData(); //Copy to buf + void writeData(); //Copy from buf + + void onTcpSocketEvent(TcpSocketEvent e); + void onDnsReply(DnsReply r); + void onResult(MySQLResult r); //Called when exchange completed or on failure + void onTimeout(); //Connection has timed out + +private: + CDummy* m_pCbItem; + void (CDummy::*m_pCbMeth)(MySQLResult); + + void (*m_pCb)(MySQLResult); + + TcpSocket* m_pTcpSocket; + + Timer m_watchdog; + int m_timeout; + + DnsRequest* m_pDnsReq; + + bool m_closed; + + enum MySQLStep + { + // MYSQL_INIT, + MYSQL_HANDSHAKE, + MYSQL_AUTH, + MYSQL_COMMANDS, + MYSQL_CLOSED + }; + + //Parameters + Host m_host; + + string m_user; + string m_password; + string m_db; + + //Low-level buffers & state-machine + MySQLStep m_state; + + byte* m_buf; + byte* m_pPos; + int m_len; + int m_size; + + int m_packetId; + +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/services/sql/sha1.h Tue Jun 01 12:55:46 2010 +0000 @@ -0,0 +1,145 @@ +/** + * \file sha1.h + * + * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef POLARSSL_SHA1_H +#define POLARSSL_SHA1_H + +/** + * \brief SHA-1 context structure + */ +typedef struct +{ + unsigned long total[2]; /*!< number of bytes processed */ + unsigned long state[5]; /*!< intermediate digest state */ + unsigned char buffer[64]; /*!< data block being processed */ + + unsigned char ipad[64]; /*!< HMAC: inner padding */ + unsigned char opad[64]; /*!< HMAC: outer padding */ +} +sha1_context; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief SHA-1 context setup + * + * \param ctx context to be initialized + */ +void sha1_starts( sha1_context *ctx ); + +/** + * \brief SHA-1 process buffer + * + * \param ctx SHA-1 context + * \param input buffer holding the data + * \param ilen length of the input data + */ +void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ); + +/** + * \brief SHA-1 final digest + * + * \param ctx SHA-1 context + * \param output SHA-1 checksum result + */ +void sha1_finish( sha1_context *ctx, unsigned char output[20] ); + +/** + * \brief Output = SHA-1( input buffer ) + * + * \param input buffer holding the data + * \param ilen length of the input data + * \param output SHA-1 checksum result + */ +void sha1( const unsigned char *input, int ilen, unsigned char output[20] ); + +#if 0 //No need for that +/** + * \brief Output = SHA-1( file contents ) + * + * \param path input file name + * \param output SHA-1 checksum result + * + * \return 0 if successful, 1 if fopen failed, + * or 2 if fread failed + */ +int sha1_file( const char *path, unsigned char output[20] ); +#endif + +/** + * \brief SHA-1 HMAC context setup + * + * \param ctx HMAC context to be initialized + * \param key HMAC secret key + * \param keylen length of the HMAC key + */ +void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen ); + +/** + * \brief SHA-1 HMAC process buffer + * + * \param ctx HMAC context + * \param input buffer holding the data + * \param ilen length of the input data + */ +void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen ); + +/** + * \brief SHA-1 HMAC final digest + * + * \param ctx HMAC context + * \param output SHA-1 HMAC checksum result + */ +void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] ); + +/** + * \brief SHA-1 HMAC context reset + * + * \param ctx HMAC context to be reset + */ +void sha1_hmac_reset( sha1_context *ctx ); + +/** + * \brief Output = HMAC-SHA-1( hmac key, input buffer ) + * + * \param key HMAC secret key + * \param keylen length of the HMAC key + * \param input buffer holding the data + * \param ilen length of the input data + * \param output HMAC-SHA-1 result + */ +void sha1_hmac( const unsigned char *key, int keylen, + const unsigned char *input, int ilen, + unsigned char output[20] ); + +/** + * \brief Checkup routine + * + * \return 0 if successful, or 1 if the test failed + */ +int sha1_self_test( int verbose ); + +#ifdef __cplusplus +} +#endif + +#endif /* sha1.h */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/services/sql/sha1config.h Tue Jun 01 12:55:46 2010 +0000 @@ -0,0 +1,6 @@ +#ifndef SHA1CONFIG_H +#define SHA1CONFIG_H + +#define POLARSSL_SHA1_C 1 + +#endif