forked from basvk/PIC-Websockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.h
1799 lines (1374 loc) · 57.3 KB
/
http.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
HTTP Headers for Microchip TCP/IP Stack
Company:
Microchip Technology Inc.
File Name:
http.h
Summary:
The HTTP web server module together with a file system (SYS_FS) allow
the board to act as a web server.
Description:
The HTTP module runs a web server within the TCP/IP stack.
This facilitates an easy method to view status information
and control applications using any standard web browser.
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright 2012-2015 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*******************************************************************************/
//DOM-IGNORE-END
#ifndef __HTTP_H_
#define __HTTP_H_
#include "system/fs/sys_fs.h"
// DOM-IGNORE-BEGIN
#ifdef __cplusplus // Provide C++ Compatibility
extern "C" {
#endif
// DOM-IGNORE-END
// *****************************************************************************
// *****************************************************************************
// Section: Commands and Server Responses
// *****************************************************************************
// *****************************************************************************
//******************************************************************************
//Supported Commands and Server Response Codes
typedef enum
{
HTTP_GET = 0u, // GET command is being processed
#if defined(TCPIP_HTTP_USE_WEBSOCKETS)
HTTP_WEBSOCKET_FRAME, // Websockets
#endif
HTTP_POST, // POST command is being processed
HTTP_BAD_REQUEST, // 400 Bad Request will be returned
HTTP_UNAUTHORIZED, // 401 Unauthorized will be returned
HTTP_NOT_FOUND, // 404 Not Found will be returned
HTTP_OVERFLOW, // 414 Request-URI Too Long will be returned
HTTP_INTERNAL_SERVER_ERROR, // 500 Internal Server Error will be returned
HTTP_NOT_IMPLEMENTED, // 501 Not Implemented (not a GET or POST command)
HTTP_REDIRECT, // 302 Redirect will be returned
HTTP_SSL_REQUIRED, // 403 Forbidden is returned, indicating SSL is required
HTTP_MPFS_FORM, // Show the MPFS Upload form
HTTP_MPFS_UP, // An MPFS Upload is being processed
HTTP_MPFS_OK, // An MPFS Upload was successful
HTTP_MPFS_WAIT, // An MPFS Upload waiting for the write operation to complete
HTTP_OTA_WAIT_WRITE_COMPLETE, //Waiting for OTA write commands issued to IPF driver
HTTP_OTA_WAIT_LAST_WRITE, //Waiting for last OTA write commands issued to IPF driver
HTTP_OTA_FINAL, //Last OTA write commands issued to IPF driver
HTTP_MPFS_ERROR, // An MPFS Upload was not a valid image
} HTTP_STATUS;
// *****************************************************************************
// *****************************************************************************
// Section: HTTP Definitions
// *****************************************************************************
// *****************************************************************************
//******************************************************************************
// Result states for execution callbacks
typedef enum
{
HTTP_IO_DONE = 0u, // Finished with procedure
HTTP_IO_NEED_DATA, // More data needed to continue, call again later
HTTP_IO_WAITING // Waiting for asynchronous process to complete, call again later
} HTTP_IO_RESULT;
// Result states for TCPIP_HTTP_PostNameRead, TCPIP_HTTP_PostValueRead and TCPIP_HTTP_PostReadPair
typedef enum
{
HTTP_READ_OK = 0u, // Read was successful
HTTP_READ_TRUNCATED, // Buffer overflow prevented by truncating value
HTTP_READ_INCOMPLETE // Entire object is not yet in the buffer. Try again later.
} HTTP_READ_STATUS;
// File type definitions
typedef enum
{
HTTP_TXT = 0u, // File is a text document
HTTP_HTM, // File is HTML (extension .htm)
HTTP_HTML, // File is HTML (extension .html)
HTTP_CGI, // File is HTML (extension .cgi)
HTTP_XML, // File is XML (extension .xml)
HTTP_CSS, // File is stylesheet (extension .css)
HTTP_GIF, // File is GIF image (extension .gif)
HTTP_PNG, // File is PNG image (extension .png)
HTTP_JPG, // File is JPG image (extension .jpg)
HTTP_JS, // File is java script (extension .js)
HTTP_JAVA, // File is java (extension .class)
HTTP_WAV, // File is audio (extension .wav)
HTTP_SVG, // File is SVG (extension .svg))
HTTP_UNKNOWN // File type is unknown
} HTTP_FILE_TYPE;
// HTTP connection identifier, handle of a HTTP connection
typedef const void* HTTP_CONN_HANDLE;
// HTTP module configuration flags
// Multiple flags can be OR-ed
typedef enum
{
HTTP_MODULE_FLAG_DEFAULT = 0x00, // Default flags value
HTTP_MODULE_FLAG_ADJUST_SKT_FIFOS = 0x01, // Adjust corresponding socket FIFO at run time.
// Improves throughput when the socket buffers are small.
HTTP_MODULE_FLAG_NO_DELAY = 0x02, // Create the HTTP sockets with NO-DELAY option.
// It will flush data as soon as possible.
}HTTP_MODULE_FLAGS;
// HTTP module dynamic configuration data
typedef struct
{
uint16_t nConnections; // number of simultaneous HTTP connections allowed
uint16_t nTlsConnections; // Not used in the current implementation;
// Number of simultaneous HTTPS connections allowed
uint16_t dataLen; // size of the data buffer for reading cookie and GET/POST arguments (bytes)
uint16_t sktTxBuffSize; // size of TX buffer for the associated socket; leave 0 for default
uint16_t sktRxBuffSize; // size of RX buffer for the associated socket; leave 0 for default
uint16_t tlsSktTxBuffSize; // Not used in the current implementation;
// Size of TLS TX buffer for the associated socket; leave 0 for default (min 512 bytes)
uint16_t tlsSktRxBuffSize; // Not used in the current implementation;
// Size of TLS RX buffer for the associated socket; leave 0 for default (min 512 bytes)
uint16_t configFlags; // a HTTP_MODULE_FLAGS value.
} TCPIP_HTTP_MODULE_CONFIG;
// *****************************************************************************
// *****************************************************************************
// Section: Function Prototypes
// *****************************************************************************
// *****************************************************************************
//*****************************************************************************
/*
Function:
uint8_t* TCPIP_HTTP_URLDecode(uint8_t* cData)
Summary:
Parses a string from URL encoding to plain-text.
Description:
This function parses a string from URL encoding to plain-text. The following
conversions are made: = to \0, & to \0, + to , and
%xx to a single hex byte.
After completion, the data has been decoded and a null terminator
signifies the end of a name or value. A second null terminator (or a
null name parameter) indicates the end of all the data.
Precondition:
The data parameter is null terminated and has at least one extra
byte free.
Parameters:
cData - The string which is to be decoded in place.
Returns:
A pointer to the last null terminator in data, which is also the
first free byte for new data.
Remarks:
This function is called by the stack to parse GET arguments and
cookie data. User applications can use this function to decode POST
data, but first need to verify that the string is null-terminated.
*/
uint8_t* TCPIP_HTTP_URLDecode(uint8_t* cData);
//*****************************************************************************
/*
Function:
const uint8_t* TCPIP_HTTP_ArgGet(const uint8_t* cData, const uint8_t* cArg)
Summary:
Locates a form field value in a given data array.
Description:
This function searches through a data array to find the value associated with a
given argument. It can be used to find form field values in data
received over GET or POST.
The end of data is assumed to be reached when a null name parameter is
encountered. This requires the string to have an even number of
null-terminated strings, followed by an additional null terminator.
Precondition:
The data array has a valid series of null terminated name/value pairs.
Parameters:
cData - the buffer to search
cArg - the name of the argument to find
Returns:
A pointer to the argument value, or NULL if not found.
Example:
<code>
void TCPIP_HTTP_Print_cookiename(HTTP_CONN_HANDLE connHandle)
{
const uint8_t *ptr;
TCP_SOCKET sktHTTP;
ptr = TCPIP_HTTP_ArgGet(TCPIP_HTTP_CurrentConnectionDataBufferGet(connHandle), (const uint8_t*)"name");
sktHTTP = TCPIP_HTTP_CurrentConnectionSocketGet(connHandle);
if(ptr)
TCPIP_TCP_StringPut(sktHTTP, ptr);
else
TCPIP_TCP_StringPut(sktHTTP, (const uint8_t*)"not set");
}
</code>
Remarks:
None.
*/
const uint8_t* TCPIP_HTTP_ArgGet(const uint8_t* cData, const uint8_t* cArg);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_FileInclude(HTTP_CONN_HANDLE connHandle, const uint8_t* cFile)
Summary:
Writes a file byte-for-byte to the currently loaded TCP socket.
Description:
This function allows an entire file to be included as a dynamic variable, providing
a basic templating system for HTML web pages. This reduces unneeded
duplication of visual elements such as headers, menus, etc.
When pHttpCon->callbackPos is 0, the file is opened and as many bytes
as possible are written. The current position is then saved to
pHttpCon->callbackPos and the file is closed. On subsequent calls,
reading begins at the saved location and continues. Once the end of
the input file is reached, pHttpCon->callbackPos is set back to 0 to
indicate completion.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
cFile - the name of the file to be sent
Returns:
None.
Remarks:
Users should not call this function directly, but should instead add
dynamic variables in the form of <c>~inc:filename.ext~</c> in their HTML code
to include (for example) the file "filename.ext" at that specified
location. The mpfs2.jar utility will handle the rest.
*/
void TCPIP_HTTP_FileInclude(HTTP_CONN_HANDLE connHandle, const uint8_t* cFile);
//*****************************************************************************
/*
Function:
HTTP_READ_STATUS TCPIP_HTTP_PostNameRead(HTTP_CONN_HANDLE connHandle, uint8_t* cData, uint16_t wLen)
Summary:
Reads a name from a URL encoded string in the TCP buffer.
Description:
This function reads a name from a URL encoded string in the TCP buffer. This function
is meant to be called from an TCPIP_HTTP_PostExecute callback to facilitate
easier parsing of incoming data. This function also prevents buffer
overflows by forcing the programmer to indicate how many bytes are
expected. At least two extra bytes are needed in cData over the maximum
length of data expected to be read.
This function will read until the next '=' character, which indicates the
end of a name parameter. It assumes that the front of the buffer is
the beginning of the name parameter to be read.
This function properly updates pHttpCon->byteCount by decrementing it
by the number of bytes read. It also removes the delimiting '=' from
the buffer.
Precondition:
The front of the TCP buffer is the beginning of a name parameter, and the rest of
the TCP buffer contains a URL-encoded string with a name parameter
terminated by a '=' character.
Parameters:
connHandle - HTTP connection handle
cData - where to store the name once it is read
wLen - how many bytes can be written to cData
Returns:
- HTTP_READ_OK - name was successfully read
- HTTP_READ_TRUNCTATED - entire name could not fit in the buffer, so the
value was truncated and data has been lost
- HTTP_READ_INCOMPLETE - entire name was not yet in the buffer, so call
this function again later to retrieve
Remarks:
None.
*/
HTTP_READ_STATUS TCPIP_HTTP_PostNameRead(HTTP_CONN_HANDLE connHandle, uint8_t* cData, uint16_t wLen);
//*****************************************************************************
/*
Function:
HTTP_READ_STATUS TCPIP_HTTP_PostValueRead(HTTP_CONN_HANDLE connHandle, uint8_t* cData, uint16_t wLen)
Summary:
Reads a value from a URL encoded string in the TCP buffer.
Description:
This function reads a value from a URL encoded string in the TCP buffer. This function
is meant to be called from an TCPIP_HTTP_PostExecute callback to facilitate
easier parsing of incoming data. This function also prevents buffer
overflows by forcing the programmer to indicate how many bytes are
expected. At least 2 extra bytes are needed in cData above the maximum
length of data expected to be read.
This function will read until the next '&' character, which indicates the
end of a value parameter. It assumes that the front of the buffer is
the beginning of the value parameter to be read. If pHttpCon->byteCount
indicates that all expected bytes are in the buffer, it assumes that
all remaining data is the value and acts accordingly.
This function properly updates pHttpCon->byteCount by decrementing it
by the number of bytes read. The terminating '&' character is also
removed from the buffer.
Precondition:
The front of the TCP buffer is the beginning of a name parameter, and the rest of
the TCP buffer contains a URL-encoded string with a name parameter
terminated by a '=' character.
Parameters:
connHandle - HTTP connection handle
cData - where to store the value once it is read
wLen - how many bytes can be written to cData
Returns:
- HTTP_READ_OK - value was successfully read
- HTTP_READ_TRUNCTATED - entire value could not fit in the buffer, so the
value was truncated and data has been lost
- HTTP_READ_INCOMPLETE - entire value was not yet in the buffer, so call
this function again later to retrieve
Remarks:
None.
*/
HTTP_READ_STATUS TCPIP_HTTP_PostValueRead(HTTP_CONN_HANDLE connHandle, uint8_t* cData, uint16_t wLen);
//*****************************************************************************
/*
Function:
FILE_HANDLE TCPIP_HTTP_CurrentConnectionFileGet(HTTP_CONN_HANDLE connHandle)
Summary:
Get handle to current connection's file.
Description:
This function returns the handle of the current HTTP connection file.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
Handle to File System file belonging to the connection defined by connHandle
Example:
<code>
uint8_t myBuff[20];
// Get the file handle and read from that file
SYS_FS_FileRead(myBuff, sizeof(myBuff), TCPIP_HTTP_CurrentConnectionFileGet(connHandle));
</code>
Remarks:
None.
*/
SYS_FS_HANDLE TCPIP_HTTP_CurrentConnectionFileGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
uint16_t TCPIP_HTTP_CurrentConnectionPostSmGet(HTTP_CONN_HANDLE connHandle)
Summary:
Get the POST state machine state.
Description:
This function returns the POST state machine state for the connection defined by connHandle.
This state is maintained by the HTTP connection and can be used by the user of the
HTTP to maintain its own POST state machine.
The values of the POST state machine have significance only for the user of the HTTP connection.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
16-bit integer POST state machine state.
Example:
<code>
#define SM_POST_LCD_READ_NAME 1
#define SM_POST_LCD_READ_VALUE 2
switch(TCPIP_HTTP_CurrentConnectionPostSmGet(connHandle))
{
// Find the name
case SM_POST_LCD_READ_NAME:
.
.
.
// Found the value, so store the LCD and return
case SM_POST_LCD_READ_VALUE:
.
.
.
}
</code>
Remarks:
None.
*/
uint16_t TCPIP_HTTP_CurrentConnectionPostSmGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_CurrentConnectionPostSmSet(HTTP_CONN_HANDLE connHandle, uint16_t state)
Summary:
Set the POST state machine state.
Description:
This function sets the POST state machine state for the connection defined by connHandle.
This state is maintained by the HTTP connection and can be used by the user of the
HTTP to maintain its own POST state machine.
The values of the POST state machine have significance only for the user of the HTTP connection.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
state - 16 bit integer state for POST state machine
Returns:
None.
Example:
<code>
uint8_t* httpDataBuff;
uint16_t httpBuffSize;
#define SM_POST_LCD_READ_NAME 1
#define SM_POST_LCD_READ_VALUE 2
switch(TCPIP_HTTP_CurrentConnectionPostSmGet(connHandle))
{
// Find the name
case SM_POST_LCD_READ_NAME:
// Read a name
httpBuffSize = TCPIP_HTTP_CurrentConnectionDataBufferSizeGet(connHandle);
if(TCPIP_HTTP_PostNameRead(connHandle, httpDataBuff, httpBuffSize) == HTTP_READ_INCOMPLETE)
return HTTP_IO_NEED_DATA;
TCPIP_HTTP_CurrentConnectionPostSmSet(connHandle, SM_POST_LCD_READ_VALUE);
// No break...continue reading value
// Found the value, so store the LCD and return
case SM_POST_LCD_READ_VALUE:
.
.
.
}
</code>
Remarks:
None.
*/
void TCPIP_HTTP_CurrentConnectionPostSmSet(HTTP_CONN_HANDLE connHandle, uint16_t state);
//*****************************************************************************
/*
Function:
uint8_t* TCPIP_HTTP_CurrentConnectionDataBufferGet(HTTP_CONN_HANDLE connHandle)
Summary:
Returns pointer to connection general purpose data buffer.
Description:
This function returns a pointer to the HTTP connection internal data buffer.
This gives access to the application to the data that's stored in the
HTTP connection buffer.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
Pointer to the connection's general purpose data buffer.
Example:
<code>
void TCPIP_HTTP_Print_cookiename(HTTP_CONN_HANDLE connHandle)
{
const uint8_t *ptr;
TCP_SOCKET sktHTTP;
ptr = TCPIP_HTTP_ArgGet(TCPIP_HTTP_CurrentConnectionDataBufferGet(connHandle), (const uint8_t*)"name");
sktHTTP = TCPIP_HTTP_CurrentConnectionSocketGet(connHandle);
if(ptr)
TCPIP_TCP_StringPut(sktHTTP, ptr);
else
TCPIP_TCP_StringPut(sktHTTP, (const uint8_t*)"not set");
}
</code>
Remarks:
None.
*/
uint8_t* TCPIP_HTTP_CurrentConnectionDataBufferGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
uint16_t TCPIP_HTTP_CurrentConnectionDataBufferSizeGet(HTTP_CONN_HANDLE connHandle)
Summary:
Returns the size of the connection general purpose data buffer.
Description:
This function returns the size of the HTTP connection internal data buffer.
This buffer is created at the HTTP initialization using the size specified in
TCPIP_HTTP_MODULE_CONFIG.dataLen .
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
Size of the connection's general purpose data buffer.
Example:
<code>
</code>
Remarks:
Currently the size of the buffer is the same for all connections.
The connHandle parameter is not used.
*/
uint16_t TCPIP_HTTP_CurrentConnectionDataBufferSizeGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
uint32_t TCPIP_HTTP_CurrentConnectionCallbackPosGet(HTTP_CONN_HANDLE connHandle)
Summary:
Returns the callback position indicator.
Description:
This function will return the current value of the callback position indicator
for the HTTP connection identified by connHandle.
The callback position indicator is used in the processing of the
HTTP dynamic variables.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
Callback position indicator for connection defined by connHandle.
Example:
<code>
uint32_t callbackPos;
callbackPos = TCPIP_HTTP_CurrentConnectionCallbackPosGet(connHandle);
if(callbackPos == 0x00u)
callbackPos = (uint32_t)DDNSClient.Host.szRAM;
callbackPos = (uint32_t)TCPIP_TCP_StringPut(TCPIP_HTTP_CurrentConnectionSocketGet(connHandle), (uint8_t*)callbackPos);
if(*(uint8_t*)callbackPos == '\0')
callbackPos = 0x00;
TCPIP_HTTP_CurrentConnectionCallbackPosSet(connHandle, callbackPos);
</code>
Remarks:
None.
*/
uint32_t TCPIP_HTTP_CurrentConnectionCallbackPosGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_CurrentConnectionCallbackPosSet(HTTP_CONN_HANDLE connHandle, uint32_t callbackPos)
Summary:
Sets the callback position indicator.
Description:
This function will set the current value of the callback position indicator
for the HTTP connection identified by connHandle.
The callback position indicator is used in the processing of the
HTTP dynamic variables.
When set to a value != 0, it indicates to the HTTP server that the application
has more pending processing that needs to be done.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
callbackPos - new connection callback position value
Returns:
None.
Example:
<code>
void TCPIP_HTTP_Print_builddate(HTTP_CONN_HANDLE connHandle)
{
TCP_SOCKET sktHTTP;
sktHTTP = TCPIP_HTTP_CurrentConnectionSocketGet(connHandle);
TCPIP_HTTP_CurrentConnectionCallbackPosSet(connHandle, 0x01);
if(TCPIP_TCP_PutIsReady(sktHTTP) < strlen((const char*)__DATE__" "__TIME__))
{ // Don't have room to output build date and time
return;
}
TCPIP_HTTP_CurrentConnectionCallbackPosSet(connHandle, 0x00);
TCPIP_TCP_StringPut(sktHTTP, (const void*)__DATE__" "__TIME__);
}
</code>
Remarks:
None.
*/
void TCPIP_HTTP_CurrentConnectionCallbackPosSet(HTTP_CONN_HANDLE connHandle, uint32_t callbackPos);
//*****************************************************************************
/*
Function:
HTTP_STATUS TCPIP_HTTP_CurrentConnectionStatusGet(HTTP_CONN_HANDLE connHandle);
Summary:
Gets HTTP status.
Description:
This function returns the current HTTP status of the selected HTTP connection.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
A HTTP_STATUS value.
Example:
<code>
HTTP_STATUS currStat = TCPIP_HTTP_CurrentConnectionStatusGet(connHandle);
</code>
Remarks:
None.
*/
HTTP_STATUS TCPIP_HTTP_CurrentConnectionStatusGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_CurrentConnectionStatusSet(HTTP_CONN_HANDLE connHandle, HTTP_STATUS stat)
Summary:
Sets HTTP status.
Description:
Allows write access to the HTTP status of the selected HTTP connection.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
stat - new HTTP_STATUS enumeration value.
Returns:
None.
Example:
<code>
byteCount = TCPIP_HTTP_CurrentConnectionByteCountGet(connHandle);
sktHTTP = TCPIP_HTTP_CurrentConnectionSocketGet(connHandle);
if(byteCount > TCPIP_TCP_GetIsReady(sktHTTP) + TCPIP_TCP_FifoRxFreeGet(sktHTTP))
{ // Configuration Failure
// 302 Redirect will be returned
TCPIP_HTTP_CurrentConnectionStatusSet(connHandle, HTTP_REDIRECT);
}
</code>
Remarks:
None.
*/
void TCPIP_HTTP_CurrentConnectionStatusSet(HTTP_CONN_HANDLE connHandle, HTTP_STATUS stat);
//*****************************************************************************
/*
Function:
uint8_t TCPIP_HTTP_CurrentConnectionHasArgsGet(HTTP_CONN_HANDLE connHandle)
Summary:
Checks whether there are get or cookie arguments.
Description:
The function will get the value of the "cookies or get arguments" that are present.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
The current value of the connection hasArgs.
Example:
<code>
uint8_t hasArgs = TCPIP_HTTP_CurrentConnectionHasArgsGet(connHandle);
</code>
Remarks:
None.
*/
uint8_t TCPIP_HTTP_CurrentConnectionHasArgsGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_CurrentConnectionHasArgsSet(HTTP_CONN_HANDLE connHandle, uint8_t args)
Summary:
Sets whether there are get or cookie arguments.
Description:
The function sets the value of the "cookies or get arguments" that are present.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
args - number of arguments
Returns:
None.
Example:
<code>
else if(!memcmp(filename, "cookies.htm", 11))
{
TCPIP_HTTP_CurrentConnectionHasArgsSet(connHandle, 1);
}
</code>
Remarks:
None.
*/
void TCPIP_HTTP_CurrentConnectionHasArgsSet(HTTP_CONN_HANDLE connHandle, uint8_t args);
//*****************************************************************************
/*
Function:
uint32_t TCPIP_HTTP_CurrentConnectionByteCountGet(HTTP_CONN_HANDLE connHandle)
Summary:
Returns how many bytes have been read so far
Description:
This function returns the current value of the counter showing the number of bytes
read from the connection so far.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
Current connection byte count, how many bytes have been read so far.
Example:
<code>
switch(TCPIP_HTTP_CurrentConnectionPostSmGet(connHandle))
{
case SM_CFG_SNMP_READ_NAME:
// If all parameters have been read, end
if(TCPIP_HTTP_CurrentConnectionByteCountGet(connHandle) == 0u)
{
return HTTP_IO_DONE;
}
.
.
.
}
</code>
Remarks:
None.
*/
uint32_t TCPIP_HTTP_CurrentConnectionByteCountGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_CurrentConnectionByteCountSet(HTTP_CONN_HANDLE connHandle, uint32_t byteCount)
Summary:
Sets how many bytes have been read so far.
Description:
This function sets the current value of the counter showing the number of bytes
read from the connection so far.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
byteCount - byte count to be set
Returns:
None.
Remarks:
None.
*/
void TCPIP_HTTP_CurrentConnectionByteCountSet(HTTP_CONN_HANDLE connHandle, uint32_t byteCount);
//*****************************************************************************
/*
Function:
void TCPIP_HTTP_CurrentConnectionByteCountDec(HTTP_CONN_HANDLE connHandle, uint32_t byteCount)
Summary:
Decrements the connection byte count.
Description:
This function decrements the current value of the counter showing the number of bytes
read from the connection so far.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
byteCount - byte count reduction
Returns:
None.
Remarks:
None.
*/
void TCPIP_HTTP_CurrentConnectionByteCountDec(HTTP_CONN_HANDLE connHandle, uint32_t byteCount);
//*****************************************************************************
/*
Function:
TCP_SOCKET TCPIP_HTTP_CurrentConnectionSocketGet(HTTP_CONN_HANDLE connHandle)
Summary:
Get the socket for the current connection.
Description:
The function returns the TCP socket of the specified HTTP connection.
The user gets access to the connection socket which it can use
for sending/reading data.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
TCP_SOCKET for the connection defined by connHandle.
Example:
<code>
uint32_t byteCount;
TCP_SOCKET sktHTTP;
byteCount = TCPIP_HTTP_CurrentConnectionByteCountGet(connHandle);
sktHTTP = TCPIP_HTTP_CurrentConnectionSocketGet(connHandle);
if(byteCount > TCPIP_TCP_GetIsReady(sktHTTP) + TCPIP_TCP_FifoRxFreeGet(sktHTTP))
{ // Configuration Failure
TCPIP_HTTP_CurrentConnectionStatusSet(connHandle, HTTP_REDIRECT);
return HTTP_IO_DONE;
}
</code>
Remarks:
None.
*/
TCP_SOCKET TCPIP_HTTP_CurrentConnectionSocketGet(HTTP_CONN_HANDLE connHandle);
//*****************************************************************************
/*
Function:
uint8_t TCPIP_HTTP_CurrentConnectionIsAuthorizedGet(HTTP_CONN_HANDLE connHandle)
Summary:
Gets the authorized state for the current connection.
Description:
This function returns the authorization status for the current HTTP connection.
This is one of the values returned by the TCPIP_HTTP_FileAuthenticate() function.
Precondition:
None.
Parameters:
connHandle - HTTP connection handle
Returns:
A uint8_t representing the authorization status.
Example:
<code>