David Fletcher / Mbed 2 deprecated CC3000WebServer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HttpString.h Source File

HttpString.h

00001 /*****************************************************************************
00002 *
00003 *  HTTPString.h
00004 *  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
00005 *
00006 *  Redistribution and use in source and binary forms, with or without
00007 *  modification, are permitted provided that the following conditions
00008 *  are met:
00009 *
00010 *    Redistributions of source code must retain the above copyright
00011 *    notice, this list of conditions and the following disclaimer.
00012 *
00013 *    Redistributions in binary form must reproduce the above copyright
00014 *    notice, this list of conditions and the following disclaimer in the
00015 *    documentation and/or other materials provided with the   
00016 *    distribution.
00017 *
00018 *    Neither the name of Texas Instruments Incorporated nor the names of
00019 *    its contributors may be used to endorse or promote products derived
00020 *    from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00026 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00027 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 *
00034 *****************************************************************************/
00035 #ifndef _HTTP_STRING_H_
00036 #define _HTTP_STRING_H_
00037 
00038 /** 
00039  * @defgroup HttpString String routines helper module
00040  * This module implements some string and buffer-related helper routines
00041  *
00042  * @{
00043  */
00044 
00045 #include "Common.h"
00046 
00047 /**
00048  * A structure to hold a string or buffer which is not null-terminated
00049  */
00050 //#ifdef __CCS__
00051 //struct __attribute__ ((__packed__)) HttpBlob
00052 //#elif __IAR_SYSTEMS_ICC__
00053 //#pragma pack(1)
00054 struct HttpBlob
00055 //#endif
00056 {
00057     uint16 uLength;
00058     uint8* pData;
00059 };
00060 
00061 /**
00062  * Utility macro which sets an existing blob 
00063  */
00064 #define HttpBlobSetConst(blob, constString) \
00065     {   \
00066         (blob).pData = (uint8*)constString; \
00067         (blob).uLength = sizeof(constString) - 1; \
00068     }
00069 
00070 /**
00071  * Perform string comparison between two strings.
00072  * @param first Pointer to data about the first blob or string
00073  * @param second Pointer to data about the second blob or string
00074  * @return zero if equal, positive if first is later in order, negative if second is later in order
00075  */
00076 int HttpString_strcmp(struct HttpBlob first, struct HttpBlob second);
00077 
00078 /**
00079  * return pointer to the next token
00080  * @param token Pointer to data of the first token
00081  * @param blob Pointer to data of the search string/blob
00082  * @return pointer if found, otherwize NULL
00083  */
00084 uint8* HttpString_nextToken(char* pToken, uint16 uTokenLength, struct HttpBlob blob);
00085 
00086 /**
00087  * Parse a string representation of an unsigned decimal number
00088  * Stops at any non-digit character.
00089  * @param string The string to parse
00090  * @return The parsed value
00091  */
00092 uint32 HttpString_atou(struct HttpBlob string);
00093 
00094 /**
00095  * Format an unsigned decimal number as a string
00096  * @param uNum The number to format
00097  * @param[in,out] pString A string buffer which returns the formatted string. On entry, uLength is the maximum length of the buffer, upon return uLength is the actual length of the formatted string
00098  */
00099 void HttpString_utoa(uint32 uNum, struct HttpBlob* pString);
00100 
00101 /**
00102  * Format an unsigned decimal number as an hexdecimal string
00103  * @param uNum The number to format
00104  * @param bPadZero nonzero to pad with zeros up to the string length, or zero to use minimal length required to represent the number
00105  * @param[in,out] pString A string buffer which returns the formatted string. On entry, uLength is the maximum length of the buffer, upon return uLength is the actual length of the formatted string
00106  */
00107 void HttpString_htoa(uint32 uNum, struct HttpBlob* pString, uint8 bPadZero);
00108 
00109 /// @}
00110 
00111 #endif // _HTTP_STRING_H_
00112