1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: http_Connection.h 4 5 Copyright (C)2009-2011 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 38684 $ 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 // 147 148 //---------------------------------------- 149 // 150 // 151 152 /* Please see man pages for details 153 154 155 156 157 158 159 160 161 */ 162 nn::Result Connect(void); 163 164 /* Please see man pages for details 165 166 167 168 169 170 171 172 173 */ 174 nn::Result ConnectAsync(void); 175 176 /* Please see man pages for details 177 178 179 180 181 182 183 184 */ 185 nn::Result Cancel(void); 186 187 /* Please see man pages for details 188 189 190 191 192 193 194 195 196 */ 197 nn::Result GetStatus(Status* pStatusBuf) const; 198 199 /* Please see man pages for details 200 201 202 203 204 205 206 207 208 */ 209 nn::Result GetError(ResultCode* pResultCodeBuf) const; 210 211 /* Please see man pages for details 212 213 214 215 216 217 218 219 220 221 222 223 */ 224 nn::Result GetProgress(size_t* pReceivedLen, size_t* pContentLen) const; 225 226 // 227 228 //---------------------------------------- 229 // 230 // 231 232 /* Please see man pages for details 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 nn::Result Read(u8* pBodyBuf, size_t bufLen); 272 273 /* Please see man pages for details 274 275 276 277 278 279 280 281 282 283 284 285 286 287 */ 288 nn::Result Read(u8* pBodyBuf, size_t bufLen, const nn::fnd::TimeSpan& timeout); 289 290 291 /* Please see man pages for details 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 nn::Result GetHeaderField(const char* pLabel, char* pFieldBuf, size_t bufSize, size_t* pFieldLengthCourier = NULL) const; 325 326 /* Please see man pages for details 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 */ 343 nn::Result GetHeaderField(const char* pLabel, char* pFieldBuf, size_t bufSize, const nn::fnd::TimeSpan& timeout, size_t* pFieldLengthCourier = NULL) const; 344 345 /* Please see man pages for details 346 347 348 349 350 351 352 353 354 355 356 357 */ 358 nn::Result GetHeaderAll(char* pHeaderBuf, size_t bufSize, size_t* pLengthCourier = NULL) const; 359 360 /* Please see man pages for details 361 362 363 364 365 366 367 368 369 370 371 372 */ 373 nn::Result GetHeaderAll(char* pHeaderBuf, size_t bufSize, const nn::fnd::TimeSpan& timeout, size_t* pLengthCourier = NULL) const; 374 375 /* Please see man pages for details 376 377 378 379 380 381 382 383 */ 384 nn::Result GetStatusCode(s32* pStatusCodeCourier) const; 385 386 /* Please see man pages for details 387 388 389 390 391 392 393 394 395 396 */ 397 nn::Result GetStatusCode(s32* pStatusCodeCourier, const nn::fnd::TimeSpan& timeout) const; 398 399 // 400 401 402 //---------------------------------------- 403 // 404 // 405 406 /* Please see man pages for details 407 408 409 410 411 412 413 414 415 416 417 418 */ 419 nn::Result AddHeaderField(const char* pLabel, const char* pValue); 420 421 422 /* Please see man pages for details 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 nn::Result AddPostDataAscii(const char* pLabel, const char* pValue); 448 449 /* Please see man pages for details 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 nn::Result AddPostDataBinary(const char* pLabel, const void* pValue, size_t valueSize); 475 476 /* Please see man pages for details 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 nn::Result AddPostDataRaw(const void* pValue, size_t valueSize); 503 504 /* Please see man pages for details 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 nn::Result SetLazyPostDataSetting( PostDataType dataType ); 546 547 /* Please see man pages for details 548 549 550 551 552 553 554 555 556 557 558 */ 559 nn::Result NotifyFinishSendPostData( void ); 560 561 /* Please see man pages for details 562 563 564 565 566 567 568 569 570 571 */ 572 nn::Result SetPostDataEncoding(EncodingType type); 573 574 /* Please see man pages for details 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 */ 597 nn::Result SendPostDataAscii(const char* pLabel, const char* pValue); 598 599 /* Please see man pages for details 600 601 602 603 604 605 606 607 608 609 610 611 612 613 */ 614 nn::Result SendPostDataAscii(const char* pLabel, const char* pValue, const nn::fnd::TimeSpan& timeout); 615 616 /* Please see man pages for details 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 nn::Result SendPostDataBinary(const char* pLabel, const void* pValue, size_t valueSize); 642 643 /* Please see man pages for details 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 */ 659 nn::Result SendPostDataBinary(const char* pLabel, const void* pValue, size_t valueSize, const nn::fnd::TimeSpan& timeout); 660 661 /* Please see man pages for details 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 */ 685 nn::Result SendPostDataRaw(const void* pValue, size_t valueSize); 686 687 /* Please see man pages for details 688 689 690 691 692 693 694 695 696 697 698 699 700 701 */ 702 nn::Result SendPostDataRaw(const void* pValue, size_t valueSize, const nn::fnd::TimeSpan& timeout); 703 704 // 705 706 //---------------------------------------- 707 // 708 // 709 710 /* Please see man pages for details 711 712 713 714 715 716 717 718 719 720 721 */ 722 nn::Result SetRootCa(const u8* pCertData, size_t certDataSize); 723 724 /* Please see man pages for details 725 726 727 728 729 730 731 732 733 734 */ 735 nn::Result SetRootCa( InternalCaCertId inCaCertName ); 736 737 /* Please see man pages for details 738 739 740 741 742 743 744 745 746 747 748 */ 749 nn::Result SetRootCaStore(CertStore& certStore); 750 751 752 /* Please see man pages for details 753 754 755 756 757 758 759 760 761 762 763 764 765 766 */ 767 nn::Result SetClientCert(const u8* pCertData, size_t certDataSize, const u8* pPrivateKeyData, size_t privateKeyDataSize); 768 769 /* Please see man pages for details 770 771 772 773 774 775 776 777 778 779 780 */ 781 nn::Result SetClientCert( InternalClientCertId inClientCertName ); 782 783 /* Please see man pages for details 784 785 786 787 788 789 790 791 792 793 794 795 */ 796 nn::Result SetClientCert(ClientCert& clientCert); 797 798 799 /* Please see man pages for details 800 801 802 803 804 805 806 807 808 809 810 */ 811 nn::Result GetSslError(s32* pResultCodeBuf) const; 812 813 814 /* Please see man pages for details 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 */ 836 nn::Result SetVerifyOption(u32 verifyOption); 837 838 /* Please see man pages for details 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 */ 859 nn::Result DisableVerifyOptionForDebug( u32 excludeVerifyOptions ); 860 861 /* Please see man pages for details 862 863 864 865 866 867 */ 868 nn::Result SetRootCaDefault( void ) NN_ATTRIBUTE_DEPRECATED; 869 870 /* Please see man pages for details 871 872 873 874 875 876 */ 877 nn::Result SetClientCertDefault( void ) NN_ATTRIBUTE_DEPRECATED; 878 879 /* Please see man pages for details 880 881 882 883 884 885 886 887 888 889 890 891 892 */ 893 nn::Result SetKeepAliveAvailability( bool isUseKeepAlive ); 894 // 895 896 897 private: 898 /* Please see man pages for details 899 900 */ 901 ConnectionHandle m_ConnectHandle; 902 903 /* Please see man pages for details 904 905 */ 906 nn::Handle m_privateIpcSession; 907 908 /* Please see man pages for details 909 910 */ 911 mutable ConnectionIpc m_PrivateIpcClient; 912 913 914 /* Please see man pages for details 915 916 917 */ 918 nn::Result SetProxyDefault(void); 919 920 /* Please see man pages for details 921 922 923 */ IsConnected()924 bool IsConnected() const 925 { 926 return (m_ConnectHandle > 0) ? true : false; 927 } 928 929 /* Please see man pages for details 930 931 932 */ 933 Result AssignPrivateIpcClient(); 934 }; 935 936 937 } // end of namespace http 938 } // end of namespace nn 939 940 941 #endif // __cplusplus 942 943 944 945 #include <nn/util/detail/util_CLibImpl.h> 946 947 948 /* Please see man pages for details 949 950 951 952 953 954 955 956 957 */ 958 959 /* Please see man pages for details 960 961 962 963 964 */ 965 NN_UTIL_DETAIL_CLIBIMPL_DEFINE_BUFFER_CLASS(nnhttpConnection, nn::http::Connection, 16, u32); 966 967 /* Please see man pages for details 968 969 */ 970 NN_EXTERN_C nnResult nnhttpConnectionInitialize(nnhttpConnection* this_, const char *pUrl, nnHttpRequestMethod method); 971 972 /* Please see man pages for details 973 974 */ 975 NN_EXTERN_C nnResult nnhttpConnectionFinalize(nnhttpConnection* this_); 976 977 /* Please see man pages for details 978 979 */ 980 NN_EXTERN_C nnResult nnhttpConnectionConnect(nnhttpConnection* this_); 981 982 /* Please see man pages for details 983 984 */ 985 NN_EXTERN_C nnResult nnhttpConnectionConnectAsync(nnhttpConnection* this_); 986 987 /* Please see man pages for details 988 989 */ 990 NN_EXTERN_C nnResult nnhttpConnectionCancel(nnhttpConnection* this_); 991 992 /* Please see man pages for details 993 994 */ 995 NN_EXTERN_C nnResult nnhttpConnectionRead(nnhttpConnection* this_, u8* pBodyBuf, u32 bufLen); 996 997 /* Please see man pages for details 998 999 */ 1000 NN_EXTERN_C nnResult nnhttpConnectionGetStatus(const nnhttpConnection* this_, nnHttpStatus* pStatusBuf); 1001 1002 /* Please see man pages for details 1003 1004 */ 1005 NN_EXTERN_C nnResult nnhttpConnectionGetProgress(const nnhttpConnection* this_, u32* pReceivedLen, u32* pContentLen); 1006 1007 /* Please see man pages for details 1008 1009 */ 1010 NN_EXTERN_C nnResult nnhttpConnectionGetError(const nnhttpConnection* this_, nnHttpResultCode* pResultCodeBuf); 1011 1012 1013 1014 /* Connection settings */ 1015 /* Please see man pages for details 1016 1017 */ 1018 NN_EXTERN_C nnResult nnhttpConnectionSetProxy(nnhttpConnection* this_, const char* pProxyName, u16 port, const char* pUserName, const char* pPassword); 1019 1020 /* Please see man pages for details 1021 1022 */ 1023 NN_EXTERN_C nnResult nnhttpConnectionSetBasicAuthorization(nnhttpConnection* this_, const char *pUserName, const char *pPassword); 1024 1025 1026 /* HTTP request settings */ 1027 /* Please see man pages for details 1028 1029 */ 1030 NN_EXTERN_C nnResult nnhttpConnectionAddHeaderField(nnhttpConnection* this_, const char* pLabel, const char* pValue); 1031 1032 /* Please see man pages for details 1033 1034 */ 1035 NN_EXTERN_C nnResult nnhttpConnectionAddPostDataAscii(nnhttpConnection* this_, const char* pLabel, const char* pValue); 1036 1037 /* Please see man pages for details 1038 1039 */ 1040 NN_EXTERN_C nnResult nnhttpConnectionAddPostDataBinary(nnhttpConnection* this_, const char* pLabel, const char* pValue, u32 length); 1041 1042 /* Please see man pages for details 1043 1044 */ 1045 NN_EXTERN_C nnResult nnhttpConnectionAddPostDataRaw(nnhttpConnection* this_, const char* pValue, u32 length); 1046 1047 /* Please see man pages for details 1048 1049 */ 1050 NN_EXTERN_C nnResult nnhttpConnectionSetLazyPostDataSetting(nnhttpConnection* this_, nnHttpPostDataType dataType); 1051 1052 1053 /* Please see man pages for details 1054 1055 */ 1056 NN_EXTERN_C nnResult nnhttpConnectionNotifyFinishSendPostData(nnhttpConnection* this_); 1057 1058 /* Please see man pages for details 1059 1060 */ 1061 NN_EXTERN_C nnResult nnhttpConnectionSetPostDataEncoding(nnhttpConnection* this_, nnHttpEncodingType type); 1062 1063 /* Please see man pages for details 1064 1065 */ 1066 NN_EXTERN_C nnResult nnhttpConnectionSendPostDataAscii(nnhttpConnection* this_, const char* pLabel, const char* pValue); 1067 1068 /* Please see man pages for details 1069 1070 */ 1071 NN_EXTERN_C nnResult nnhttpConnectionSendPostDataBinary(nnhttpConnection* this_, const char* pLabel, const void* pValue, size_t length); 1072 1073 /* Please see man pages for details 1074 1075 */ 1076 NN_EXTERN_C nnResult nnhttpConnectionSendPostDataRaw(nnhttpConnection* this_, const void* pValue, u32 length); 1077 1078 1079 1080 /* Get HTTP response */ 1081 /* Please see man pages for details 1082 1083 */ 1084 NN_EXTERN_C nnResult nnhttpConnectionGetHeaderField(const nnhttpConnection* this_, const char* pLabel, char* pFieldBuf, size_t bufSize, size_t* pFieldLengthCourier); 1085 1086 /* Please see man pages for details 1087 1088 */ 1089 NN_EXTERN_C nnResult nnhttpConnectionGetHeaderAll(const nnhttpConnection* this_, char* pHeaderBuf, size_t bufSize, size_t* pLengthCourier); 1090 1091 /* Please see man pages for details 1092 1093 */ 1094 NN_EXTERN_C nnResult nnhttpConnectionGetStatusCode(const nnhttpConnection* this_, s32* pStatusCodeCourier); 1095 1096 /* Please see man pages for details 1097 1098 */ 1099 NN_EXTERN_C nnResult nnhttpConnectionGetSslError(const nnhttpConnection* this_, s32* pResultCodeBuf); 1100 1101 /* Please see man pages for details 1102 1103 */ 1104 NN_EXTERN_C nnResult nnhttpConnectionSetVerifyOption(nnhttpConnection* this_, u32 verifyOption); 1105 1106 /* Please see man pages for details 1107 1108 */ 1109 NN_EXTERN_C nnResult nnhttpSetRootCa(nnhttpConnection* this_, const u8 *pCertData, size_t certDataSize); 1110 1111 /* Please see man pages for details 1112 1113 */ 1114 NN_EXTERN_C nnResult nnhttpSetInternalRootCa( nnhttpConnection* this_, NnHttpInternalCaCertId inCaCertName ); 1115 1116 /* Please see man pages for details 1117 1118 */ 1119 NN_EXTERN_C nnResult nnhttpSetRootCaStore( nnhttpConnection* this_, nnhttpCertStore* pCertStore); 1120 1121 /* Please see man pages for details 1122 1123 */ 1124 NN_EXTERN_C nnResult nnhttpSetClientCert(nnhttpConnection* this_, const u8* pCertData, size_t certDataSize, const u8* pPrivateKeyData, size_t privateKeyDataSize); 1125 1126 /* Please see man pages for details 1127 1128 */ 1129 NN_EXTERN_C nnResult nnhttpSetInternalClientCert(nnhttpConnection* this_, NnHttpInternalClientCertId inClientCertName ); 1130 1131 /* Please see man pages for details 1132 1133 */ 1134 NN_EXTERN_C nnResult nnhttpSetClientCertObj(nnhttpConnection* this_, nnhttpClientCert* pClientCert); 1135 1136 1137 1138 1139 /* Please see man pages for details 1140 1141 */ 1142 NN_EXTERN_C nnResult nnhttpDisableVerifyOptionForDebug(nnhttpConnection* this_, u32 verifyOption); 1143 1144 /* 1145 1146 1147 1148 */ 1149 1150 #endif /* NN_HTTP_HTTP_CONNECTION_H_ */ 1151