Fixed custom headers and Basic authorization, added support for redirection, functional file download interface can be used for SW updates and more.
Dependents: Sample_HTTPClient Sample_HTTPClient LWM2M_NanoService_Ethernet LWM2M_NanoService_Ethernet ... more
Fork of HTTPClient by
More recent changes - added iCal processing.
Derivative of a derivative, however this one works when it comes to supplying Basic authorization to access a protected resource. Some additional changes to the debug interface to clean it up for consistency with many other components I have.
Revision 40:bcb19f8dbba3, committed 2017-03-14
- Comitter:
- WiredHome
- Date:
- Tue Mar 14 02:59:32 2017 +0000
- Parent:
- 39:21fc7a4b6927
- Child:
- 41:37e7df011c1f
- Commit message:
- Revisions to clean up the iCal interface.
Changed in this revision
data/HTTPiCal.cpp | Show annotated file Show diff for this revision Revisions of this file |
data/HTTPiCal.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/data/HTTPiCal.cpp Fri Mar 10 02:53:09 2017 +0000 +++ b/data/HTTPiCal.cpp Tue Mar 14 02:59:32 2017 +0000 @@ -1,6 +1,6 @@ #include "HTTPiCal.h" -#define DEBUG "iCal" +//#define DEBUG "iCal" #include <cstdio> #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) #define DBG(x, ...) std::printf("[DBG %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); @@ -47,6 +47,7 @@ void HTTPiCal::writeReset() { //INFO("writeReset()"); EventCount = 0; + seeking = idle; lineBuf[0] = '\0'; } @@ -57,13 +58,14 @@ pEOL = strchr(pStart, '\n'); //INFO("\r\n\r\nwrite[%d:%d] = \r\n%s\r\nend-write\r\n", len, pEOL - pStart, buf); + //printf("lineBuf:[%d] %s\r\n", len, buf); while (pEOL && (pEOL - pStart) < len) { int lbLen = strlen(lineBuf); strncpy(lineBuf + lbLen, pStart, (pEOL - pStart)); lineBuf[lbLen + (pEOL - pStart) + 1] = '\0'; if (lineBuf[pEOL - pStart + lbLen - 1] == '\r') lineBuf[pEOL - pStart + lbLen - 1] = '\0'; - //INFO("lineBuf:[%s]", lineBuf); + //printf("lineBuf:[%s]\r\n", lineBuf); ParseICalStream(lineBuf, gridStartTime, gridEndTime, -300); //INFO(""); lineBuf[0] = '\0'; @@ -107,10 +109,6 @@ const char * RPT_DAYS[] = { "SU", "MO", "TU", "WE", "TH", "FR", "SA", "" }; -int HTTPiCal::GetNumEvents(void) -{ - return EventCount; -} const char * HTTPiCal::RepeatDayAbbrev(int i) { @@ -598,19 +596,6 @@ return tzo; } -void HTTPiCal::ParseICalStart(void) { - tzAdjusted = false; - seeking = idle; - EventCount = 0; - -} - -int HTTPiCal::ParseICalClose(void) { - if (EventCount > 0) - SortEvents(); - return GetNumEvents(); -} - int HTTPiCal::ParseICalStream(const char * pStart, time_t gridStartTime, time_t gridEndTime, tz_min_t tzoMin, bool showEvents) { INFO("Parse(%s)", pStart); @@ -667,8 +652,10 @@ EventList[EventCount].End += (60 * tzoMin); } // Process it - if (showEvents) + if (showEvents) { + //printf("ev: %d\r\n", EventCount); ShowEventInfo(EventList[EventCount]); + } // Force to ALWAYS time_t aStart = EventList[EventCount].Start; time_t aEnd = EventList[EventCount].End;
--- a/data/HTTPiCal.h Fri Mar 10 02:53:09 2017 +0000 +++ b/data/HTTPiCal.h Tue Mar 14 02:59:32 2017 +0000 @@ -103,7 +103,45 @@ /// @returns true if the event was available and copied. /// bool GetEvent(unsigned int i, Event_T * event); + + + /// Compute the intersection of two time ranges, and evaluate the recurringing events. + /// + /// This compares a pair of time ranges, each by a start and end time. If they overlap + /// it then computes the intersection of those two ranges. Additionally, for a + /// specified Event, it will evaluate the recurring events that may also fall into + /// the target time range. + /// + /// @note This is usually the only API you need, as this will first call + /// the TimeIntersects function, and if that fails, then it will evaluate + /// repeat information. + /// + /// @param[in,out] start1 is the starting time of range 1. + /// @param[in,out] end1 is the ending time of range 1. + /// @param[in] start2 is the starting time of range 2. + /// @param[in] end2 is the ending time of range 2. + /// @param[in] Event is a pointer to the event of interest that may have recurring series. + /// @returns true if the ranges overlap, and then start1 and end1 are set to the + /// intersection. + /// + bool RepeatIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2, Event_T * Event = NULL); + + /// Compute the intersection of two time ranges, and returns that intersection. + /// + /// This compares a pair of time ranges, each by a start and end time. If they overlap + /// it then computes the intersection of those two ranges. + /// + /// @param[in,out] start1 is the starting time of range 1. + /// @param[in,out] end1 is the ending time of range 1. + /// @param[in] start2 is the starting time of range 2. + /// @param[in] end2 is the ending time of range 2. + /// @returns true if the ranges overlap, and then start1 and end1 are set to the + /// intersection. + /// + bool TimeIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2); + + protected: friend class HTTPClient; @@ -157,9 +195,11 @@ } seekstate_t; seekstate_t seeking; + #if !defined(min) && !defined(max) #define min(a,b) (((a)<(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b)) - + #endif + /// Determine if a specific timestamp is in a leap year /// /// @param[in] t is the timestamp to evaluate @@ -232,12 +272,6 @@ int ParseICalStream(const char * pStart, time_t gridStartTime, time_t gridEndTime, tz_min_t tzoMin, bool showEvents = true); - /// Get the number of events that have been cached. - /// - /// @returns the number of events. - /// - int GetNumEvents(void); - /// Compute if the referenced event occurs within the specified time window. /// /// @param[in] startWindow is the starting timestamp. @@ -245,45 +279,9 @@ /// @param[in] Event is a pointer to the event, which can have repeat rules. /// @returns true if the event laps into the current time window. /// - bool EventIntersects(time_t startWindow, time_t endWindow, Event_T * Event); - - /// Compute the intersection of two time ranges, and evaluate the recurringing events. - /// - /// This compares a pair of time ranges, each by a start and end time. If they overlap - /// it then computes the intersection of those two ranges. Additionally, for a - /// specified Event, it will evaluate the recurring events that may also fall into - /// the target time range. - /// - /// @note This is usually the only API you need, as this will first call - /// the TimeIntersects function, and if that fails, then it will evaluate - /// repeat information. - /// - /// @param[in,out] start1 is the starting time of range 1. - /// @param[in,out] end1 is the ending time of range 1. - /// @param[in] start2 is the starting time of range 2. - /// @param[in] end2 is the ending time of range 2. - /// @param[in] Event is a pointer to the event of interest that may have recurring series. - /// @returns true if the ranges overlap, and then start1 and end1 are set to the - /// intersection. - /// - bool RepeatIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2, Event_T * Event = NULL); - - - /// Compute the intersection of two time ranges, and returns that intersection. - /// - /// This compares a pair of time ranges, each by a start and end time. If they overlap - /// it then computes the intersection of those two ranges. - /// - /// @param[in,out] start1 is the starting time of range 1. - /// @param[in,out] end1 is the ending time of range 1. - /// @param[in] start2 is the starting time of range 2. - /// @param[in] end2 is the ending time of range 2. - /// @returns true if the ranges overlap, and then start1 and end1 are set to the - /// intersection. - /// - bool TimeIntersects(time_t * start1, time_t * end1, time_t * start2, time_t * end2); - - +// bool EventIntersects(time_t startWindow, time_t endWindow, Event_T * Event); + + // Private Functions - no real value external to the iCal public interface // other than for test code.