This library is stripped down version of NetServices library. HTTP server and client function is NOT supported.

Dependents:   imu-daq-eth

Committer:
idinor
Date:
Wed Jul 20 11:45:39 2011 +0000
Revision:
0:dcf3c92487ca

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
idinor 0:dcf3c92487ca 1
idinor 0:dcf3c92487ca 2 /*
idinor 0:dcf3c92487ca 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
idinor 0:dcf3c92487ca 4
idinor 0:dcf3c92487ca 5 Permission is hereby granted, free of charge, to any person obtaining a copy
idinor 0:dcf3c92487ca 6 of this software and associated documentation files (the "Software"), to deal
idinor 0:dcf3c92487ca 7 in the Software without restriction, including without limitation the rights
idinor 0:dcf3c92487ca 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
idinor 0:dcf3c92487ca 9 copies of the Software, and to permit persons to whom the Software is
idinor 0:dcf3c92487ca 10 furnished to do so, subject to the following conditions:
idinor 0:dcf3c92487ca 11
idinor 0:dcf3c92487ca 12 The above copyright notice and this permission notice shall be included in
idinor 0:dcf3c92487ca 13 all copies or substantial portions of the Software.
idinor 0:dcf3c92487ca 14
idinor 0:dcf3c92487ca 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
idinor 0:dcf3c92487ca 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
idinor 0:dcf3c92487ca 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
idinor 0:dcf3c92487ca 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
idinor 0:dcf3c92487ca 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
idinor 0:dcf3c92487ca 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
idinor 0:dcf3c92487ca 21 THE SOFTWARE.
idinor 0:dcf3c92487ca 22 */
idinor 0:dcf3c92487ca 23
idinor 0:dcf3c92487ca 24 /** \file
idinor 0:dcf3c92487ca 25 DNS Request header file
idinor 0:dcf3c92487ca 26 */
idinor 0:dcf3c92487ca 27
idinor 0:dcf3c92487ca 28 #ifndef DNSREQUEST_H
idinor 0:dcf3c92487ca 29 #define DNSREQUEST_H
idinor 0:dcf3c92487ca 30
idinor 0:dcf3c92487ca 31 #include "core/net.h"
idinor 0:dcf3c92487ca 32 #include "core/ipaddr.h"
idinor 0:dcf3c92487ca 33 #include "core/host.h"
idinor 0:dcf3c92487ca 34 //Essentially it is a safe interface to NetDnsRequest
idinor 0:dcf3c92487ca 35
idinor 0:dcf3c92487ca 36 ///DNS Request error codes
idinor 0:dcf3c92487ca 37 enum DNSRequestErr
idinor 0:dcf3c92487ca 38 {
idinor 0:dcf3c92487ca 39 __DNS_MIN = -0xFFFF,
idinor 0:dcf3c92487ca 40 DNS_SETUP, ///<DNSRequest not properly configured
idinor 0:dcf3c92487ca 41 DNS_IF, ///<Interface has problems, does not exist or is not initialized
idinor 0:dcf3c92487ca 42 DNS_MEM, ///<Not enough mem
idinor 0:dcf3c92487ca 43 DNS_INUSE, ///<Interface / Port is in use
idinor 0:dcf3c92487ca 44 DNS_PROCESSING, ///<Request has not completed
idinor 0:dcf3c92487ca 45 //...
idinor 0:dcf3c92487ca 46 DNS_OK = 0 ///<Success
idinor 0:dcf3c92487ca 47 };
idinor 0:dcf3c92487ca 48
idinor 0:dcf3c92487ca 49 ///DNS Request Result Events
idinor 0:dcf3c92487ca 50 enum DNSReply
idinor 0:dcf3c92487ca 51 {
idinor 0:dcf3c92487ca 52 DNS_PRTCL,
idinor 0:dcf3c92487ca 53 DNS_NOTFOUND, ///Hostname is unknown
idinor 0:dcf3c92487ca 54 DNS_ERROR, ///Problem with DNS Service
idinor 0:dcf3c92487ca 55 //...
idinor 0:dcf3c92487ca 56 DNS_FOUND,
idinor 0:dcf3c92487ca 57 };
idinor 0:dcf3c92487ca 58
idinor 0:dcf3c92487ca 59 class NetDnsRequest;
idinor 0:dcf3c92487ca 60 enum NetDnsReply;
idinor 0:dcf3c92487ca 61
idinor 0:dcf3c92487ca 62 ///This is a simple DNS Request class
idinor 0:dcf3c92487ca 63 /**
idinor 0:dcf3c92487ca 64 This class exposes an API to deal with DNS Requests
idinor 0:dcf3c92487ca 65 */
idinor 0:dcf3c92487ca 66 class DNSRequest
idinor 0:dcf3c92487ca 67 {
idinor 0:dcf3c92487ca 68 public:
idinor 0:dcf3c92487ca 69 ///Creates a new request
idinor 0:dcf3c92487ca 70 DNSRequest();
idinor 0:dcf3c92487ca 71
idinor 0:dcf3c92487ca 72 ///Terminates and closes request
idinor 0:dcf3c92487ca 73 ~DNSRequest();
idinor 0:dcf3c92487ca 74
idinor 0:dcf3c92487ca 75 ///Resolves an hostname
idinor 0:dcf3c92487ca 76 /**
idinor 0:dcf3c92487ca 77 @param hostname : hostname to resolve
idinor 0:dcf3c92487ca 78 */
idinor 0:dcf3c92487ca 79 DNSRequestErr resolve(const char* hostname);
idinor 0:dcf3c92487ca 80
idinor 0:dcf3c92487ca 81 ///Resolves an hostname
idinor 0:dcf3c92487ca 82 /**
idinor 0:dcf3c92487ca 83 @param host : hostname to resolve, the result will be stored in the IpAddr field of this object
idinor 0:dcf3c92487ca 84 */
idinor 0:dcf3c92487ca 85 DNSRequestErr resolve(Host* pHost);
idinor 0:dcf3c92487ca 86
idinor 0:dcf3c92487ca 87 ///Setups callback
idinor 0:dcf3c92487ca 88 /**
idinor 0:dcf3c92487ca 89 The callback function will be called on result.
idinor 0:dcf3c92487ca 90 @param pMethod : callback function
idinor 0:dcf3c92487ca 91 */
idinor 0:dcf3c92487ca 92 void setOnReply( void (*pMethod)(DNSReply) );
idinor 0:dcf3c92487ca 93
idinor 0:dcf3c92487ca 94 class CDummy;
idinor 0:dcf3c92487ca 95 ///Setups callback
idinor 0:dcf3c92487ca 96 /**
idinor 0:dcf3c92487ca 97 The callback function will be called on result.
idinor 0:dcf3c92487ca 98 @param pItem : instance of class on which to execute the callback method
idinor 0:dcf3c92487ca 99 @param pMethod : callback method
idinor 0:dcf3c92487ca 100 */
idinor 0:dcf3c92487ca 101 template<class T>
idinor 0:dcf3c92487ca 102 void setOnReply( T* pItem, void (T::*pMethod)(DNSReply) )
idinor 0:dcf3c92487ca 103 {
idinor 0:dcf3c92487ca 104 m_pCbItem = (CDummy*) pItem;
idinor 0:dcf3c92487ca 105 m_pCbMeth = (void (CDummy::*)(DNSReply)) pMethod;
idinor 0:dcf3c92487ca 106 }
idinor 0:dcf3c92487ca 107
idinor 0:dcf3c92487ca 108 ///Gets IP address once it has been resolved
idinor 0:dcf3c92487ca 109 /**
idinor 0:dcf3c92487ca 110 @param pIp : pointer to an IpAddr instance in which to store the resolved IP address
idinor 0:dcf3c92487ca 111 */
idinor 0:dcf3c92487ca 112 DNSRequestErr getResult(IpAddr* pIp);
idinor 0:dcf3c92487ca 113
idinor 0:dcf3c92487ca 114 ///Closes DNS Request before completion
idinor 0:dcf3c92487ca 115 DNSRequestErr close();
idinor 0:dcf3c92487ca 116
idinor 0:dcf3c92487ca 117 protected:
idinor 0:dcf3c92487ca 118 void onNetDnsReply(NetDnsReply r);
idinor 0:dcf3c92487ca 119 DNSRequestErr checkInst();
idinor 0:dcf3c92487ca 120
idinor 0:dcf3c92487ca 121 private:
idinor 0:dcf3c92487ca 122 NetDnsRequest* m_pNetDnsRequest;
idinor 0:dcf3c92487ca 123
idinor 0:dcf3c92487ca 124 CDummy* m_pCbItem;
idinor 0:dcf3c92487ca 125 void (CDummy::*m_pCbMeth)(DNSReply);
idinor 0:dcf3c92487ca 126
idinor 0:dcf3c92487ca 127 void (*m_pCb)(DNSReply);
idinor 0:dcf3c92487ca 128
idinor 0:dcf3c92487ca 129 };
idinor 0:dcf3c92487ca 130
idinor 0:dcf3c92487ca 131 #endif