1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: http_Connection.h 4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 $Rev: 37900 $ 11 *--------------------------------------------------------------------------- 12 13 14 */ 15 16 #ifndef NN_HTTP_HTTP_CONNECTION_H_ 17 #define NN_HTTP_HTTP_CONNECTION_H_ 18 19 #include <nn/Result.h> 20 #include <nn/Handle.h> 21 #include <nn/http/http_Types.h> 22 #include <nn/http/http_Result.h> 23 #include <nn/http/http_ConnectionIpc.h> 24 #include <nn/http/http_CertStore.h> 25 #include <nn/http/http_ClientCert.h> 26 #include <nn/util/util_NonCopyable.h> 27 #include <nn/fnd/fnd_TimeSpan.h> 28 29 #ifdef __cplusplus 30 31 namespace nn { 32 namespace http { 33 34 /* Please see man pages for details 35 36 37 */ 38 class Connection : private nn::util::NonCopyable<Connection> 39 { 40 public: 41 //---------------------------------------- 42 // 43 //@{ 44 45 /* Please see man pages for details 46 47 48 49 50 51 52 */ 53 explicit Connection(void); 54 55 /* Please see man pages for details 56 57 58 59 60 61 62 63 */ 64 explicit Connection(const char* pUrl, RequestMethod method = REQUEST_METHOD_GET, bool isUseDefaultProxy = true); 65 66 /* Please see man pages for details 67 68 */ 69 virtual ~Connection(void); 70 71 /* Please see man pages for details 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 */ 93 nn::Result Initialize(const char* pUrl, RequestMethod method = REQUEST_METHOD_GET, bool isUseDefaultProxy = true); 94 95 /* Please see man pages for details 96 97 98 99 100 101 102 103 104 105 106 107 */ 108 nn::Result Finalize(void); 109 110 //@} 111 112 //---------------------------------------- 113 // 114 //@{ 115 116 /* Please see man pages for details 117 118 119 120 121 122 123 124 125 126 127 128 129 */ 130 nn::Result SetProxy(const char* pProxyName, u16 port, const char* pUserName, const char* pPassword); 131 132 /* Please see man pages for details 133 134 135 136 137 138 139 140 141 142 143 */ 144 nn::Result SetBasicAuthorization(const char* pUserName, const char* pPassword); 145 146 /* Please see man pages for details 147 148 149 150 151 152 153 154 155 156 157 158 */ 159 nn::Result SetSocketBufferSize(size_t size); 160 161 //@} 162 163 //---------------------------------------- 164 // 165 //@{ 166 167 /* Please see man pages for details 168 169 170 171 172 173 174 175 176 */ 177 nn::Result Connect(void); 178 179 /* Please see man pages for details 180 181 182 183 184 185 186 187 188 */ 189 nn::Result ConnectAsync(void); 190 191 /* Please see man pages for details 192 193 194 195 196 197 198 199 */ 200 nn::Result Cancel(void); 201 202 /* Please see man pages for details 203 204 205 206 207 208 209 210 211 */ 212 nn::Result GetStatus(Status* pStatusBuf) const; 213 214 /* Please see man pages for details 215 216 217 218 219 220 221 222 223 */ 224 nn::Result GetError(ResultCode* pResultCodeBuf) const; 225 226 /* Please see man pages for details 227 228 229 230 231 232 233 234 235 236 237 238 */ 239 nn::Result GetProgress(size_t* pReceivedLen, size_t* pContentLen) const; 240 241 //@} 242 243 //---------------------------------------- 244 // 245 //@{ 246 247 /* Please see man pages for details 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 nn::Result Read(u8* pBodyBuf, size_t bufLen); 286 287 /* Please see man pages for details 288 289 290 291 292 293 294 295 296 297 298 299 300 301 */ 302 nn::Result Read(u8* pBodyBuf, size_t bufLen, const nn::fnd::TimeSpan& timeout); 303 304 305 /* Please see man pages for details 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 nn::Result GetHeaderField(const char* pLabel, char* pFieldBuf, size_t bufSize, size_t* pFieldLengthCourier = NULL) const; 338 339 /* Please see man pages for details 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 */ 356 nn::Result GetHeaderField(const char* pLabel, char* pFieldBuf, size_t bufSize, const nn::fnd::TimeSpan& timeout, size_t* pFieldLengthCourier = NULL) const; 357 358 /* Please see man pages for details 359 360 361 362 363 364 365 366 367 368 369 370 */ 371 nn::Result GetHeaderAll(char* pHeaderBuf, size_t bufSize, size_t* pLengthCourier = NULL) const; 372 373 /* Please see man pages for details 374 375 376 377 378 379 380 381 382 383 384 385 */ 386 nn::Result GetHeaderAll(char* pHeaderBuf, size_t bufSize, const nn::fnd::TimeSpan& timeout, size_t* pLengthCourier = NULL) const; 387 388 /* Please see man pages for details 389 390 391 392 393 394 395 396 */ 397 nn::Result GetStatusCode(s32* pStatusCodeCourier) const; 398 399 /* Please see man pages for details 400 401 402 403 404 405 406 407 408 409 */ 410 nn::Result GetStatusCode(s32* pStatusCodeCourier, const nn::fnd::TimeSpan& timeout) const; 411 412 //@} 413 414 415 //---------------------------------------- 416 // 417 //@{ 418 419 /* Please see man pages for details 420 421 422 423 424 425 426 427 428 429 430 431 */ 432 nn::Result AddHeaderField(const char* pLabel, const char* pValue); 433 434 435 /* Please see man pages for details 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 nn::Result AddPostDataAscii(const char* pLabel, const char* pValue); 461 462 /* Please see man pages for details 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 nn::Result AddPostDataBinary(const char* pLabel, const void* pValue, size_t valueSize); 488 489 /* Please see man pages for details 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 nn::Result AddPostDataRaw(const void* pValue, size_t valueSize); 516 517 /* Please see man pages for details 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 nn::Result SetLazyPostDataSetting( PostDataType dataType ); 559 560 /* Please see man pages for details 561 562 563 564 565 566 567 568 569 570 571 */ 572 nn::Result NotifyFinishSendPostData( void ); 573 574 /* Please see man pages for details 575 576 577 578 579 580 581 582 583 584 */ 585 nn::Result SetPostDataEncoding(EncodingType type); 586 587 /* Please see man pages for details 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 */ 609 nn::Result SendPostDataAscii(const char* pLabel, const char* pValue); 610 611 /* Please see man pages for details 612 613 614 615 616 617 618 619 620 621 622 623 624 625 */ 626 nn::Result SendPostDataAscii(const char* pLabel, const char* pValue, const nn::fnd::TimeSpan& timeout); 627 628 /* Please see man pages for details 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 */ 652 nn::Result SendPostDataBinary(const char* pLabel, const void* pValue, size_t valueSize); 653 654 /* Please see man pages for details 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 */ 670 nn::Result SendPostDataBinary(const char* pLabel, const void* pValue, size_t valueSize, const nn::fnd::TimeSpan& timeout); 671 672 /* Please see man pages for details 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 */ 695 nn::Result SendPostDataRaw(const void* pValue, size_t valueSize); 696 697 /* Please see man pages for details 698 699 700 701 702 703 704 705 706 707 708 709 710 711 */ 712 nn::Result SendPostDataRaw(const void* pValue, size_t valueSize, const nn::fnd::TimeSpan& timeout); 713 714 //@} 715 716 //---------------------------------------- 717 // 718 //@{ 719 720 /* Please see man pages for details 721 722 723 724 725 726 727 728 729 730 731 */ 732 nn::Result SetRootCa(const u8* pCertData, size_t certDataSize); 733 734 /* Please see man pages for details 735 736 737 738 739 740 741 742 743 744 */ 745 nn::Result SetRootCa( InternalCaCertId inCaCertName ); 746 747 /* Please see man pages for details 748 749 750 751 752 753 754 755 756 757 758 */ 759 nn::Result SetRootCaStore(CertStore& certStore); 760 761 762 /* Please see man pages for details 763 764 765 766 767 768 769 770 771 772 773 774 775 776 */ 777 nn::Result SetClientCert(const u8* pCertData, size_t certDataSize, const u8* pPrivateKeyData, size_t privateKeyDataSize); 778 779 /* Please see man pages for details 780 781 782 783 784 785 786 787 788 789 790 */ 791 nn::Result SetClientCert( InternalClientCertId inClientCertName ); 792 793 /* Please see man pages for details 794 795 796 797 798 799 800 801 802 803 804 805 */ 806 nn::Result SetClientCert(ClientCert& clientCert); 807 808 809 /* Please see man pages for details 810 811 812 813 814 815 816 817 818 819 820 */ 821 nn::Result GetSslError(s32* pResultCodeBuf) const; 822 823 824 /* Please see man pages for details 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 */ 846 nn::Result SetVerifyOption(u32 verifyOption); 847 848 /* Please see man pages for details 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 */ 869 nn::Result DisableVerifyOptionForDebug( u32 excludeVerifyOptions ); 870 871 /* Please see man pages for details 872 873 874 875 876 877 */ 878 nn::Result SetRootCaDefault( void ) NN_ATTRIBUTE_DEPRECATED; 879 880 /* Please see man pages for details 881 882 883 884 885 886 */ 887 nn::Result SetClientCertDefault( void ) NN_ATTRIBUTE_DEPRECATED; 888 889 /* Please see man pages for details 890 891 892 893 894 895 896 897 898 899 900 901 902 */ 903 nn::Result SetKeepAliveAvailability( bool isUseKeepAlive ); 904 //@} 905 906 907 private: 908 /* Please see man pages for details 909 910 */ 911 ConnectionHandle m_ConnectHandle; 912 913 /* Please see man pages for details 914 915 */ 916 nn::Handle m_privateIpcSession; 917 918 /* Please see man pages for details 919 920 */ 921 mutable ConnectionIpc m_PrivateIpcClient; 922 923 924 /* Please see man pages for details 925 926 927 */ 928 nn::Result SetProxyDefault(void); 929 930 /* Please see man pages for details 931 932 933 */ IsConnected()934 bool IsConnected() const 935 { 936 return (m_ConnectHandle > 0) ? true : false; 937 } 938 939 /* Please see man pages for details 940 941 942 */ 943 Result AssignPrivateIpcClient(); 944 }; 945 946 947 } // end of namespace http 948 } // end of namespace nn 949 950 951 #endif // __cplusplus 952 953 954 955 #include <nn/util/detail/util_CLibImpl.h> 956 957 958 /* Please see man pages for details 959 960 961 962 963 964 965 966 967 */ 968 969 /* Please see man pages for details 970 971 972 973 974 */ 975 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnhttpConnection, nn::http::Connection, 16, u32); 976 977 /* Please see man pages for details 978 979 */ 980 NN_EXTERN_C nnResult nnhttpConnectionInitialize(nnhttpConnection* this_, const char *pUrl, nnHttpRequestMethod method); 981 982 /* Please see man pages for details 983 984 */ 985 NN_EXTERN_C nnResult nnhttpConnectionFinalize(nnhttpConnection* this_); 986 987 /* Please see man pages for details 988 989 */ 990 NN_EXTERN_C nnResult nnhttpConnectionConnect(nnhttpConnection* this_); 991 992 /* Please see man pages for details 993 994 */ 995 NN_EXTERN_C nnResult nnhttpConnectionConnectAsync(nnhttpConnection* this_); 996 997 /* Please see man pages for details 998 999 */ 1000 NN_EXTERN_C nnResult nnhttpConnectionCancel(nnhttpConnection* this_); 1001 1002 /* Please see man pages for details 1003 1004 */ 1005 NN_EXTERN_C nnResult nnhttpConnectionRead(nnhttpConnection* this_, u8* pBodyBuf, u32 bufLen); 1006 1007 /* Please see man pages for details 1008 1009 */ 1010 NN_EXTERN_C nnResult nnhttpConnectionGetStatus(const nnhttpConnection* this_, nnHttpStatus* pStatusBuf); 1011 1012 /* Please see man pages for details 1013 1014 */ 1015 NN_EXTERN_C nnResult nnhttpConnectionGetProgress(const nnhttpConnection* this_, u32* pReceivedLen, u32* pContentLen); 1016 1017 /* Please see man pages for details 1018 1019 */ 1020 NN_EXTERN_C nnResult nnhttpConnectionGetError(const nnhttpConnection* this_, nnHttpResultCode* pResultCodeBuf); 1021 1022 1023 1024 /* Connection settings */ 1025 /* Please see man pages for details 1026 1027 */ 1028 NN_EXTERN_C nnResult nnhttpConnectionSetProxy(nnhttpConnection* this_, const char* pProxyName, u16 port, const char* pUserName, const char* pPassword); 1029 1030 /* Please see man pages for details 1031 1032 */ 1033 NN_EXTERN_C nnResult nnhttpConnectionSetBasicAuthorization(nnhttpConnection* this_, const char *pUserName, const char *pPassword); 1034 1035 /* Please see man pages for details 1036 1037 */ 1038 NN_EXTERN_C nnResult nnhttpConnectionSetSocketBufferSize(nnhttpConnection* this_, u32 size); 1039 1040 1041 /* HTTP request settings */ 1042 /* Please see man pages for details 1043 1044 */ 1045 NN_EXTERN_C nnResult nnhttpConnectionAddHeaderField(nnhttpConnection* this_, const char* pLabel, const char* pValue); 1046 1047 /* Please see man pages for details 1048 1049 */ 1050 NN_EXTERN_C nnResult nnhttpConnectionAddPostDataAscii(nnhttpConnection* this_, const char* pLabel, const char* pValue); 1051 1052 /* Please see man pages for details 1053 1054 */ 1055 NN_EXTERN_C nnResult nnhttpConnectionAddPostDataBinary(nnhttpConnection* this_, const char* pLabel, const char* pValue, u32 length); 1056 1057 /* Please see man pages for details 1058 1059 */ 1060 NN_EXTERN_C nnResult nnhttpConnectionAddPostDataRaw(nnhttpConnection* this_, const char* pValue, u32 length); 1061 1062 /* Please see man pages for details 1063 1064 */ 1065 NN_EXTERN_C nnResult nnhttpConnectionSetLazyPostDataSetting(nnhttpConnection* this_, nnHttpPostDataType dataType); 1066 1067 1068 /* Please see man pages for details 1069 1070 */ 1071 NN_EXTERN_C nnResult nnhttpConnectionNotifyFinishSendPostData(nnhttpConnection* this_); 1072 1073 /* Please see man pages for details 1074 1075 */ 1076 NN_EXTERN_C nnResult nnhttpConnectionSetPostDataEncoding(nnhttpConnection* this_, nnHttpEncodingType type); 1077 1078 /* Please see man pages for details 1079 1080 */ 1081 NN_EXTERN_C nnResult nnhttpConnectionSendPostDataAscii(nnhttpConnection* this_, const char* pLabel, const char* pValue); 1082 1083 /* Please see man pages for details 1084 1085 */ 1086 NN_EXTERN_C nnResult nnhttpConnectionSendPostDataBinary(nnhttpConnection* this_, const char* pLabel, const void* pValue, size_t length); 1087 1088 /* Please see man pages for details 1089 1090 */ 1091 NN_EXTERN_C nnResult nnhttpConnectionSendPostDataRaw(nnhttpConnection* this_, const void* pValue, u32 length); 1092 1093 1094 1095 /* Get HTTP response */ 1096 /* Please see man pages for details 1097 1098 */ 1099 NN_EXTERN_C nnResult nnhttpConnectionGetHeaderField(const nnhttpConnection* this_, const char* pLabel, char* pFieldBuf, size_t bufSize, size_t* pFieldLengthCourier); 1100 1101 /* Please see man pages for details 1102 1103 */ 1104 NN_EXTERN_C nnResult nnhttpConnectionGetHeaderAll(const nnhttpConnection* this_, char* pHeaderBuf, size_t bufSize, size_t* pLengthCourier); 1105 1106 /* Please see man pages for details 1107 1108 */ 1109 NN_EXTERN_C nnResult nnhttpConnectionGetStatusCode(const nnhttpConnection* this_, s32* pStatusCodeCourier); 1110 1111 /* Please see man pages for details 1112 1113 */ 1114 NN_EXTERN_C nnResult nnhttpConnectionGetSslError(const nnhttpConnection* this_, s32* pResultCodeBuf); 1115 1116 /* Please see man pages for details 1117 1118 */ 1119 NN_EXTERN_C nnResult nnhttpConnectionSetVerifyOption(nnhttpConnection* this_, u32 verifyOption); 1120 1121 /* Please see man pages for details 1122 1123 */ 1124 NN_EXTERN_C nnResult nnhttpSetRootCa(nnhttpConnection* this_, const u8 *pCertData, size_t certDataSize); 1125 1126 /* Please see man pages for details 1127 1128 */ 1129 NN_EXTERN_C nnResult nnhttpSetInternalRootCa( nnhttpConnection* this_, NnHttpInternalCaCertId inCaCertName ); 1130 1131 /* Please see man pages for details 1132 1133 */ 1134 NN_EXTERN_C nnResult nnhttpSetRootCaStore( nnhttpConnection* this_, nnhttpCertStore* pCertStore); 1135 1136 /* Please see man pages for details 1137 1138 */ 1139 NN_EXTERN_C nnResult nnhttpSetClientCert(nnhttpConnection* this_, const u8* pCertData, size_t certDataSize, const u8* pPrivateKeyData, size_t privateKeyDataSize); 1140 1141 /* Please see man pages for details 1142 1143 */ 1144 NN_EXTERN_C nnResult nnhttpSetInternalClientCert(nnhttpConnection* this_, NnHttpInternalClientCertId inClientCertName ); 1145 1146 /* Please see man pages for details 1147 1148 */ 1149 NN_EXTERN_C nnResult nnhttpSetClientCertObj(nnhttpConnection* this_, nnhttpClientCert* pClientCert); 1150 1151 1152 1153 1154 /* Please see man pages for details 1155 1156 */ 1157 NN_EXTERN_C nnResult nnhttpDisableVerifyOptionForDebug(nnhttpConnection* this_, u32 verifyOption); 1158 1159 /* 1160 1161 1162 1163 */ 1164 1165 #endif /* NN_HTTP_HTTP_CONNECTION_H_ */ 1166