Changeset 74250 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Sep 13, 2018 4:33:17 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 125044
- Location:
- trunk/include/iprt/cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restbase.h
r74181 r74250 386 386 */ 387 387 virtual const char *typeName(void) const = 0; 388 389 /**390 * Factory method.391 * @returns Pointer to new object on success, NULL if out of memory.392 */393 typedef DECLCALLBACK(RTCRestObjectBase *) FNCREATEINSTANCE(void);394 /** Pointer to factory method. */395 typedef FNCREATEINSTANCE *PFNCREATEINSTANCE;396 388 397 389 protected: -
trunk/include/iprt/cpp/restclient.h
r74232 r74250 29 29 #include <iprt/http.h> 30 30 #include <iprt/cpp/restbase.h> 31 #include <iprt/cpp/reststringmap.h> 31 32 32 33 … … 463 464 * This may install callbacks and such like. 464 465 * 466 * When overridden, the parent class must always be called. 467 * 465 468 * @returns IPRT status code. 466 469 * @param a_hHttp The HTTP handle to prepare for receiving. 467 * @param a_pppvHdr If a header callback handler is installed, set the value pointed to to NULL. 468 * @param a_pppvBody If a body callback handler is installed, set the value pointed to to NULL. 469 */ 470 virtual int receivePrepare(RTHTTP a_hHttp, void ***a_pppvHdr, void ***a_pppvBody); 470 */ 471 virtual int receivePrepare(RTHTTP a_hHttp); 471 472 472 473 /** … … 478 479 * which case it is possible receivePrepare() wasn't called. 479 480 * 480 * @note Called before consume Headers() and consumeBody().481 * @note Called before consumeBody() but after consumeHeader(). 481 482 */ 482 483 virtual void receiveComplete(int a_rcStatus, RTHTTP a_hHttp); 483 484 484 485 /** 485 * Callback that consumes HTTP headerdata from the server.486 * Callback that consumes HTTP body data from the server. 486 487 * 487 488 * @param a_pchData Body data. 488 489 * @param a_cbData Amount of body data. 489 490 * 490 * @note Called after receiveComplete().. 491 */ 492 virtual void consumeHeaders(const char *a_pchData, size_t a_cbData); 493 494 /** 495 * Callback that consumes HTTP body data from the server. 496 * 497 * @param a_pchData Body data. 498 * @param a_cbData Amount of body data. 499 * 500 * @note Called after consumeHeaders(). 491 * @note Called after consumeHeader(). 501 492 */ 502 493 virtual void consumeBody(const char *a_pchData, size_t a_cbData); … … 559 550 int addError(int a_rc, const char *a_pszFormat, ...); 560 551 561 /** Field flags. */ 562 enum 563 { 564 /** Collection map, name is a prefix followed by '*'. */ 565 kHdrField_MapCollection = RT_BIT_32(24) 566 }; 567 568 /** Header field descriptor. */ 569 typedef struct 570 { 571 /** The header field name. */ 572 const char *pszName; 573 /** The length of the field name.*/ 574 uint32_t cchName; 575 /** Flags, TBD. */ 576 uint32_t fFlags; 577 /** Object factory. */ 578 RTCRestObjectBase::PFNCREATEINSTANCE pfnCreateInstance; 579 } HEADERFIELDDESC; 580 581 /** 582 * Helper that extracts fields from the HTTP headers. 583 * 584 * @param a_paFieldDescs Pointer to an array of field descriptors. 585 * @param a_pappFieldValues Pointer to a parallel array of value pointer pointers. 586 * @param a_cFields Number of field descriptors.. 587 * @param a_pchData The header blob to search. 588 * @param a_cbData The size of the header blob to search. 589 */ 590 void extractHeaderFieldsFromBlob(HEADERFIELDDESC const *a_paFieldDescs, RTCRestObjectBase ***a_pappFieldValues, 591 size_t a_cFields, const char *a_pchData, size_t a_cbData); 592 593 /** 594 * Helper that extracts a header field. 595 * 596 * @retval VINF_SUCCESS 597 * @retval VERR_NOT_FOUND if not found. 598 * @retval VERR_NO_STR_MEMORY 599 * @param a_pszField The header field header name. 600 * @param a_cchField The length of the header field name. 601 * @param a_pchData The header blob to search. 602 * @param a_cbData The size of the header blob to search. 603 * @param a_pStrDst Where to store the header value on successs. 604 */ 605 int extractHeaderFromBlob(const char *a_pszField, size_t a_cchField, const char *a_pchData, size_t a_cbData, 606 RTCString *a_pStrDst); 552 /** 553 * Deserializes a header field value. 554 * 555 * @returns IPRT status code. 556 * @param a_pObj The object to deserialize into. 557 * @param a_pchValue Pointer to the value (not zero terminated). 558 * Not necessarily valid UTF-8! 559 * @param a_cchValue The value length. 560 * @param a_fFlags Flags to pass to fromString(). 561 * @param a_pszErrorTag The error tag (field name). 562 */ 563 int deserializeHeader(RTCRestObjectBase *a_pObj, const char *a_pchValue, size_t a_cchValue, 564 uint32_t a_fFlags, const char *a_pszErrorTag); 565 566 /** 567 * Deserializes a header field value. 568 * 569 * @returns IPRT status code. 570 * @param a_pMap The string map object to deserialize into. 571 * @param a_pchField Pointer to the map field name. (Caller dropped the prefix.) 572 * Not necessarily valid UTF-8! 573 * @param a_cchField Length of field name. 574 * @param a_pchValue Pointer to the value (not zero terminated). 575 * Not necessarily valid UTF-8! 576 * @param a_cchValue The value length. 577 * @param a_fFlags Flags to pass to fromString(). 578 * @param a_pszErrorTag The error tag (field name). 579 */ 580 int deserializeHeaderIntoMap(RTCRestStringMapBase *a_pMap, const char *a_pchField, size_t a_cchField, 581 const char *a_pchValue, size_t a_cchValue, uint32_t a_fFlags, const char *a_pszErrorTag); 607 582 608 583 /** … … 626 601 virtual int unknownField(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE; 627 602 }; 603 604 605 /** 606 * Consumes a header. 607 * 608 * Child classes can override this to pick up their header fields, but must 609 * always call the parent class. 610 * 611 * @returns IPRT status code. 612 * @param a_uMatchWord Match word constructed by RTHTTP_MAKE_HDR_MATCH_WORD 613 * @param a_pchField The field name (not zero terminated). 614 * Not necessarily valid UTF-8! 615 * @param a_cchField The length of the field. 616 * @param a_pchValue The field value (not zero terminated). 617 * @param a_cchValue The length of the value. 618 */ 619 virtual int consumeHeader(uint32_t a_uMatchWord, const char *a_pchField, size_t a_cchField, 620 const char *a_pchValue, size_t a_cchValue); 621 622 private: 623 /** Callback for use with RTHttpSetHeaderCallback. */ 624 static FNRTHTTPHEADERCALLBACK receiveHttpHeaderCallback; 628 625 }; 629 626
Note:
See TracChangeset
for help on using the changeset viewer.