📄 using.txt
字号:
January 26. 2004Using reSIProcate.ReSIProcate is an object oriented SIP interface and stack implemented inC++. The reSIProcate approach emphasizes consistency, type safety, and ease ofuse. A central component of any SIP service is handling of SIP messages and theirparts. A SIP message consists of headers, request/status line, and body.Headers:=======Headers are accessed from messages with the header method. The header method isoverloaded so that its return value is appopriate for each type of header. Theactual header method is determined by the header type token passed to theoverloaded header method.Each header type defined in RFC3261 has a corresponding header access token. Forexample, the header access tokens for To and From headers are h_To andh_From. The rule for determing the header access token from a header as named inRFC3261 is to remove all dashes from the header name and prefix the result with"h_". For example, "Content-Disposition" becomes h_ContentDisposition.Given a existing message, fetching the To header is simply:<code>const NameAddr& to = message->header(h_To);</code>The header methods are both accessors and setters. Accessing a header that isn'tin the message creates the header in a default state. So to set an empty message'sTo header:<code>SipMessage message;// displayName and uri are accessor/setter methods on NameAddr, the storage class// for To headers.message.header(h_To).displayName() = "Speedy Shannon";message.header(h_To).uri() = Uri("speedy@home.com");</code>The header methods are used also to access existing headers. If you want to makesure that you are accessing an existing header and are not creating a defaultheader, use the exists method. The exists method is overloaded with the sameaccess tokens.<code>SipMessage* message;if (!message->exists(h_To)){ // complain bitterly ...}else{ NameAddr& to = message->header(h_To); ...}</code>However, if the message variable is declared const, the header methods will notcreate a default instance of a missing header, but will throwSipMessage::Exception. This is a typical mode when working with incomingmessages.<code>try{ const SipMessage* message; To::Type& to = message->header(h_To); ...}catch (SipMessage::Exception e){ // complain bitterly ...}</code>The remove method is also overloaded for the access tokens. Removing a headerthat does not exist is a no-op.<code>SipMessage* message = ...;message->remove(h_RecordRoutes);</code>Each header type is either a single instance or multiple instance. For example,the header type To is single instance while the header type Record-Route ismultiple instance. The return types differ accordingly. Multiple instance headers are accessed through a collection of theappropriate header type. As a programming hint, access tokens formultiple headers are pluralized.Similarly, the collection of each header type is named the pluralizedheader type. Below is an example accessing a collection of NameAddrinstances.<code>NameAddrs& rr = message.header(h_RecordRoutes);</code>The collection of header values can be iterated in the usual stl like fashion.<code>for (NameAddrs::iterator i = rr.begin(); i != rr.end(); ++i){ NameAddr& r = *i; ...}</code>All collections of header values support begin, end, empty, size, front, back,push_back, push_front, reverse, and clear. Each collection is specific to theheader type so no casting is necessary.<code>NameAddr na;na.displayName() = "Alice";na.uri() = Uri("sip:alice@company.com");rr.push_back(na);</code>--The request/status lines are special cases of headers. They areaccessed by the header method with the header type tokensh_RequestLine and h_StatusLine. A message may have one or the other ofthese headers but never both. To determine if a message has a RequestLine, use:<code>if (message->isRequest()){ ...}</code>Similarly for Status Line:<code>if (message->isResponse()){ ...}</code>Note that a newly created message has neither a request or status line. Theapplication must add one or the other for the message to be well formed.Body:====A message body is accessed with the getContents method. The returedvalue is of type Contents*, an abstract type. The return value must becast (dynamic_cast is recommended for runtime type safety) to beused. The content type of a message can be determined by examining theContent-Type header of the message. New message contents are created by instantiating an instance of atype derived from Contents. For example, SdpContents. A variety ofcontent types are currently supported, including mulitpart, signed,and Pkcs7. New content types can be created either inside or outsideof the reSIP library (see Creating a New Contents Type).Setting the contents of a message takes care of setting the Content-Type andContent-Length of the message.<code>Pkcs7* pres = new Pkcs7();...message->setContents(pres);</code>Recursive multipart contents are supported. --Every RFC 3261 header has a corresponding access token. However, manyof the headers have identical form. For example. The To and Fromheader values both consist of a display name and a URI. The To andFrom headers are managed programmatically as NameAddr instances. Theclass that manages each header type is responsible for parsing headertext, providing storage and access during the life of the message, andserializing the header value to text for transmission.The table below shows the reSIP types for each of the built in RFCheaders currently supported by reSIP. The reSIP type is the returntype of a SipMessage header call with the access token as itsargument.Table of headers================RFC name reSIP access token reSIP type----------------------------------------------------------------Accept h_Accepts Mimes Accept-Encoding h_AcceptEncodings Tokens Accept-Language h_AcceptLanguages Tokens Alert-Info h_AlertInfos GenericUrisAllow h_Allows Tokens Authentication-Info h_AuthenticationInfos Auths Authorization h_Authorizations Auths Call-ID h_CallID, h_CallId CallID, CallIdCall-Info h_CallInfos GenericUrisContact h_Contacts NameAddrs Content-Disposition h_ContentDisposition Token Content-Encoding h_ContentEncoding Token Content-Language h_ContentLanguages Tokens Content-Length h_ContentLength UInt32Category Content-Type h_ContentType Mime Content-Transfer-Encoding h_ContentTransferEncoding StringCategory CSeq h_CSeq CSeqCategory Date h_Date DateCategory Error-Info h_ErrorInfos GenericUrisExpires h_Expires UInt32CategoryFrom h_From NameAddr In-ReplyTo h_InReplyTo CallID, CallIdMax-Forwards h_MaxForwards UInt32Category MIME-Version h_MIMEVersion TokensMin-Expires h_MinExpires UInt32Category Organization h_Organization StringCategory Priority h_Priority Token Proxy-Authenticate h_ProxyAuthenticates Auths Proxy-Authorization h_ProxyAuthorizations AuthsProxy-Require h_ProxyRequires Tokens Record-Route h_RecordRoutes NameAddrsReply-To h_ReplyTo NameAddr Require h_Requires Tokens Retry-After h_RetryAfter UInt32Category Route h_Routes NameAddrsServer h_Server StringCategory Subject h_Subject StringCategory Supported h_Supporteds TokensTimestamp h_Timestamp StringCategory To h_To NameAddr Unsupported h_Unsupporteds Tokens User-Agent h_UserAgent StringCategory Via h_Vias Vias Warning h_Warnings WarningCategoriesWWW-Authenticate h_WWWAuthenticates Auths(!dlb!: const headers accessors return non-const references -- should have constand non-const versions of all settable accessors)The following table lists each of the reSIP types for managing headers. Acomplete list of accessors is included for each type. Recall that many headersare multi-valued; the return type in the multi-valued cases must be iterated toget to the types shown. Multi-values headers are identified with (*).Table of reSIP header types==========================RequestLine=========== RFC name: Request-Line Description: The first line of a request message. Does not correspond to a header proper but is accessed with the header interface in reSIP. Example: INVITE sip:bob@biloxi.com SIP/2.0 Parts: RFC Name accessor reSIP type settable -------------------------------------------------------------- Request-URI uri() Uri yes Method getMethod() MethodTypes yes Method unknownMethodName() Data yes SIP-Version getSipVersion() Data no RFC Headers: <none>StatusLine========== RFC name: Status-Line Description: The first line of a response message. Does not correspond to a header proper but is accessed with the header interface in reSIP. Example: SIP/2.0 200 OK Parts: RFC Name accessor reSIP type settable -------------------------------------------------------------- Status-Code responseCode() int yes // dlb should be statusCode() SIP-Version getSipVersion() Data no Reason-Phrase reason() Data yes RFC Headers: <none>Auth==== RFC name: challenge Description: Identifies the authentication scheme in a challenge response. Example: Digest-Authenticate: username="Alice", realm="atlanta.com", nonce="84a4cc6f3082121f32b42a2187831a9e", response="7587245234b3434cc3412213e5f113a5432" Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- auth-scheme scheme() Data yes RFC Headers: Authentication-Info Authorization (*) Proxy-Authenticate (*) Proxy-Authorization (*) WWW-Authenticate (*)CSeqCategory============ RFC name: CSeq Description: Places the message in sequence in the call. Example: CSeq: 314159 INVITE Parts: RFC Name accessor reSIP type settable -------------------------------------------------------------- sequence() int yes Method method() MethodTypes yes unknownMethodName() Data no RFC Headers: CSeqCallID====== RFC name: Call-ID Description: Uniquely identifies the call. Example: Call-ID: a84b4c76e66710@pc33.atlanta.com Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- value() Data yes RFC Headers: Call-IDDateCategory============ RFC name: SIP-date Description: Human readable date string. Example: Date: Sat, 13 Nov 2010 23:29:00 GMT Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- wkday dayOfWeek() DayOfWeek yes date1 dayOfMonth int yes month() int yes year() int yes time hour() int yes minute() int yes second() int yes RFC Headers: DateGenericUri ========== RFC name: absoluteURI Description: Non-structured human readable URI. Example: Alert-Info: <http://www.example.com/sounds/moo.wav> Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- uri() Data yes RFC Headers: Alert-Info Call-Info Error-InfoUInt32Category =============== RFC name: 1*DIGIT Description: An integer. Example: Max-Forwards: 70 Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- value() int yes comment comment() Data yes RFC Headers: Content-Length // note: does not permit (comment) Max-Forwards // note: does not permit (comment) Min-Expires // note: does not permit (comment) Retry-AfterExpiresCategory=============== RFC name: Description: Seconds to expiration. Example: Expires: 5 Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- value() int yes RFC Headers: ExpiresMime ============ RFC name: media-type Description: Mime type and sub-type. Example: Content-Type: application/sdp Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- m-type type() Data yes m-subtype subType() Data yes RFC Headers: Accept (*) Content-Type NameAddr ============ RFC name: name-addr Description: URI and display name. Example: To: Bob <sip:bob@biloxi.com> Parts: RFC Name accessor reSIP type settable ---------------------------------------------------------- display-name displayName() Data yes addr-spec uri() Uri yes RFC Headers: Contact (*) From Record-Route (*) Refer-To Referred-By Reply-To Route (*) To StringCategory ==============
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -