Handler et parseur simple pour un fichier XML pour le projet télécommande par iPhone ou iPod, remplace un tag par la valeur de la variable entière. Très perfectible.

Committer:
jfpautex
Date:
Fri Oct 29 21:48:27 2010 +0000
Revision:
0:2b2fce21fd82
versin #1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jfpautex 0:2b2fce21fd82 1
jfpautex 0:2b2fce21fd82 2 /*
jfpautex 0:2b2fce21fd82 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
jfpautex 0:2b2fce21fd82 4
jfpautex 0:2b2fce21fd82 5 Permission is hereby granted, free of charge, to any person obtaining a copy
jfpautex 0:2b2fce21fd82 6 of this software and associated documentation files (the "Software"), to deal
jfpautex 0:2b2fce21fd82 7 in the Software without restriction, including without limitation the rights
jfpautex 0:2b2fce21fd82 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jfpautex 0:2b2fce21fd82 9 copies of the Software, and to permit persons to whom the Software is
jfpautex 0:2b2fce21fd82 10 furnished to do so, subject to the following conditions:
jfpautex 0:2b2fce21fd82 11
jfpautex 0:2b2fce21fd82 12 The above copyright notice and this permission notice shall be included in
jfpautex 0:2b2fce21fd82 13 all copies or substantial portions of the Software.
jfpautex 0:2b2fce21fd82 14
jfpautex 0:2b2fce21fd82 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jfpautex 0:2b2fce21fd82 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jfpautex 0:2b2fce21fd82 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jfpautex 0:2b2fce21fd82 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jfpautex 0:2b2fce21fd82 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jfpautex 0:2b2fce21fd82 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jfpautex 0:2b2fce21fd82 21 THE SOFTWARE.
jfpautex 0:2b2fce21fd82 22 */
jfpautex 0:2b2fce21fd82 23
jfpautex 0:2b2fce21fd82 24 #ifndef FSW_HANDLER_H
jfpautex 0:2b2fce21fd82 25 #define FSW_HANDLER_H
jfpautex 0:2b2fce21fd82 26
jfpautex 0:2b2fce21fd82 27 #include "../HTTPRequestHandler.h"
jfpautex 0:2b2fce21fd82 28 #include "mbed.h"
jfpautex 0:2b2fce21fd82 29
jfpautex 0:2b2fce21fd82 30 #include <map>
jfpautex 0:2b2fce21fd82 31 using std::map;
jfpautex 0:2b2fce21fd82 32
jfpautex 0:2b2fce21fd82 33 #include <string>
jfpautex 0:2b2fce21fd82 34 using std::string;
jfpautex 0:2b2fce21fd82 35
jfpautex 0:2b2fce21fd82 36 class FSWagoHandler : public HTTPRequestHandler
jfpautex 0:2b2fce21fd82 37 {
jfpautex 0:2b2fce21fd82 38 public:
jfpautex 0:2b2fce21fd82 39 FSWagoHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
jfpautex 0:2b2fce21fd82 40 virtual ~FSWagoHandler();
jfpautex 0:2b2fce21fd82 41
jfpautex 0:2b2fce21fd82 42 static void mount(const string& fsPath, const string& rootPath);
jfpautex 0:2b2fce21fd82 43
jfpautex 0:2b2fce21fd82 44 //protected:
jfpautex 0:2b2fce21fd82 45 static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new FSWagoHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one
jfpautex 0:2b2fce21fd82 46
jfpautex 0:2b2fce21fd82 47 virtual void doGet();
jfpautex 0:2b2fce21fd82 48 virtual void doPost();
jfpautex 0:2b2fce21fd82 49 virtual void doHead();
jfpautex 0:2b2fce21fd82 50
jfpautex 0:2b2fce21fd82 51 virtual void onReadable(); //Data has been read
jfpautex 0:2b2fce21fd82 52 virtual void onWriteable(); //Data has been written & buf is free
jfpautex 0:2b2fce21fd82 53 virtual void onClose(); //Connection is closing
jfpautex 0:2b2fce21fd82 54
jfpautex 0:2b2fce21fd82 55 private:
jfpautex 0:2b2fce21fd82 56 FILE* m_fp;
jfpautex 0:2b2fce21fd82 57 bool m_err404;
jfpautex 0:2b2fce21fd82 58 static map<string,string> m_lFsPath;
jfpautex 0:2b2fce21fd82 59
jfpautex 0:2b2fce21fd82 60 // ajout decodeur
jfpautex 0:2b2fce21fd82 61 int decode(char* rBuf, int len);
jfpautex 0:2b2fce21fd82 62 int indexOfChar(char* rBuf, int len, char x);
jfpautex 0:2b2fce21fd82 63 int remplaceCharAtIndex(char* rBuf, int len, int index, char x);
jfpautex 0:2b2fce21fd82 64 int insertCharsAtIndex(char* rBuf, int len, int index, char* x, int lenx);
jfpautex 0:2b2fce21fd82 65 };
jfpautex 0:2b2fce21fd82 66
jfpautex 0:2b2fce21fd82 67 #endif