This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UrlReader.cpp Source File

UrlReader.cpp

00001 #include "NyLPC_http.h"
00002 #include "NyLPC_stdlib.h"
00003 #include "mbed.h"
00004 #include "UrlReader.h"
00005 namespace MiMic
00006 {
00007     UrlReader::UrlReader(const char* i_ref_url)
00008     {
00009         this->_ref_str=i_ref_url;
00010     }
00011     bool UrlReader::getPath(const char* &path,int &l)
00012     {
00013         return NyLPC_cUrlReader_getPath(this->_ref_str,&path,(NyLPC_TInt32*)&l);
00014     }
00015     bool UrlReader::isPathEqual(const char* path)
00016     {
00017         const char* p;
00018         int l;
00019         if(!NyLPC_cUrlReader_getPath(this->_ref_str,&p,(NyLPC_TInt32*)&l)){
00020             return false;
00021         }
00022         return ((l==strlen(path)) && (strncmp(p,path,l)==0));
00023     }
00024     /**
00025      * @param i_ref_str
00026      *  URL text for read.
00027      *  This is referenced pointer. Must hold it until an instance is closed.
00028      */
00029     void UrlReader::setUrl(const char* i_ref_url)
00030     {
00031         this->_ref_str=i_ref_url;
00032     }
00033     //bool hasHost(const char* key);
00034     //bool getHost(const char* i_ref_url);
00035     //bool hasPath(const char* i_ref_url);
00036     //bool getPath(const char* i_ref_url);
00037     /**
00038      * This function confirms URL has a query key.
00039      * @param key
00040      * key name.
00041      */
00042     bool UrlReader::hasQueryKey(const char* key)
00043     {
00044         return NyLPC_cUrlReader_findKeyValue(this->_ref_str,key)!=NULL;
00045     }
00046     bool UrlReader::getQueryStr(const char* key,const char* &o_ref_val,int &o_val_len)
00047     {
00048         return NyLPC_cUrlReader_getStr(this->_ref_str,key,&o_ref_val,(NyLPC_TInt32*)&o_val_len)==NyLPC_TBool_TRUE;
00049     }
00050     bool UrlReader::getQueryUInt(const char* key,unsigned int &v)
00051     {
00052         return NyLPC_cUrlReader_getUInt(this->_ref_str,key,(NyLPC_TUInt32*)&v)==NyLPC_TBool_TRUE;
00053     }
00054     bool UrlReader::getQueryInt(const char* key,int &v)
00055     {
00056         return NyLPC_cUrlReader_getInt(this->_ref_str,key,(NyLPC_TInt32*)&v)==NyLPC_TBool_TRUE;
00057     }
00058     bool UrlReader::isQueryEqualStr(const char* key,const char* v)
00059     {
00060         const char* kv;
00061         NyLPC_TInt32 l;
00062         if(NyLPC_cUrlReader_getStr(this->_ref_str,key,&kv,&l)){
00063             return strncmp(v,kv,l)==0;
00064         }
00065         return false;
00066     }
00067     bool UrlReader::isQueryEqualUInt(const char* key,unsigned int v)
00068     {
00069         NyLPC_TUInt32 l;
00070         if(NyLPC_cUrlReader_getUInt(this->_ref_str,key,&l)){
00071             return l==v;
00072         }
00073         return false;
00074     }
00075     bool UrlReader::isQueryEqualInt(const char* key,int v)
00076     {
00077         NyLPC_TInt32 l;
00078         if(NyLPC_cUrlReader_getInt(this->_ref_str,key,&l)){
00079             return l==v;
00080         }
00081         return false;
00082     }
00083 
00084 }