-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathFB_Const.h
2669 lines (2382 loc) · 104 KB
/
FB_Const.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
#include "./core/Firebase_Client_Version.h"
#if !FIREBASE_CLIENT_VERSION_CHECK(40408)
#error "Mixed versions compilation."
#endif
/**
* Created September 14, 2023
*
* The MIT License (MIT)
* Copyright (c) 2023 K. Suwatchai (Mobizt)
*
*
* Permission is hereby granted, free of charge, to any person returning a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef FB_CONST_H_
#define FB_CONST_H_
#include <Arduino.h>
#include "./mbfs/MB_MCU.h"
#include <time.h>
#if !defined(__AVR__)
#include <vector>
#include <functional>
#endif
#include "./FirebaseFS.h"
#include "./FB_Network.h"
#if defined(DEFAULT_FLASH_FS) || defined(DEFAULT_SD_FS)
#define FIREBASEJSON_USE_FS
#endif
#if defined(FIREBASE_USE_PSRAM)
#define FIREBASEJSON_USE_PSRAM
#endif
// FirebaseJson was already included in MB_FS.h
#include "./mbfs/MB_FS.h"
#if (defined(ENABLE_OTA_FIRMWARE_UPDATE) || defined(FIREBASE_ENABLE_OTA_FIRMWARE_UPDATE)) && (defined(ENABLE_RTDB) || defined(FIREBASE_ENABLE_RTDB) || (defined(ENABLE_FB_STORAGE) || defined(FIREBASE_ENABLE_FB_STORAGE)) || defined(ENABLE_GC_STORAGE))
#if defined(ESP32)
#include <Update.h>
#elif defined(ESP8266) || defined(MB_ARDUINO_PICO)
#include <Updater.h>
#endif
#define OTA_UPDATE_ENABLED
#endif
#if defined(MB_ARDUINO_PICO) && defined(INC_FREERTOS_H) && !defined(ENABLE_PICO_FREE_RTOS)
#define ENABLE_PICO_FREE_RTOS
#include <task.h>
#endif
#if defined(ESP32)
#if defined(ESP_ARDUINO_VERSION)
#if ESP_ARDUINO_VERSION > ESP_ARDUINO_VERSION_VAL(2, 0, 1)
#define ESP32_GT_2_0_1_FS_MEMORY_FIX
#endif
#endif
#endif
#define FIREBASE_PORT 443
#define MAX_REDIRECT 5
#define MIN_NET_RECONNECT_TIMEOUT 10 * 1000
#define MAX_NET_RECONNECT_TIMEOUT 5 * 60 * 1000
#define MIN_SOCKET_CONN_TIMEOUT 1 * 1000
#define DEFAULT_SOCKET_CONN_TIMEOUT 10 * 1000
#define MAX_SOCKET_CONN_TIMEOUT 60 * 1000
#define MIN_SERVER_RESPONSE_TIMEOUT 1 * 1000
#define DEFAULT_SERVER_RESPONSE_TIMEOUT 10 * 1000
#define MAX_SERVER_RESPONSE_TIMEOUT 60 * 1000
#define MIN_RTDB_KEEP_ALIVE_TIMEOUT 20 * 1000
#define DEFAULT_RTDB_KEEP_ALIVE_TIMEOUT 45 * 1000
#define MAX_RTDB_KEEP_ALIVE_TIMEOUT 2 * 60 * 1000
#define MIN_RTDB_STREAM_RECONNECT_INTERVAL 1000
#define MAX_RTDB_STREAM_RECONNECT_INTERVAL 60 * 1000
#define MIN_RTDB_STREAM_ERROR_NOTIFIED_INTERVAL 3 * 1000
#define MAX_RTDB_STREAM_ERROR_NOTIFIED_INTERVAL 30 * 1000
#define MIN_TOKEN_GENERATION_BEGIN_STEP_INTERVAL 300
#define MIN_TOKEN_GENERATION_ERROR_INTERVAL 5 * 1000
#define MIN_NTP_SERVER_SYNC_TIME_OUT 15 * 1000
#define FB_TIME_SYNC_INTERVAL 1500
#define DEFAULT_AUTH_TOKEN_PRE_REFRESH_SECONDS 5 * 60
#define DEFAULT_AUTH_TOKEN_EXPIRED_SECONDS 3600
#define DEFAULT_REQUEST_TIMEOUT 2000
// The TCP session will be closed when time out reached
#define DEFAULT_TCP_CONNECTION_TIMEOUT 3 * 60 * 1000
#define SD_CS_PIN 15
#define STREAM_TASK_STACK_SIZE 8192
#define QUEUE_TASK_STACK_SIZE 8192
#define MAX_BLOB_PAYLOAD_SIZE 1024
#define FIREBASE_DEFAULT_TS 1618971013
#define FIREBASE_NON_TS -1000
#define ESP_REPORT_PROGRESS_INTERVAL 2
#define _NO_REF 0
#define _NO_QUERY 0
#define _NO_SUB_TYPE 0
#define _NO_BLOB_SIZE 0
#define _NO_PRIORITY 0
#define _NO_PAYLOAD ""
#define _NO_ETAG ""
#define _NO_FILE ""
#define _EMPTY_STR ""
#define _IS_ASYNC true
#define _NO_ASYNC false
#define _NO_QUEUE false
#include "FB_Error.h"
typedef void (*FB_TCPConnectionRequestCallback)(const char *, int);
typedef void (*FB_NetworkConnectionRequestCallback)(void);
typedef void (*FB_NetworkStatusRequestCallback)(void);
typedef void (*FB_ResponseCallback)(const char *);
typedef enum
{
mem_storage_type_undefined,
mem_storage_type_flash,
mem_storage_type_sd
} firebase_mem_storage_type;
typedef enum
{
firebase_cert_type_undefined = -1,
firebase_cert_type_none = 0,
firebase_cert_type_data,
firebase_cert_type_file
} firebase_cert_type;
#if defined(FIREBASE_ESP32_CLIENT) || defined(FIREBASE_ESP8266_CLIENT)
struct StorageType
{
static const int8_t UNDEFINED = 0; // add to compatible with firebase_mem_storage_type enum
static const int8_t FLASH = 1; // now set to 1 instead of 0 in older version
static const int8_t SD = 2; // now set to 2 instead of 1 in older version
};
#endif
enum firebase_con_mode
{
firebase_con_mode_undefined,
firebase_con_mode_rtdb,
firebase_con_mode_rtdb_stream,
firebase_con_mode_fcm,
firebase_con_mode_storage,
firebase_con_mode_gc_storage,
firebase_con_mode_firestore,
firebase_con_mode_functions
};
enum firebase_data_type
{
// Do not changes the order as it used by firebase_rtdb_data_type
d_any = 0,
d_null,
d_integer,
d_float,
d_double,
d_boolean,
d_string,
d_json,
d_array,
d_blob,
d_file,
d_file_ota,
d_timestamp,
d_shallow
};
enum firebase_rtdb_data_type
{
firebase_rtdb_data_type_null = d_null,
firebase_rtdb_data_type_integer = d_integer,
firebase_rtdb_data_type_float = d_float,
firebase_rtdb_data_type_double = d_double,
firebase_rtdb_data_type_boolean = d_boolean,
firebase_rtdb_data_type_string = d_string,
firebase_rtdb_data_type_json = d_json,
firebase_rtdb_data_type_array = d_array,
firebase_rtdb_data_type_blob = d_blob,
firebase_rtdb_data_type_file = d_file,
// old version compat
fb_esp_rtdb_data_type_null = d_null,
fb_esp_rtdb_data_type_integer = d_integer,
fb_esp_rtdb_data_type_float = d_float,
fb_esp_rtdb_data_type_double = d_double,
fb_esp_rtdb_data_type_boolean = d_boolean,
fb_esp_rtdb_data_type_string = d_string,
fb_esp_rtdb_data_type_json = d_json,
fb_esp_rtdb_data_type_array = d_array,
fb_esp_rtdb_data_type_blob = d_blob,
fb_esp_rtdb_data_type_file = d_file
};
enum firebase_request_method
{
http_undefined,
http_put,
http_post,
http_get,
http_patch,
http_delete,
rtdb_set_nocontent, /* HTTP PUT (No content) */
rtdb_update_nocontent, /* HTTP PATCH (No content) */
rtdb_get_nocontent, /* HTTP GET (No content) */
rtdb_stream, /* HTTP GET (SSE) */
rtdb_backup, /* HTTP GET */
rtdb_restore, /* HTTP PATCH */
rtdb_get_rules, /* HTTP GET */
rtdb_set_rules, /* HTTP PUT */
rtdb_get_shallow, /* HTTP GET */
rtdb_get_priority, /* HTTP GET */
rtdb_set_priority, /* HTTP PUT */
};
enum firebase_http_connection_type
{
firebase_http_connection_type_undefined,
firebase_http_connection_type_keep_alive,
firebase_http_connection_type_close
};
enum firebase_settings_provider_type
{
auth_provider_type_login,
auth_provider_type_service_account
};
enum firebase_auth_token_status
{
token_status_uninitialized,
token_status_on_initialize,
token_status_on_signing,
token_status_on_request,
token_status_on_refresh,
token_status_ready,
token_status_error
};
enum firebase_auth_token_type
{
token_type_undefined,
token_type_legacy_token,
token_type_id_token,
token_type_custom_token,
token_type_oauth2_access_token,
token_type_refresh_token
};
enum firebase_jwt_generation_step
{
firebase_jwt_generation_step_begin,
firebase_jwt_generation_step_encode_header_payload,
firebase_jwt_generation_step_sign,
firebase_jwt_generation_step_exchange
};
enum firebase_user_email_sending_type
{
firebase_user_email_sending_type_verify,
firebase_user_email_sending_type_reset_psw
};
#if defined(ENABLE_RTDB) || defined(FIREBASE_ENABLE_RTDB)
enum firebase_rtdb_task_type
{
firebase_rtdb_task_undefined,
firebase_rtdb_task_download_rules,
firebase_rtdb_task_read_rules,
firebase_rtdb_task_upload_rules,
firebase_rtdb_task_store_rules
};
enum firebase_rtdb_value_type
{
firebase_rtdb_value_type_any = 0,
firebase_rtdb_value_type_std_string = 1,
firebase_rtdb_value_type_arduino_string = 2,
firebase_rtdb_value_type_mb_string = 3,
firebase_rtdb_value_type_char_array = 4,
firebase_rtdb_value_type_int = 5,
firebase_rtdb_value_type_float = 6,
firebase_rtdb_value_type_double = 7,
firebase_rtdb_value_type_json = 8,
firebase_rtdb_value_type_array = 9,
firebase_rtdb_value_type_blob = 10
};
enum firebase_rtdb_upload_status
{
firebase_rtdb_upload_status_error = -1,
firebase_rtdb_upload_status_unknown = 0,
firebase_rtdb_upload_status_init = 1,
firebase_rtdb_upload_status_upload = 2,
firebase_rtdb_upload_status_complete = 3,
// old version compat
fb_esp_rtdb_upload_status_error = -1,
fb_esp_rtdb_upload_status_unknown = 0,
fb_esp_rtdb_upload_status_init = 1,
fb_esp_rtdb_upload_status_upload = 2,
fb_esp_rtdb_upload_status_complete = 3
};
enum firebase_rtdb_download_status
{
firebase_rtdb_download_status_error = -1,
firebase_rtdb_download_status_unknown = 0,
firebase_rtdb_download_status_init = 2,
firebase_rtdb_download_status_download = 3,
firebase_rtdb_download_status_complete = 4,
// old version compat
fb_esp_rtdb_download_status_error = -1,
fb_esp_rtdb_download_status_unknown = 0,
fb_esp_rtdb_download_status_init = 2,
fb_esp_rtdb_download_status_download = 3,
fb_esp_rtdb_download_status_complete = 4
};
#endif
#if defined(ENABLE_FIRESTORE) || defined(FIREBASE_ENABLE_FIRESTORE)
enum firebase_cfs_upload_status
{
firebase_cfs_upload_status_error = -1,
firebase_cfs_upload_status_unknown = 0,
firebase_cfs_upload_status_init = 1,
firebase_cfs_upload_status_upload = 2,
firebase_cfs_upload_status_complete = 3,
firebase_cfs_upload_status_process_response = 4,
// old version compat
fb_esp_cfs_upload_status_error = -1,
fb_esp_cfs_upload_status_unknown = 0,
fb_esp_cfs_upload_status_init = 1,
fb_esp_cfs_upload_status_upload = 2,
fb_esp_cfs_upload_status_complete = 3,
fb_esp_cfs_upload_status_process_response = 4
};
#endif
#if defined(ENABLE_FCM) || defined(FIREBASE_ENABLE_FCM)
enum firebase_fcm_msg_mode
{
firebase_fcm_msg_mode_legacy_http,
firebase_fcm_msg_mode_httpv1,
firebase_fcm_msg_mode_subscribe,
firebase_fcm_msg_mode_unsubscribe,
firebase_fcm_msg_mode_app_instance_info,
firebase_fcm_msg_mode_apn_token_registration
};
#endif
#if defined(ENABLE_GC_STORAGE) || defined(FIREBASE_ENABLE_GC_STORAGE)
enum firebase_gcs_request_type
{
firebase_gcs_request_type_undefined,
firebase_gcs_request_type_upload_simple,
firebase_gcs_request_type_upload_multipart,
firebase_gcs_request_type_upload_resumable_init,
firebase_gcs_request_type_upload_resumable_run,
firebase_gcs_request_type_download,
firebase_gcs_request_type_patch,
firebase_gcs_request_type_delete,
firebase_gcs_request_type_get_metadata,
firebase_gcs_request_type_set_metadata,
firebase_gcs_request_type_update_metadata,
firebase_gcs_request_type_list,
firebase_gcs_request_type_download_ota
};
enum firebase_gcs_upload_type
{
gcs_upload_type_simple,
gcs_upload_type_multipart,
gcs_upload_type_resumable
};
enum firebase_gcs_upload_status
{
firebase_gcs_upload_status_error = -1,
firebase_gcs_upload_status_unknown = 0,
firebase_gcs_upload_status_init = 1,
firebase_gcs_upload_status_upload = 2,
firebase_gcs_upload_status_complete = 3,
// old version compat
fb_esp_gcs_upload_status_error = -1,
fb_esp_gcs_upload_status_unknown = 0,
fb_esp_gcs_upload_status_init = 1,
fb_esp_gcs_upload_status_upload = 2,
fb_esp_gcs_upload_status_complete = 3
};
enum firebase_gcs_download_status
{
firebase_gcs_download_status_error = -1,
firebase_gcs_download_status_unknown = 0,
firebase_gcs_download_status_init = 1,
firebase_gcs_download_status_download = 2,
firebase_gcs_download_status_complete = 3,
// old version compat
fb_esp_gcs_download_status_error = -1,
fb_esp_gcs_download_status_unknown = 0,
fb_esp_gcs_download_status_init = 1,
fb_esp_gcs_download_status_download = 2,
fb_esp_gcs_download_status_complete = 3
};
#endif
#if defined(ENABLE_FB_STORAGE) || defined(FIREBASE_ENABLE_FB_STORAGE)
enum firebase_fcs_request_type
{
firebase_fcs_request_type_undefined,
firebase_fcs_request_type_upload,
firebase_fcs_request_type_upload_pgm_data,
firebase_fcs_request_type_download,
firebase_fcs_request_type_get_meta,
firebase_fcs_request_type_delete,
firebase_fcs_request_type_list,
firebase_fcs_request_type_download_ota
};
enum firebase_fcs_upload_status
{
firebase_fcs_upload_status_error = -1,
firebase_fcs_upload_status_unknown = 0,
firebase_fcs_upload_status_init = 1,
firebase_fcs_upload_status_upload = 2,
firebase_fcs_upload_status_complete = 3,
// old version compat
fb_esp_fcs_upload_status_error = -1,
fb_esp_fcs_upload_status_unknown = 0,
fb_esp_fcs_upload_status_init = 1,
fb_esp_fcs_upload_status_upload = 2,
fb_esp_fcs_upload_status_complete = 3
};
enum firebase_fcs_download_status
{
firebase_fcs_download_status_error = -1,
firebase_fcs_download_status_unknown = 0,
firebase_fcs_download_status_init = 1,
firebase_fcs_download_status_download = 2,
firebase_fcs_download_status_complete = 3,
// old version compat
fb_esp_fcs_download_status_error = -1,
fb_esp_fcs_download_status_unknown = 0,
fb_esp_fcs_download_status_init = 1,
fb_esp_fcs_download_status_download = 2,
fb_esp_fcs_download_status_complete = 3
};
#endif
#if defined(ENABLE_FIRESTORE) || defined(FIREBASE_ENABLE_FIRESTORE)
enum firebase_firestore_request_type
{
firebase_firestore_request_type_undefined,
firebase_firestore_request_type_export_docs,
firebase_firestore_request_type_import_docs,
firebase_firestore_request_type_get_doc,
firebase_firestore_request_type_batch_get_doc,
firebase_firestore_request_type_create_doc,
firebase_firestore_request_type_patch_doc,
firebase_firestore_request_type_delete_doc,
firebase_firestore_request_type_run_query,
firebase_firestore_request_type_begin_transaction,
firebase_firestore_request_type_rollback,
firebase_firestore_request_type_list_doc,
firebase_firestore_request_type_list_collection,
firebase_firestore_request_type_commit_document,
firebase_firestore_request_type_batch_write_doc,
firebase_firestore_request_type_create_index,
firebase_firestore_request_type_delete_index,
firebase_firestore_request_type_list_index,
firebase_firestore_request_type_get_index
};
enum firebase_firestore_document_write_type
{
firebase_firestore_document_write_type_undefined,
firebase_firestore_document_write_type_update,
firebase_firestore_document_write_type_delete,
firebase_firestore_document_write_type_transform
};
enum firebase_firestore_transform_type
{
firebase_firestore_transform_type_undefined,
firebase_firestore_transform_type_set_to_server_value,
firebase_firestore_transform_type_increment,
firebase_firestore_transform_type_maaximum,
firebase_firestore_transform_type_minimum,
firebase_firestore_transform_type_append_missing_elements,
firebase_firestore_transform_type_remove_all_from_array
};
enum firebase_firestore_consistency_mode
{
firebase_firestore_consistency_mode_undefined,
firebase_firestore_consistency_mode_transaction,
firebase_firestore_consistency_mode_newTransaction,
firebase_firestore_consistency_mode_readTime
};
#endif
#if defined(ENABLE_FB_FUNCTIONS) || defined(FIREBASE_ENABLE_FB_FUNCTIONS)
enum firebase_functions_creation_step
{
firebase_functions_creation_step_idle,
firebase_functions_creation_step_gen_upload_url,
firebase_functions_creation_step_upload_zip_file,
firebase_functions_creation_step_upload_source_files,
firebase_functions_creation_step_deploy,
firebase_functions_creation_step_polling_status,
firebase_functions_creation_step_set_iam_policy,
firebase_functions_creation_step_delete
};
enum firebase_functions_request_type
{
firebase_functions_request_type_undefined,
firebase_functions_request_type_call,
firebase_functions_request_type_create,
firebase_functions_request_type_delete,
firebase_functions_request_type_gen_download_url,
firebase_functions_request_type_gen_upload_url,
firebase_functions_request_type_upload,
firebase_functions_request_type_pgm_upload,
firebase_functions_request_type_upload_bucket_sources,
firebase_functions_request_type_get,
firebase_functions_request_type_get_iam_policy,
firebase_functions_request_type_list,
firebase_functions_request_type_patch,
firebase_functions_request_type_set_iam_policy,
firebase_functions_request_type_test_iam_policy,
firebase_functions_request_type_list_operations,
};
enum firebase_functions_sources_type
{
functions_sources_type_undefined,
functions_sources_type_storage_bucket_archive,
functions_sources_type_storage_bucket_sources,
functions_sources_type_flash_data,
functions_sources_type_local_archive,
functions_sources_type_repository,
};
enum firebase_functions_trigger_type
{
firebase_functions_trigger_type_undefined,
firebase_functions_trigger_type_https,
firebase_functions_trigger_type_event
};
enum firebase_functions_status
{
firebase_functions_status_CLOUD_FUNCTION_STATUS_UNSPECIFIED,
firebase_functions_status_ACTIVE,
firebase_functions_status_OFFLINE,
firebase_functions_status_DEPLOY_IN_PROGRESS,
firebase_functions_status_DELETE_IN_PROGRESS,
firebase_functions_status_UNKNOWN
};
enum firebase_functions_operation_status
{
firebase_functions_operation_status_unknown = -1,
firebase_functions_operation_status_generate_upload_url = 0,
firebase_functions_operation_status_upload_source_file_in_progress = 1,
firebase_functions_operation_status_deploy_in_progress = 2,
firebase_functions_operation_status_set_iam_policy_in_progress = 3,
firebase_functions_operation_status_delete_in_progress = 4,
firebase_functions_operation_status_finished = 5,
firebase_functions_operation_status_error = 6,
// old version compat
fb_esp_functions_operation_status_unknown = -1,
fb_esp_functions_operation_status_generate_upload_url = 0,
fb_esp_functions_operation_status_upload_source_file_in_progress = 1,
fb_esp_functions_operation_status_deploy_in_progress = 2,
fb_esp_functions_operation_status_set_iam_policy_in_progress = 3,
fb_esp_functions_operation_status_delete_in_progress = 4,
fb_esp_functions_operation_status_finished = 5,
fb_esp_functions_operation_status_error = 6
};
#endif
struct firebase_wifi_credential_t
{
MB_String ssid;
MB_String password;
};
class firebase_wifi
{
friend class Firebase_TCP_Client;
public:
firebase_wifi(){};
~firebase_wifi()
{
clearAP();
clearMulti();
};
void addAP(const String &ssid, const String &password)
{
firebase_wifi_credential_t data;
data.ssid = ssid;
data.password = password;
credentials.push_back(data);
}
void clearAP()
{
credentials.clear();
}
size_t size() { return credentials.size(); }
firebase_wifi_credential_t operator[](size_t index)
{
return credentials[index];
}
private:
MB_List<firebase_wifi_credential_t> credentials;
#if defined(FIREBASE_HAS_WIFIMULTI)
WiFiMulti *multi = nullptr;
#endif
void reconnect()
{
if (credentials.size())
{
disconnect();
connect();
}
}
void connect()
{
#if defined(FIREBASE_HAS_WIFIMULTI)
clearMulti();
multi = new WiFiMulti();
for (size_t i = 0; i < credentials.size(); i++)
multi->addAP(credentials[i].ssid.c_str(), credentials[i].password.c_str());
if (credentials.size() > 0)
multi->run();
#elif defined(FIREBASE_WIFI_IS_AVAILABLE)
WiFi.begin((CONST_STRING_CAST)credentials[0].ssid.c_str(), credentials[0].password.c_str());
#endif
}
void disconnect()
{
#if defined(FIREBASE_WIFI_IS_AVAILABLE)
WiFi.disconnect();
#endif
}
void clearMulti()
{
#if defined(FIREBASE_HAS_WIFIMULTI)
if (multi)
delete multi;
multi = nullptr;
#endif
}
};
template <typename T>
struct firebase_base64_io_t
{
// the total bytes of data in output buffer
int bufWrite = 0;
// the size of output buffer
size_t bufLen = 1024;
// for file, the type of filesystem to write
mbfs_file_type filetype = mb_fs_mem_storage_type_undefined;
// for T array
T *outT = nullptr;
// for T vector
MB_VECTOR<T> *outL = nullptr;
// for client
Client *outC = nullptr;
// for ota
bool ota = false;
};
struct firebase_response_t
{
int code = 0;
};
struct firebase_auth_token_error_t
{
MB_String message;
int code = 0;
};
struct server_response_data_t
{
int httpCode = 0;
// Must not be negative
int payloadLen = 0;
// The response content length, must not be negative as it uses to determine
// the available data to read in event-stream
// and content length specific read in http response
int contentLen = 0;
int chunkRange = 0;
firebase_data_type dataType = firebase_data_type::d_any;
int payloadOfs = 0;
bool boolData = false;
int intData = 0;
float floatData = 0.0f;
double doubleData = 0.0f;
MB_VECTOR<uint8_t> blobData;
bool isEvent = false;
bool noEvent = false;
bool isChunkedEnc = false;
bool hasEventData = false;
bool noContent = false;
bool eventPathChanged = false;
bool dataChanged = false;
bool redirect = false;
MB_String location;
MB_String contentType;
MB_String connection;
MB_String eventPath;
MB_String eventType;
MB_String eventData;
MB_String etag;
MB_String pushName;
MB_String fbError;
MB_String transferEnc;
};
struct firebase_chunk_state_info
{
int state = 0;
int chunkedSize = 0;
int dataLen = 0;
};
struct firebase_tcp_response_handler_t
{
// the chunk index of all data that is being process
int chunkIdx = 0;
// the payload chunk index that is being process
int pChunkIdx = 0;
// the total bytes of http response payload to read
int payloadLen = 0;
// the total bytes of base64 decoded data from response payload
int decodedPayloadLen = 0;
// the current size of chunk data to read from client
int chunkBufSize = 0;
// the amount of http response payload that read,
// compare with the content length header value for finishing check
int payloadRead = 0;
// status showed that the http headers was found and is being read
bool isHeader = false;
// status showed that the http headers was completely read
bool headerEnded = false;
// status for OTA request
bool downloadOTA = false;
// the prefered size of chunk data to read from client
size_t defaultChunkSize = 0;
// keep the auth token generation error
struct firebase_auth_token_error_t error;
// keep the http header or the first line of stream event data
MB_String header;
// time out checking for execution
unsigned long dataTime = 0;
// pointer to payload
MB_String *payload = nullptr;
// data is already in receive buffer (must be int)
int bufferAvailable = 0;
// data in receive buffer is base64 file data
bool isBase64File = false;
// the base64 encoded string downloaded anount
int downloadByteLen = 0;
// pad (=) length checking from tail of encoded string of file/blob data
int base64PadLenTail = 0;
// pad (=) length checking from base64 encoded string signature (begins with "file,base64, and "blob,base64,)
// of file/blob data
int base64PadLenSignature = 0;
// the tcp client pointer
Client *client = nullptr;
// the chunk state info
firebase_chunk_state_info chunkState;
public:
int available()
{
if (client)
return client->available();
return false;
}
};
#if defined(ENABLE_RTDB) || defined(FIREBASE_ENABLE_RTDB)
struct firebase_rtdb_address_t
{
int dout = 0;
int din = 0;
int priority = 0;
int query = 0;
};
struct firebase_rtdb_request_data_info
{
firebase_data_type type = d_any;
struct firebase_rtdb_address_t address;
int value_subtype = 0;
MB_String etag;
size_t blobSize = 0;
};
typedef struct firebase_rtdb_upload_status_info_t
{
size_t progress = 0;
firebase_rtdb_upload_status status = firebase_rtdb_upload_status_unknown;
MB_String localFileName;
MB_String remotePath;
int size = 0;
int elapsedTime = 0;
MB_String errorMsg;
} RTDB_UploadStatusInfo;
typedef struct firebase_rtdb_download_status_info_t
{
size_t progress = 0;
firebase_rtdb_download_status status = firebase_rtdb_download_status_unknown;
MB_String localFileName;
MB_String remotePath;
int size = 0;
int elapsedTime = 0;
MB_String errorMsg;
} RTDB_DownloadStatusInfo;
typedef void (*RTDB_UploadProgressCallback)(RTDB_UploadStatusInfo);
typedef void (*RTDB_DownloadProgressCallback)(RTDB_DownloadStatusInfo);
struct firebase_rtdb_request_info_t
{
MB_String path;
MB_String pre_payload;
MB_String post_payload;
MB_String payload;
MB_String filename;
firebase_request_method method = http_get;
struct firebase_rtdb_request_data_info data;
firebase_rtdb_task_type task_type = firebase_rtdb_task_undefined;
bool queue = false;
bool async = false;
size_t fileSize = 0;
#if defined(FIREBASE_ESP_CLIENT)
firebase_mem_storage_type storageType = mem_storage_type_undefined;
#else
uint8_t storageType = StorageType::UNDEFINED;
#endif
int progress = -1;
RTDB_UploadStatusInfo *uploadStatusInfo = nullptr;
RTDB_DownloadStatusInfo *downloadStatusInfo = nullptr;
RTDB_UploadProgressCallback uploadCallback = NULL;
RTDB_DownloadProgressCallback downloadCallback = NULL;
};
#endif
typedef struct firebase_spi_ethernet_module_t
{
#if defined(ESP8266) && defined(ESP8266_CORE_SDK_V3_X_X)
#ifdef INC_ENC28J60_LWIP
ENC28J60lwIP *enc28j60 = nullptr;
#endif
#ifdef INC_W5100_LWIP
Wiznet5100lwIP *w5100 = nullptr;
#endif
#ifdef INC_W5500_LWIP
Wiznet5500lwIP *w5500 = nullptr;
#endif
#elif defined(MB_ARDUINO_PICO)
#endif
} SPI_ETH_Module;
struct firebase_auth_token_info_t
{
const char *legacy_token = "";
MB_String auth_type;
MB_String jwt;
MB_String scope;
unsigned long expires = 0;
/* milliseconds count when last expiry time was set */
unsigned long last_millis = 0;
firebase_auth_token_type token_type = token_type_undefined;
firebase_auth_token_status status = token_status_uninitialized;
struct firebase_auth_token_error_t error;
};
struct firebase_auth_signin_token_t
{
MB_String uid;
MB_String claims;
};
struct firebase_service_account_data_info_t
{
MB_String client_email;
MB_String client_id;
MB_String project_id;
MB_String private_key_id;
const char *private_key = "";
};
struct firebase_auth_signin_user_t
{
MB_String email;
MB_String password;
};
struct firebase_auth_cert_t
{
const char *data = NULL;
MB_String file;
#if defined(FIREBASE_ESP_CLIENT)
firebase_mem_storage_type file_storage = mem_storage_type_flash;
#else
uint8_t file_storage = StorageType::UNDEFINED;
#endif
};
struct firebase_service_account_file_info_t
{
MB_String path;
#if defined(FIREBASE_ESP_CLIENT)
firebase_mem_storage_type storage_type = mem_storage_type_flash;
#else
uint8_t storage_type = StorageType::UNDEFINED;
#endif
};
struct firebase_service_account_t
{
struct firebase_service_account_data_info_t data;