├── LICENSE ├── README.md ├── core ├── CoreLexer.go ├── CoreParser.go ├── Debug.go ├── Host.go ├── HostNameParser.go ├── HostNameParser_test.go ├── HostPort.go ├── Lexer.go ├── LogWriter.go ├── NameValue.go ├── NameValueList.go ├── ParameterNames.go ├── StringTokenizer.go └── Token.go ├── rtp ├── README.md ├── address.go ├── collisionlist.go ├── hostaddress.go ├── ipaddress.go ├── ntptime.go ├── random.go ├── rawpacket.go ├── rtcpapppacket.go ├── rtcpbyepacket.go ├── rtcppacket.go ├── rtp.go ├── rtppacket.go ├── rtptime.go ├── transmissioninfo.go └── transmissionparams.go ├── sdp └── README.md └── sip ├── ClientTransaction.go ├── Dialog.go ├── DialogState.go ├── ListeningPoint.go ├── README.md ├── RequestEvent.go ├── ResponseEvent.go ├── ServerTransaction.go ├── SipListener.go ├── SipProvider.go ├── SipStack.go ├── Timeout.go ├── TimeoutEvent.go ├── Transaction.go ├── TransactionState.go ├── address ├── Address.go ├── AddressFactory.go ├── AddressImpl.go ├── Authority.go ├── Hop.go ├── SipURI.go ├── SipURIImpl.go ├── TelURL.go ├── TelURLImpl.go ├── TelphoneNumber.go ├── URI.go ├── URIImpl.go └── UserInfo.go ├── header ├── AcceptEncodingHeader.go ├── AcceptEncodingImpl.go ├── AcceptEncodingList.go ├── AcceptHeader.go ├── AcceptImpl.go ├── AcceptLanguageHeader.go ├── AcceptLanguageImpl.go ├── AcceptLanguageList.go ├── AcceptList.go ├── AddressHeader.go ├── AddressParametersHeader.go ├── AddressParametersImpl.go ├── AlertInfoHeader.go ├── AlertInfoImpl.go ├── AlertInfoList.go ├── AllowEventsHeader.go ├── AllowEventsImpl.go ├── AllowEventsList.go ├── AllowHeader.go ├── AllowImpl.go ├── AllowList.go ├── AuthenticationHeader.go ├── AuthenticationImpl.go ├── AuthenticationInfoHeader.go ├── AuthenticationInfoImpl.go ├── AuthorizationHeader.go ├── AuthorizationImpl.go ├── CSeqHeader.go ├── CSeqImpl.go ├── CallIdHeader.go ├── CallIdImpl.go ├── CallIdentifier.go ├── CallInfoHeader.go ├── CallInfoImpl.go ├── CallInfoList.go ├── Challenge.go ├── ContactHeader.go ├── ContactImpl.go ├── ContactListImpl.go ├── ContentDispositionHeader.go ├── ContentDispositionImpl.go ├── ContentEncodingHeader.go ├── ContentEncodingImpl.go ├── ContentEncodingList.go ├── ContentLanguageHeader.go ├── ContentLanguageImpl.go ├── ContentLanguageList.go ├── ContentLengthHeader.go ├── ContentLengthImpl.go ├── ContentTypeHeader.go ├── ContentTypeImpl.go ├── DateHeader.go ├── DateImpl.go ├── Encoding.go ├── ErrorInfoHeader.go ├── ErrorInfoImpl.go ├── ErrorInfoList.go ├── EventHeader.go ├── EventImpl.go ├── ExpiresHeader.go ├── ExpiresImpl.go ├── ExtensionHeader.go ├── ExtensionImpl.go ├── ExtensionList.go ├── FromHeader.go ├── FromImpl.go ├── InReplyToHeader.go ├── InReplyToImpl.go ├── InReplyToList.go ├── MaxForwardsHeader.go ├── MaxForwardsImpl.go ├── MediaRange.go ├── MediaType.go ├── MimeVersionHeader.go ├── MimeVersionImpl.go ├── MinExpiresHeader.go ├── MinExpiresImpl.go ├── OptionTag.go ├── OrganizationHeader.go ├── OrganizationImpl.go ├── ParametersHeader.go ├── ParametersImpl.go ├── PriorityHeader.go ├── PriorityImpl.go ├── Protocol.go ├── ProxyAuthenticateHeader.go ├── ProxyAuthenticateImpl.go ├── ProxyAuthenticateList.go ├── ProxyAuthorizationHeader.go ├── ProxyAuthorizationImpl.go ├── ProxyRequireHeader.go ├── ProxyRequireImpl.go ├── ProxyRequireList.go ├── QValue.go ├── RAckHeader.go ├── RAckImpl.go ├── RSeqHeader.go ├── RSeqImpl.go ├── ReasonHeader.go ├── ReasonImpl.go ├── ReasonList.go ├── RecordRouteHeader.go ├── RecordRouteImpl.go ├── RecordRouteList.go ├── ReferToHeader.go ├── ReferToImpl.go ├── ReplyToHeader.go ├── ReplyToImpl.go ├── RequestLine.go ├── RequireHeader.go ├── RequireImpl.go ├── RequireList.go ├── RetryAfterHeader.go ├── RetryAfterImpl.go ├── RouteHeader.go ├── RouteImpl.go ├── RouteList.go ├── SIPHeaderHeader.go ├── SIPHeaderImpl.go ├── SIPHeaderList.go ├── ServerHeader.go ├── ServerImpl.go ├── StatusLine.go ├── SubjectHeader.go ├── SubjectImpl.go ├── SubscriptionStateHeader.go ├── SubscriptionStateImpl.go ├── SupportedHeader.go ├── SupportedImpl.go ├── SupportedList.go ├── TimeStampHeader.go ├── TimeStampImpl.go ├── ToHeader.go ├── ToImpl.go ├── UnsupportedHeader.go ├── UnsupportedImpl.go ├── UnsupportedList.go ├── UserAgentHeader.go ├── UserAgentImpl.go ├── ViaHeader.go ├── ViaImpl.go ├── ViaList.go ├── WWWAuthenticateHeader.go ├── WWWAuthenticateImpl.go ├── WWWAuthenticateList.go ├── WarningHeader.go ├── WarningImpl.go └── WarningList.go ├── message ├── Message.go ├── Request.go ├── Response.go ├── Router.go ├── SIPMessage.go ├── SIPRequest.go ├── SIPResponse.go └── Utils.go └── parser ├── AcceptEncodingParser.go ├── AcceptEncodingParser_test.go ├── AcceptLanguageParser.go ├── AcceptLanguageParser_test.go ├── AcceptParser.go ├── AcceptParser_test.go ├── AddressParametersParser.go ├── AddressParser.go ├── AddressParser_test.go ├── AlertInfoParser.go ├── AlertInfoParser_test.go ├── AllowEventsParser.go ├── AllowEventsParser_test.go ├── AllowParser.go ├── AllowParser_test.go ├── AuthenticationInfoParser.go ├── AuthenticationInfoParser_test.go ├── AuthorizationParser.go ├── AuthorizationParser_test.go ├── CSeqParser.go ├── CSeqParser_test.go ├── CallIdParser.go ├── CallIdParser_test.go ├── CallInfoParser.go ├── CallInfoParser_test.go ├── ChallengeParser.go ├── ContactParser.go ├── ContactParser_test.go ├── ContentDispositionParser.go ├── ContentDispositionParser_test.go ├── ContentEncodingParser.go ├── ContentEncodingParser_test.go ├── ContentLanguageParser.go ├── ContentLanguageParser_test.go ├── ContentLengthParser.go ├── ContentLengthParser_test.go ├── ContentTypeParser.go ├── ContentTypeParser_test.go ├── DateParser.go ├── DateParser_test.go ├── ErrorInfoParser.go ├── ErrorInfoParser_test.go ├── EventParser.go ├── EventParser_test.go ├── ExpiresParser.go ├── ExpiresParser_test.go ├── FromParser.go ├── FromParser_test.go ├── HeaderPareser_test.go ├── HeaderParser.go ├── InReplyToParser.go ├── InReplyToParser_test.go ├── MaxForwardsParser.go ├── MaxForwardsParser_test.go ├── MimeVersionParser.go ├── MimeVersionParser_test.go ├── MinExpiresParser.go ├── MinExpiresParser_test.go ├── OrganizationParser.go ├── OrganizationParser_test.go ├── ParametersParser.go ├── ParseExceptionListener.go ├── ParserFactory.go ├── PriorityParser.go ├── PriorityParser_test.go ├── ProxyAuthenticateParser.go ├── ProxyAuthenticateParser_test.go ├── ProxyAuthorizationParser.go ├── ProxyAuthorizationParser_test.go ├── ProxyRequireParser.go ├── ProxyRequireParser_test.go ├── RAckParser.go ├── RAckParser_test.go ├── RSeqParser.go ├── RSeqParser_test.go ├── ReasonParser.go ├── ReasonParser_test.go ├── RecordRouteParser.go ├── RecordRouteParser_test.go ├── ReferToParser.go ├── ReferToParser_test.go ├── ReplyToParser.go ├── ReplyToParser_test.go ├── RequestLineParser.go ├── RequestLineParser_test.go ├── RequireParser.go ├── RequireParser_test.go ├── RetryAfterParser.go ├── RetryAfterParser_test.go ├── RouteParser.go ├── RouteParser_test.go ├── SIPLexer.go ├── SIPParser.go ├── ServerParser.go ├── ServerParser_test.go ├── StatusLineParser.go ├── StatusLineParser_test.go ├── StringMsgParser.go ├── StringMsgParser_test.go ├── SubjectParser.go ├── SubjectParser_test.go ├── SubscriptionStateParser.go ├── SubscriptionStateParser_test.go ├── SupportedParser.go ├── SupportedParser_test.go ├── TimeStampParser.go ├── TimeStampParser_test.go ├── ToParser.go ├── ToParser_test.go ├── Torture1_test.go ├── Torture2_test.go ├── Torture3_test.go ├── Torture4_test.go ├── Torture5_test.go ├── URLParser.go ├── URLParser_test.go ├── UnsupportedParser.go ├── UnsupportedParser_test.go ├── UserAgentParser.go ├── UserAgentParser_test.go ├── ViaParser.go ├── ViaParser_test.go ├── WWWAuthenticateParser.go ├── WWWAuthenticateParser_test.go ├── WarningParser.go └── WarningParser_test.go /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Rain Liu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GoSIPs 2 | ====== 3 | Go SIP Stack (http://www.GoSIPs.org) 4 | 5 | The objective of GoSIPs is to develop a Golang stack interface and implementation to the Session Initiation Protocol (SIP) that can be used independently or by higher level programming entities and environments. 6 | 7 | 8 | GoSIPs is still in heavy development stage. Currently, SIP Message Parser/Encoder is almost done, but it still need more polish and torture-test. 9 | 10 | -------------------------------------------------------------------------------- /core/Debug.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | /** 4 | * A class to do debug printfs 5 | */ 6 | 7 | type Debugger struct { 8 | Debug bool 9 | ParserDebug bool 10 | } 11 | 12 | var Debug = Debugger{true, false} 13 | 14 | func (this *Debugger) print(s string) { 15 | if this.Debug { 16 | LogWrite.LogMessage(s) 17 | } 18 | } 19 | 20 | func (this *Debugger) println(s string) { 21 | if this.Debug { 22 | LogWrite.LogMessage(s + "\n") 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/HostNameParser_test.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestHostNameParser(t *testing.T) { 8 | var hostNames = []string{"foo.bar.com:1234", 9 | "proxima.chaplin.bt.co.uk", 10 | "129.6.55.181:2345", 11 | ":2345", 12 | } 13 | 14 | for i := 0; i < len(hostNames); i++ { 15 | hnp := NewHostNameParser(hostNames[i]) 16 | if hnp == nil { 17 | t.Fail() 18 | } else { 19 | hp, err := hnp.GetHostPort() 20 | if err != nil { 21 | t.Fail() 22 | } else { 23 | t.Log(hp.String()) 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/Lexer.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | type LexerMap map[string]int 4 | 5 | type Lexer interface { 6 | //StringTokenizer 7 | Consume() 8 | ConsumeK(k int) 9 | HasMoreChars() bool 10 | IsAlpha(ch byte) bool 11 | IsDigit(ch byte) bool 12 | IsHexDigit(ch byte) bool 13 | LookAhead() (byte, error) 14 | LookAheadK(k int) (byte, error) 15 | PeekLine() string 16 | GetLine() string 17 | GetNextTokenByDelim(delim byte) (string, error) 18 | 19 | //Lexer 20 | SetLexerName(lexerName string) 21 | GetLexerName() string 22 | AddKeyword(name string, value int) 23 | AddLexer(lexerName string) LexerMap 24 | ByteStringNoComma() string 25 | ByteStringNoSemicolon() string 26 | CharAsString(ch byte) string 27 | NCharAsString(nchars int) string 28 | Comment() (s string, ParseException error) 29 | CurrentLexer() LexerMap 30 | GetBuffer() string 31 | GetNextId() string 32 | GetNextToken() *Token 33 | GetPtr() int 34 | GetRest() string 35 | GetString(c byte) (s string, ParseException error) 36 | LookupToken(value int) string 37 | MarkInputPosition() int 38 | Match(tok int) (t *Token, ParseException error) 39 | Number() (n int, ParseException error) 40 | PeekNextId() string 41 | PeekNextToken() (*Token, error) 42 | PeekNextTokenK(ntokens int) ([]*Token, error) 43 | QuotedString() (s string, ParseException error) 44 | RewindInputPosition(position int) 45 | SPorHT() 46 | SelectLexer(lexerName string) 47 | StartsId() bool 48 | Ttoken() string 49 | TtokenAllowSpace() string 50 | } 51 | -------------------------------------------------------------------------------- /core/Token.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type Token struct { 8 | tokenValue string 9 | tokenType int 10 | } 11 | 12 | func NewToken(tvalue string, ttype int) *Token { 13 | return &Token{tokenValue: tvalue, tokenType: ttype} 14 | } 15 | 16 | func (this *Token) GetTokenValue() string { 17 | return this.tokenValue 18 | } 19 | func (this *Token) GetTokenType() int { 20 | return this.tokenType 21 | } 22 | func (this *Token) SetTokenValue(tvalue string) { 23 | this.tokenValue = tvalue 24 | } 25 | func (this *Token) SetTokenType(ttype int) { 26 | this.tokenType = ttype 27 | } 28 | 29 | func (this *Token) String() string { 30 | return "tokenValue = " + this.tokenValue + " / tokenType = " + strconv.Itoa(this.tokenType) 31 | } 32 | 33 | func (this *Token) Clone() interface{} { 34 | retval := &Token{} 35 | 36 | retval.tokenType = this.tokenType 37 | retval.tokenValue = this.tokenValue 38 | 39 | return retval 40 | } 41 | -------------------------------------------------------------------------------- /rtp/README.md: -------------------------------------------------------------------------------- 1 | RTP/RTCP Stack 2 | -------------------------------------------------------------------------------- /rtp/address.go: -------------------------------------------------------------------------------- 1 | package rtp 2 | 3 | /** Identifies the actual implementation being used. */ 4 | type AddressType uint8 5 | 6 | const ( 7 | IPv4AddressType AddressType = iota /**< Used by the UDP over IPv4 transmitter. */ 8 | IPv6AddressType /**< Used by the UDP over IPv6 transmitter. */ 9 | HostAddressType /**< A very general type of address, consisting of a port number and a number of bytes representing the host address. */ 10 | UserDefinedAddressType /**< Can be useful for a user-defined transmitter. */ 11 | ) 12 | 13 | /** This class is an abstract class which is used to specify destinations, multicast groups etc. */ 14 | type Address interface { 15 | /** Returns the type of address the actual implementation represents. */ 16 | GetAddressType() AddressType 17 | 18 | /** Creates a copy of the RTPAddress instance. 19 | * Creates a copy of the RTPAddress instance. If \c mgr is not NULL, the 20 | * corresponding memory manager will be used to allocate the memory for the address 21 | * copy. 22 | */ 23 | Clone() Address 24 | 25 | /** Checks if the address \c addr is the same address as the one this instance represents. 26 | * Checks if the address \c addr is the same address as the one this instance represents. 27 | * Implementations must be able to handle a NULL argument. 28 | */ 29 | IsSameAddress(addr Address) bool 30 | 31 | /** Checks if the address \c addr represents the same host as this instance. 32 | * Checks if the address \c addr represents the same host as this instance. Implementations 33 | * must be able to handle a NULL argument. 34 | */ 35 | IsFromSameHost(addr Address) bool 36 | 37 | String() string 38 | } 39 | -------------------------------------------------------------------------------- /rtp/hostaddress.go: -------------------------------------------------------------------------------- 1 | package rtp 2 | 3 | import "fmt" 4 | 5 | /** A very general kind of address consisting of a port number and a number of bytes describing the host address. */ 6 | type HostAddress struct { 7 | host string 8 | port uint16 9 | } 10 | 11 | /** Creates an instance of the class using \c addrlen bytes of \c hostaddress as host identification, 12 | * and using \c port as the port number. */ 13 | func NewHostAddress(host string, port uint16) *HostAddress { 14 | return &HostAddress{host: host, port: port} 15 | } 16 | 17 | /** Sets the host address to the first \c addrlen bytes of \c hostaddress. */ 18 | func (this *HostAddress) SetHost(host string) { 19 | this.host = host 20 | } 21 | 22 | /** Sets the port number to \c port. */ 23 | func (this *HostAddress) SetPort(port uint16) { 24 | this.port = port 25 | } 26 | 27 | /** Returns a pointer to the stored host address. */ 28 | func (this *HostAddress) GetHost() string { 29 | return this.host 30 | } 31 | 32 | /** Returns the port number stored in this instance. */ 33 | func (this *HostAddress) GetPort() uint16 { 34 | return this.port 35 | } 36 | 37 | ///////////////////////////////// 38 | func (this *HostAddress) GetAddressType() AddressType { 39 | return HostAddressType 40 | } 41 | 42 | func (this *HostAddress) IsSameAddress(addr Address) bool { 43 | if addr2, ok := addr.(*HostAddress); ok { 44 | if addr2.host == this.host && addr2.port == this.port { 45 | return true 46 | } 47 | } 48 | return false 49 | } 50 | 51 | func (this *HostAddress) IsFromSameHost(addr Address) bool { 52 | if addr2, ok := addr.(*HostAddress); ok { 53 | if addr2.host == this.host { 54 | return true 55 | } 56 | } 57 | return false 58 | } 59 | 60 | func (this *HostAddress) Clone() Address { 61 | return &HostAddress{host: this.host, port: this.port} 62 | } 63 | 64 | func (this *HostAddress) String() string { 65 | return fmt.Sprintf("%s:%d", this.host, this.port) 66 | } 67 | -------------------------------------------------------------------------------- /rtp/ntptime.go: -------------------------------------------------------------------------------- 1 | package rtp 2 | 3 | const NTPTIMEOFFSET = 2208988800 4 | 5 | /** 6 | * This is a simple wrapper for the most significant word (MSW) and least 7 | * significant word (LSW) of an NTP timestamp. 8 | */ 9 | type NTPTime struct { 10 | msw uint32 11 | lsw uint32 12 | } 13 | 14 | func NewNTPTime(m, l uint32) *NTPTime { 15 | this := &NTPTime{msw: m, lsw: l} 16 | return this 17 | } 18 | 19 | /** Returns the most significant word. */ 20 | func (this *NTPTime) GetMSW() uint32 { 21 | return this.msw 22 | } 23 | 24 | /** Returns the least significant word. */ 25 | func (this *NTPTime) GetLSW() uint32 { 26 | return this.lsw 27 | } 28 | -------------------------------------------------------------------------------- /sdp/README.md: -------------------------------------------------------------------------------- 1 | SDP Stack 2 | -------------------------------------------------------------------------------- /sip/README.md: -------------------------------------------------------------------------------- 1 | SIP Stack 2 | -------------------------------------------------------------------------------- /sip/address/Hop.go: -------------------------------------------------------------------------------- 1 | package address 2 | 3 | /** 4 | * The Hop interface defines a location a request can transit on the way to 5 | * its destination, i.e. a route. It defines the host, port and transport of 6 | * the location. This interface is used to identify locations in the 7 | * {@link Router} interface. 8 | * 9 | * @see Router 10 | * 11 | */ 12 | type Hop interface { 13 | /** 14 | * Returns the host part of this Hop. 15 | * 16 | * @return the string value of the host. 17 | */ 18 | GetHost() string 19 | 20 | /** 21 | * Returns the port part of this Hop. 22 | * 23 | * @return the integer value of the port. 24 | */ 25 | GetPort() int 26 | 27 | /** 28 | * Returns the transport part of this Hop. 29 | * 30 | * @return the string value of the transport. 31 | */ 32 | GetTransport() string 33 | 34 | /** 35 | * This method returns the Hop as a string. 36 | * 37 | * @return the stringified version of the Hop 38 | */ 39 | String() string 40 | } 41 | -------------------------------------------------------------------------------- /sip/address/URI.go: -------------------------------------------------------------------------------- 1 | package address 2 | 3 | import () 4 | 5 | /** 6 | * This class represents a generic URI. This is the base interface for any 7 | * type of URI. These are used in SIP requests to identify the callee and also 8 | * in Contact, From, and To headers. 9 | *

10 | * The generic syntax of URIs is defined in 11 | * RFC 2396. 12 | * 13 | * @see TelURL 14 | * @see SipURI 15 | */ 16 | 17 | type URI interface { // extends Cloneable, Serializable{ 18 | 19 | /** 20 | * Returns the value of the "scheme" of this URI, for example "sip", "sips" 21 | * or "tel". 22 | * 23 | * @return the scheme paramter of the URI 24 | */ 25 | GetScheme() string 26 | 27 | /** 28 | * Creates and returns a deep copy of the URI. This methods must ensure a 29 | * deep copy of the URI, so that when a URI is cloned the URI can be 30 | * modified without effecting the original URI. This provides useful 31 | * functionality for proxying Requests and Responses. This method overrides 32 | * the clone method in java.lang.Object. 33 | * 34 | * @return a deep copy of URI 35 | */ 36 | Clone() interface{} 37 | 38 | /** 39 | * This method determines if this is a URI with a scheme of "sip" or "sips". 40 | * 41 | * @return true if the scheme is "sip" or "sips", false otherwise. 42 | */ 43 | IsSipURI() bool 44 | 45 | /** 46 | * This method returns the URI as a string. 47 | * 48 | * @return String The stringified version of the URI 49 | */ 50 | String() string 51 | } 52 | -------------------------------------------------------------------------------- /sip/address/URIImpl.go: -------------------------------------------------------------------------------- 1 | package address 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | /** Implementation of the URI class. This relies on the 1.4 URI class. 8 | */ 9 | type URIImpl struct { 10 | uriString string 11 | 12 | scheme string 13 | } 14 | 15 | /** Constructor given the URI string 16 | * @param uriString The imbedded URI string. 17 | * @throws URISyntaxException When there is a syntaz error in the imbedded URI. 18 | */ 19 | func NewURIImpl(uriString string) *URIImpl { 20 | i := strings.Index(uriString, ":") 21 | if i > 0 { 22 | return &URIImpl{uriString: uriString, scheme: uriString[0:i]} 23 | } 24 | 25 | return nil 26 | } 27 | 28 | /** Encode the URI. 29 | * @return The encoded URI 30 | */ 31 | func (this *URIImpl) String() string { 32 | return this.uriString 33 | 34 | } 35 | 36 | /** Encode this URI. 37 | * @return The encoded URI 38 | */ 39 | /*func (this *URIImpl) ToString() string { 40 | return this.Encode(); 41 | 42 | }*/ 43 | 44 | /** Overrides the base clone method 45 | * @return The Cloned strucutre, 46 | */ 47 | func (this *URIImpl) Clone() interface{} { 48 | return NewURIImpl(this.uriString) 49 | } 50 | 51 | /** Returns the value of the "scheme" of 52 | * this URI, for example "sip", "sips" or "tel". 53 | * 54 | * @return the scheme paramter of the URI 55 | */ 56 | func (this *URIImpl) GetScheme() string { 57 | return this.scheme 58 | } 59 | 60 | /** This method determines if this is a URI with a scheme of 61 | * "sip" or "sips". 62 | * 63 | * @return true if the scheme is "sip" or "sips", false otherwise. 64 | */ 65 | func (this *URIImpl) IsSipURI() bool { 66 | var uri URI = this 67 | _, ok := uri.(SipURI) 68 | return ok 69 | } 70 | -------------------------------------------------------------------------------- /sip/header/AcceptEncodingHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * This interface represents the Accept-Encoding request-header. 5 | * A client includes an AcceptEncodingHeader in a Request to tell the server 6 | * what coding schemes are acceptable in the Response e.g. compress, gzip. 7 | *

8 | * If an AcceptEncodingHeader is present, and if the server cannot send a 9 | * Response which is acceptable according to the AcceptEncodingHeader, then 10 | * the server should return a Response with a status code of NOT_ACCEPTABLE. 11 | *

12 | * An empty Accept-Encoding header field is permissible, it is equivalent to 13 | * Accept-Encoding: identity, meaning no encoding is permissible. 14 | *

15 | * If no Accept-Encoding header field is present, the server SHOULD assume a 16 | * default value of identity. 17 | *

18 | * For Example:
19 | * Accept-Encoding: gzip 20 | * 21 | */ 22 | type AcceptEncodingHeader interface { 23 | ParametersHeader 24 | Encoding 25 | QValue 26 | } 27 | -------------------------------------------------------------------------------- /sip/header/AcceptEncodingList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * AcceptEncodingList of AccepEncoding headers. 9 | */ 10 | type AcceptEncodingList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** default constructor 15 | */ 16 | func NewAcceptEncodingList() *AcceptEncodingList { 17 | this := &AcceptEncodingList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_ACCEPT_ENCODING) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/AcceptLanguageHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Accept-Language header field is used in requests to indicate the 6 | 7 | * preferred languages for reason phrases, session descriptions, or 8 | 9 | * status responses carried as message bodies in the response. If no 10 | 11 | * Accept-Language header field is present, the server SHOULD assume all 12 | 13 | * languages are acceptable to the client. The q-value is used in a similar 14 | 15 | * manner to AcceptHeader to indicate degrees of preference. 16 | 17 | *

18 | 19 | * For Example:
20 | 21 | * Accept-Language: da, en-gb;q=0.8, en;q=0.7 22 | 23 | * 24 | 25 | * @see AcceptHeader 26 | 27 | */ 28 | 29 | type AcceptLanguageHeader interface { 30 | ParametersHeader 31 | QValue 32 | /** 33 | 34 | * Gets the language value of the AcceptLanguageHeader. 35 | 36 | * 37 | 38 | * @return the language Locale value of this AcceptLanguageHeader 39 | 40 | */ 41 | 42 | GetAcceptLanguage() string 43 | 44 | /** 45 | 46 | * Sets the language parameter of this AcceptLanguageHeader. 47 | 48 | * 49 | 50 | * @param language - the new Locale value of the language of 51 | 52 | * AcceptLanguageHeader 53 | */ 54 | 55 | SetAcceptLanguage(language string) 56 | } 57 | -------------------------------------------------------------------------------- /sip/header/AcceptLanguageList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * AcceptLanguageList: Strings together a list of AcceptLanguage SIPHeaders. 9 | */ 10 | type AcceptLanguageList struct { 11 | SIPHeaderList 12 | } 13 | 14 | func NewAcceptLanguageList() *AcceptLanguageList { 15 | this := &AcceptLanguageList{} 16 | this.SIPHeaderList.super(core.SIPHeaderNames_ACCEPT_LANGUAGE) 17 | return this 18 | } 19 | 20 | func (this *AcceptLanguageList) GetFirst() Header { 21 | retval := this.SIPHeaderList.Front().Value.(Header) 22 | if retval != nil { 23 | return retval 24 | } else { 25 | return NewAcceptLanguage() 26 | } 27 | } 28 | 29 | func (this *AcceptLanguageList) GetLast() Header { 30 | retval := this.SIPHeaderList.Back().Value.(Header) 31 | if retval != nil { 32 | return retval 33 | } else { 34 | return NewAcceptLanguage() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sip/header/AcceptList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * Accept List of SIP headers. 9 | *@see Accept 10 | */ 11 | type AcceptList struct { 12 | SIPHeaderList 13 | } 14 | 15 | /** default constructor 16 | */ 17 | func NewAcceptList() *AcceptList { 18 | this := &AcceptList{} 19 | this.SIPHeaderList.super(core.SIPHeaderNames_ACCEPT) 20 | return this 21 | } 22 | -------------------------------------------------------------------------------- /sip/header/AddressHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/sip/address" 5 | ) 6 | 7 | /** 8 | * This interface represents methods for manipulating Address object 9 | * values for any header that contains a Address value. 10 | *

11 | * When the header field value contains a display name encapsulated in the 12 | * Address, the URI including all URI parameters is enclosed in "<" and ">". 13 | * If no "<" and ">" are present, all parameters after the URI are header 14 | * parameters, not URI parameters. The display name can be tokens, or a 15 | * quoted string, if a larger character set is desired. 16 | * 17 | * @see Address 18 | * @see ContactHeader 19 | * @see FromHeader 20 | * @see RecordRouteHeader 21 | * @see ReplyToHeader 22 | * @see RouteHeader 23 | * @see ToHeader 24 | */ 25 | type AddressHeader interface { 26 | 27 | /** 28 | * Sets the Address parameter of this Address. 29 | * 30 | * @param address - the Address object that represents the new 31 | * address of this Address. 32 | */ 33 | SetAddress(addr address.Address) 34 | 35 | /** 36 | * Gets the address parameter of this Address. 37 | * 38 | * @return the Address of this Address 39 | */ 40 | GetAddress() address.Address 41 | } 42 | -------------------------------------------------------------------------------- /sip/header/AddressParametersHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | type AddressParametersHeader interface { 4 | ParametersHeader 5 | AddressHeader 6 | } 7 | -------------------------------------------------------------------------------- /sip/header/AddressParametersImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/sip/address" 5 | ) 6 | 7 | /** An abstract class for headers that take an address and parameters. 8 | */ 9 | type AddressParameters struct { 10 | Parameters 11 | 12 | addr address.Address 13 | } 14 | 15 | /** Constructor given the name of the header. 16 | */ 17 | func NewAddressParameters(name string) *AddressParameters { 18 | this := &AddressParameters{} 19 | this.Parameters.super(name) 20 | return this 21 | } 22 | 23 | func (this *AddressParameters) super(name string) { 24 | this.Parameters.super(name) 25 | } 26 | 27 | /** get the Address field 28 | * @return the imbedded Address 29 | */ 30 | func (this *AddressParameters) GetAddress() address.Address { 31 | return this.addr 32 | } 33 | 34 | /** set the Address field 35 | * @param address Address to set 36 | */ 37 | func (this *AddressParameters) SetAddress(addr address.Address) { 38 | this.addr = addr 39 | } 40 | -------------------------------------------------------------------------------- /sip/header/AlertInfoHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/sip/address" 5 | ) 6 | 7 | /** 8 | * When present in an INVITE request, the Alert-Info header field 9 | * specifies an alternative ring tone to the UAS. When present in a 180 10 | * (Ringing) response, the Alert-Info header field specifies an 11 | * alternative ringback tone to the UAC. A typical usage is for a proxy 12 | * to insert this header field to provide a distinctive ring feature. 13 | *

14 | * The Alert-Info header field can introduce security risks, which are 15 | * identical to the Call-Info header field risk, see section 20.9 of 16 | * RFC3261. 17 | * In addition, a user SHOULD be able to disable this feature selectively. 18 | * This helps prevent disruptions that could result from the use of this 19 | * header field by untrusted elements. 20 | *

21 | * For Example:
22 | * Alert-Info: 23 | */ 24 | 25 | type AlertInfoHeader interface { 26 | ParametersHeader 27 | 28 | /** 29 | * Sets the AlertInfo of the AlertInfoHeader to the alertInfo 30 | * parameter value. 31 | * 32 | * @param alertInfo the new Alert Info URI of this AlertInfoHeader. 33 | */ 34 | SetAlertInfo(alertInfo address.URI) 35 | 36 | /** 37 | * Returns the AlertInfo value of this AlertInfoHeader. 38 | * 39 | * @return the URI representing the AlertInfo. 40 | */ 41 | GetAlertInfo() address.URI 42 | } 43 | -------------------------------------------------------------------------------- /sip/header/AlertInfoImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "bytes" 5 | "gosips/core" 6 | "gosips/sip/address" 7 | ) 8 | 9 | /** 10 | * AlertInfo SIP Header. 11 | */ 12 | type AlertInfo struct { 13 | Parameters 14 | 15 | /** URI field 16 | */ 17 | uri *address.URIImpl 18 | } 19 | 20 | /** Constructor 21 | */ 22 | func NewAlertInfo() *AlertInfo { 23 | this := &AlertInfo{} 24 | this.Parameters.super(core.SIPHeaderNames_ALERT_INFO) 25 | return this 26 | } 27 | 28 | func (this *AlertInfo) String() string { 29 | return this.headerName + core.SIPSeparatorNames_COLON + 30 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 31 | } 32 | 33 | /** 34 | * Return value encoding in canonical form. 35 | * @return The value of the header in canonical encoding. 36 | */ 37 | func (this *AlertInfo) EncodeBody() string { 38 | var encoding bytes.Buffer 39 | encoding.WriteString(core.SIPSeparatorNames_LESS_THAN) 40 | encoding.WriteString(this.uri.String()) 41 | encoding.WriteString(core.SIPSeparatorNames_GREATER_THAN) 42 | 43 | if this.parameters != nil && this.parameters.Len() > 0 { 44 | encoding.WriteString(core.SIPSeparatorNames_SEMICOLON) 45 | encoding.WriteString(this.parameters.String()) 46 | } 47 | return encoding.String() 48 | 49 | } 50 | 51 | /** 52 | * Set the uri member 53 | * @param u URI to set 54 | */ 55 | func (this *AlertInfo) SetAlertInfo(uri address.URI) { 56 | this.uri = uri.(*address.URIImpl) 57 | } 58 | 59 | /** 60 | * Returns the AlertInfo value of this AlertInfoHeader. 61 | * 62 | * 63 | * 64 | * @return the URI representing the AlertInfo. 65 | * 66 | */ 67 | func (this *AlertInfo) GetAlertInfo() address.URI { 68 | return this.uri 69 | } 70 | -------------------------------------------------------------------------------- /sip/header/AlertInfoList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * AlertInfo Header - there can be several AlertInfo headers. 9 | */ 10 | type AlertInfoList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** default constructor 15 | */ 16 | func NewAlertInfoList() *AlertInfoList { 17 | this := &AlertInfoList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_ALERT_INFO) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/AllowEventsHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import () 4 | 5 | /** 6 | * This interface represents the AllowEvents SIP header, as defined by 7 | * RFC3265, this header is 8 | * not part of RFC3261. 9 | *

10 | * The AllowEventsHeader includes a list of tokens which indicates the event 11 | * packages supported by the client (if sent in a request) or server (if sent 12 | * in a response). In other words, a node sending an AllowEventsHeader is 13 | * advertising that it can process SUBSCRIBE requests and generate NOTIFY 14 | * requests for all of the event packages listed in that header. 15 | *

16 | * Any node implementing one or more event packages SHOULD include an appropriate 17 | * AllowEventsHeader indicating all supported events in all methods which 18 | * initiate dialogs and their responses (such as INVITE) and OPTIONS responses. 19 | * This information is very useful, for example, in allowing user agents to 20 | * render particular interface elements appropriately according to whether the 21 | * events required to implement the features they represent are supported by 22 | * the appropriate nodes. 23 | *

24 | * Note that "Allow-Events" headers MUST NOT be inserted by proxies. 25 | */ 26 | 27 | type AllowEventsHeader interface { 28 | Header 29 | 30 | /** 31 | * Sets the eventType defined in this AllowEventsHeader. 32 | * 33 | * @param eventType - the String defining the method supported 34 | * in this AllowEventsHeader 35 | * @throws ParseException which signals that an error has been reached 36 | * unexpectedly while parsing the Strings defining the eventType supported 37 | */ 38 | SetEventType(eventType string) (ParseException error) 39 | 40 | /** 41 | * Gets the eventType of the AllowEventsHeader. 42 | * 43 | * @return the String object identifing the eventTypes of AllowEventsHeader. 44 | */ 45 | GetEventType() string 46 | } 47 | -------------------------------------------------------------------------------- /sip/header/AllowHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Allow header field lists the set of methods supported by the User Agent 5 | * generating the message. All methods, including ACK and CANCEL, understood 6 | * by the User Agent MUST be included in the list of methods in the Allow header 7 | * field, when present. 8 | * The absence of an Allow header field MUST NOT be interpreted to mean that 9 | * the User Agent sending the message supports no methods. Rather, it implies 10 | * that the User Agent is not providing any information on what methods it 11 | * supports. Supplying an Allow header field in responses to methods other than 12 | * OPTIONS reduces the number of messages needed. 13 | *

14 | * For Example:
15 | * Allow: INVITE, ACK, OPTIONS, CANCEL, BYE 16 | */ 17 | type AllowHeader interface { 18 | Header 19 | 20 | /** 21 | * Sets the method supported by this AllowHeader. 22 | * 23 | * @param method - the String defining the method supported 24 | * in this AllowHeader 25 | * @throws ParseException which signals that an error has been reached 26 | * unexpectedly while parsing the method supported. 27 | */ 28 | SetMethod(method string) (ParseException error) 29 | 30 | /** 31 | * Gets the method of the AllowHeader. Returns null if no method is 32 | * defined in this Allow Header. 33 | * 34 | * @return the string identifing the method of AllowHeader. 35 | */ 36 | GetMethod() string 37 | } 38 | -------------------------------------------------------------------------------- /sip/header/AllowImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | * Allow Header. 10 | */ 11 | type Allow struct { 12 | SIPHeader 13 | 14 | /** method field 15 | */ 16 | method string 17 | } 18 | 19 | /** default constructor 20 | */ 21 | func NewAllow() *Allow { 22 | this := &Allow{} 23 | this.SIPHeader.super(core.SIPHeaderNames_ALLOW) 24 | return this 25 | } 26 | 27 | /** constructor 28 | * @param m String to set 29 | */ 30 | func NewAllowFromString(m string) *Allow { 31 | this := &Allow{} 32 | this.SIPHeader.super(core.SIPHeaderNames_ALLOW) 33 | this.method = m 34 | return this 35 | } 36 | 37 | /** get the method field 38 | * @return String 39 | */ 40 | func (this *Allow) GetMethod() string { 41 | return this.method 42 | } 43 | 44 | /** 45 | * Set the method member 46 | * @param method method to set. 47 | */ 48 | func (this *Allow) SetMethod(method string) (ParseException error) { 49 | if method == "" { 50 | return errors.New("NullPointerException: the method parameter is null") 51 | } 52 | this.method = method 53 | return nil 54 | } 55 | 56 | func (this *Allow) String() string { 57 | return this.headerName + core.SIPSeparatorNames_COLON + 58 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 59 | } 60 | 61 | /** Return body encoded in canonical form. 62 | * @return body encoded as a string. 63 | */ 64 | func (this *Allow) EncodeBody() string { 65 | return this.method 66 | } 67 | -------------------------------------------------------------------------------- /sip/header/AllowList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "container/list" 5 | "errors" 6 | "gosips/core" 7 | ) 8 | 9 | /** 10 | * List of ALLOW headers. The sip message can have multiple Allow headers 11 | * 12 | */ 13 | type AllowList struct { 14 | SIPHeaderList 15 | } 16 | 17 | /** default constructor 18 | */ 19 | func NewAllowList() *AllowList { 20 | this := &AllowList{} 21 | this.SIPHeaderList.super(core.SIPHeaderNames_ALLOW) 22 | return this 23 | } 24 | 25 | /** 26 | * Gets an Iterator of all the methods of the AllowHeader. Returns an empty 27 | * 28 | * Iterator if no methods are defined in this Allow Header. 29 | * 30 | * 31 | * 32 | * @return Iterator of String objects each identifing the methods of 33 | * 34 | * AllowHeader. 35 | * 36 | */ 37 | 38 | func (this *AllowList) GetMethods() *list.List { 39 | ll := list.New() 40 | for e := this.Front(); e != nil; e = e.Next() { 41 | ll.PushBack(e.Value.(*Allow).GetMethod()) 42 | } 43 | return ll 44 | } 45 | 46 | /** 47 | * Sets the methods supported defined by this AllowHeader. 48 | * 49 | * 50 | * 51 | * @param methods - the Iterator of Strings defining the methods supported 52 | * 53 | * in this AllowHeader 54 | * 55 | * @throws ParseException which signals that an error has been reached 56 | * 57 | * unexpectedly while parsing the Strings defining the methods supported. 58 | * 59 | */ 60 | 61 | func (this *AllowList) SetMethods(methods *list.List) (ParseException error) { 62 | 63 | for e := methods.Front(); e != nil; e = e.Next() { 64 | allow := NewAllow() 65 | if str, ok := e.Value.(string); ok { 66 | if ParseException = allow.SetMethod(str); ParseException != nil { 67 | return ParseException 68 | } 69 | } else { 70 | return errors.New("ParseException: the method parameter is not string") 71 | } 72 | 73 | this.PushBack(allow) 74 | } 75 | return nil 76 | } 77 | -------------------------------------------------------------------------------- /sip/header/AuthorizationHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Authorization header is used when a user agent wishes to authenticate 5 | * itself with a server - usually, but not necessarily, after receiving an 6 | * UNAUTHORIZED Response - by including an AuthorizationHeader with the 7 | * Request. The AuthorizationHeader consists of credentials 8 | * containing the authentication information of the user agent for the 9 | * realm of the resource being requested. 10 | *

11 | * This header field, along with Proxy-Authorization, breaks the general 12 | * rules about multiple header field values. Although not a comma- 13 | * separated list, this header field name may be present multiple times, 14 | * and MUST NOT be combined into a single header line. 15 | *

16 | * For Example:
17 | * Authorization: Digest username="Alice", realm="atlanta.com",
18 | * nonce="84a4cc6f3082121f32b42a2187831a9e",
19 | * response="7587245234b3434cc3412213e5f113a5432"
20 | * 21 | * @see Parameters 22 | * @see WWWAuthenticateHeader 23 | * @see ProxyAuthorizationHeader 24 | * 25 | */ 26 | 27 | type AuthorizationHeader interface { 28 | AuthenticationHeader 29 | } 30 | -------------------------------------------------------------------------------- /sip/header/AuthorizationImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * Authorization SIP header. 7 | * 8 | * @see ProxyAuthorization 9 | */ 10 | type Authorization struct { 11 | Authentication 12 | } 13 | 14 | /** Default constructor. 15 | */ 16 | func NewAuthorization() *Authorization { 17 | this := &Authorization{} 18 | this.Authentication.super(core.SIPHeaderNames_AUTHORIZATION) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/CallInfoList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * A list of CallInfo headers (there can be multiple in a message). 9 | */ 10 | type CallInfoList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** Default constructor 15 | */ 16 | func NewCallInfoList() *CallInfoList { 17 | this := &CallInfoList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_CALL_INFO) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/ContactListImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * List of contact headers.ContactLists are also maintained in a hashtable for quick lookup. 9 | */ 10 | type ContactList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** 15 | * Constructor. 16 | */ 17 | func NewContactList() *ContactList { 18 | this := &ContactList{} 19 | this.SIPHeaderList.super(core.SIPHeaderNames_CONTACT) 20 | return this 21 | } 22 | 23 | func (this *ContactList) super(hname string) { 24 | this.SIPHeaderList.super(hname) 25 | } 26 | 27 | /** 28 | * add a new contact header. Store it in the hashtable also 29 | * @param contact -- contact to add to this list. 30 | * @throws IllegalArgumentException if Duplicate Contact for same addr 31 | */ 32 | func (this *ContactList) AddContact(contact ContactHeader) (IllegalArgumentException error) { 33 | // Concatenate my lists. 34 | this.SIPHeaderList.PushBack(contact) 35 | return nil 36 | } 37 | 38 | /** 39 | * make a clone of this contact list. 40 | * @return Object cloned list. 41 | */ 42 | func (this *ContactList) Clone() interface{} { 43 | retval := NewContactList() 44 | for c := this.Front(); c != nil; c = c.Next() { 45 | newc := c.Value.(ContactHeader).Clone().(*Contact) 46 | retval.PushBack(newc) 47 | } 48 | return retval 49 | } 50 | 51 | /** 52 | * Get an array of contact addresses. 53 | * 54 | * @return array of contacts. 55 | * 56 | */ 57 | func (this *ContactList) GetContacts() []ContactHeader { 58 | retval := make([]ContactHeader, this.Len()) 59 | 60 | i := 0 61 | for e := this.Front(); e != nil; e = e.Next() { 62 | nextContact := e.Value.(ContactHeader) 63 | retval[i] = nextContact 64 | i++ 65 | } 66 | return retval 67 | } 68 | -------------------------------------------------------------------------------- /sip/header/ContentEncodingHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * A ContentEncodingHeader is used as a modifier to the "media-type". When 5 | * present, its value indicates what additional content codings have been 6 | * applied to the entity-body, and thus what decoding mechanisms must be 7 | * applied in order to obtain the media-type referenced by the 8 | * ContentTypeHeader. The ContentEncodingHeader is primarily used to allow a 9 | * body to be compressed without losing the identity of its underlying media 10 | * type. 11 | *

12 | * If multiple encodings have been applied to an entity, the ContentEncodings 13 | * must be listed in the order in which they were applied. All content-coding 14 | * values are case-insensitive. Clients MAY apply content encodings to the body 15 | * in requests. A server MAY 16 | * apply content encodings to the bodies in responses. The server MUST only 17 | * use encodings listed in the Accept-Encoding header field in the request. 18 | * If the server is not capable of decoding the body, or does not recognize any 19 | * of the content-coding values, it must send a UNSUPPORTED_MEDIA_TYPE 20 | * Response, listing acceptable encodings in an AcceptEncodingHeader. 21 | * 22 | * @see ContentDispositionHeader 23 | * @see ContentLengthHeader 24 | * @see ContentTypeHeader 25 | * @see ContentLanguageHeader 26 | */ 27 | 28 | type ContentEncodingHeader interface { 29 | Header 30 | Encoding 31 | } 32 | -------------------------------------------------------------------------------- /sip/header/ContentEncodingList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * Content Encoding SIP header List. Keeps a list of ContentEncoding headers 9 | */ 10 | type ContentEncodingList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** Default constructor. 15 | */ 16 | func NewContentEncodingList() *ContentEncodingList { 17 | this := &ContentEncodingList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_CONTENT_ENCODING) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/ContentLanguageHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Content-Language header field is used to indicate the language of the 5 | * message body. 6 | *

7 | * For Example:
8 | * Content-Language: fr 9 | * 10 | * @see ContentDispositionHeader 11 | * @see ContentLengthHeader 12 | * @see ContentEncodingHeader 13 | * @see ContentTypeHeader 14 | * 15 | */ 16 | type ContentLanguageHeader interface { 17 | Header 18 | 19 | /** 20 | * Gets the language value of the ContentLanguageHeader. 21 | * 22 | * @return the Locale value of this ContentLanguageHeader 23 | */ 24 | GetContentLanguage() string 25 | 26 | /** 27 | * Sets the language parameter of this ContentLanguageHeader. 28 | * 29 | * @param language - the new Locale value of the language of 30 | * ContentLanguageHeader 31 | */ 32 | SetContentLanguage(language string) 33 | } 34 | -------------------------------------------------------------------------------- /sip/header/ContentLanguageList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * ContentLanguage list of headers. (Should this be a list?) 9 | */ 10 | type ContentLanguageList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** Default constructor 15 | */ 16 | func NewContentLanguageList() *ContentLanguageList { 17 | this := &ContentLanguageList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_CONTENT_LANGUAGE) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/ContentLengthHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Content-Length header field indicates the size of the message-body, in 6 | 7 | * decimal number of octets, sent to the recipient. Applications SHOULD use 8 | 9 | * this field to indicate the size of the message-body to be transferred, 10 | 11 | * regardless of the media type of the entity. If a stream-based protocol 12 | 13 | * (such as TCP) is used as transport, the header field MUST be used. 14 | 15 | *

16 | 17 | * The size of the message-body does not include the CRLF separating header 18 | 19 | * fields and body. Any Content-Length greater than or equal to zero is a 20 | 21 | * valid value. If no body is present in a message, then the Content-Length 22 | 23 | * header field value MUST be set to zero. 24 | 25 | * 26 | 27 | * @see ContentDispositionHeader 28 | 29 | * @see ContentTypeHeader 30 | 31 | * @see ContentEncodingHeader 32 | 33 | * @see ContentLanguageHeader 34 | 35 | */ 36 | 37 | type ContentLengthHeader interface { 38 | Header 39 | 40 | /** 41 | 42 | * Set content-length of ContentLengthHeader. The content-length must be 43 | 44 | * greater than or equal to zero. 45 | 46 | * 47 | 48 | * @param contentLength the content-length of the message body 49 | 50 | * as a decimal number of octets. 51 | 52 | * @throws InvalidArgumentException if contentLength is less than zero. 53 | 54 | */ 55 | 56 | SetContentLength(contentLength int) (InvalidArgumentException error) 57 | 58 | /** 59 | 60 | * Gets content-length of the message body. 61 | 62 | * 63 | 64 | * @return content-length of the message body as a decimal number of octets. 65 | 66 | */ 67 | 68 | GetContentLength() int 69 | } 70 | -------------------------------------------------------------------------------- /sip/header/ContentTypeHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Content-Type header field indicates the media type of the message-body 5 | * sent to the recipient. The Content-Type header field MUST be present if the 6 | * body is not empty. If the body is empty, and a Content-Type header field is 7 | * present, it indicates that the body of the specific type has zero length 8 | * (for example, an empty audio file). 9 | *

10 | * For Example:
11 | * Content-Type: application/sdp 12 | * 13 | * @see ContentDispositionHeader 14 | * @see ContentLengthHeader 15 | * @see ContentEncodingHeader 16 | * @see ContentLanguageHeader 17 | */ 18 | 19 | type ContentTypeHeader interface { 20 | ParametersHeader 21 | MediaType 22 | } 23 | -------------------------------------------------------------------------------- /sip/header/DateHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "time" 4 | 5 | /** 6 | * The Date header field reflects the time when the request or response is 7 | * first sent. Retransmissions have the same Date header field value as the 8 | * original. The Date header field contains the date and time. Unlike 9 | * HTTP/1.1, SIP only supports the most recent 10 | * RFC 1123 format for dates. 11 | * SIP restricts the time zone in SIP-date to "GMT", while RFC 1123 allows any 12 | * time zone. 13 | *

14 | * The Date header field can be used by simple end systems without a 15 | * battery-backed clock to acquire a notion of current time. However, in its 16 | * GMT form, it requires clients to know their offset from GMT. 17 | *

18 | * Example:
19 | * Date: Sat, 13 Nov 2010 23:29:00 GMT 20 | */ 21 | 22 | type DateHeader interface { 23 | Header 24 | 25 | /** 26 | 27 | * Sets date of DateHeader. The date is repesented by the Calendar object. 28 | 29 | * 30 | 31 | * @param date the Calendar object date of this header. 32 | 33 | */ 34 | 35 | SetDate(date *time.Time) 36 | 37 | /** 38 | 39 | * Gets the date of DateHeader. The date is repesented by the Calender 40 | 41 | * object. 42 | 43 | * 44 | 45 | * @return the Calendar object representing the date of DateHeader 46 | 47 | */ 48 | 49 | GetDate() *time.Time 50 | } 51 | -------------------------------------------------------------------------------- /sip/header/DateImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | "time" 6 | ) 7 | 8 | /** 9 | * Date Header. 10 | */ 11 | type Date struct { 12 | SIPHeader 13 | 14 | /** date field 15 | */ 16 | date *time.Time 17 | } 18 | 19 | /** Default constructor. 20 | */ 21 | func NewDate() *Date { 22 | this := &Date{} 23 | this.SIPHeader.super(core.SIPHeaderNames_DATE) 24 | return this 25 | } 26 | 27 | func (this *Date) String() string { 28 | return this.headerName + core.SIPSeparatorNames_COLON + 29 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 30 | } 31 | 32 | /** Encode the header into a String. 33 | * @return String 34 | */ 35 | func (this *Date) EncodeBody() string { 36 | return this.date.Format(time.RFC1123) 37 | } 38 | 39 | /** 40 | * Set the date member 41 | * @param d SIPDate to set 42 | */ 43 | func (this *Date) SetDate(d *time.Time) { 44 | this.date = d 45 | } 46 | 47 | /** 48 | * Gets the date of DateHeader. The date is repesented by the Calender 49 | * object. 50 | * 51 | * @return the Calendar object representing the date of DateHeader 52 | */ 53 | func (this *Date) GetDate() *time.Time { 54 | return this.date 55 | } 56 | -------------------------------------------------------------------------------- /sip/header/Encoding.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import () 4 | 5 | /** 6 | * This interface represents encoding methods for any header that contains an 7 | * encoding value. 8 | * 9 | * @see AcceptEncodingHeader 10 | * @see ContentEncodingHeader 11 | */ 12 | type Encoding interface { 13 | 14 | /** 15 | * Sets the encoding of an EncodingHeader. 16 | * 17 | * @param encoding - the new string value defining the encoding. 18 | * @throws ParseException which signals that an error has been reached 19 | * unexpectedly while parsing the encoding value. 20 | */ 21 | 22 | SetEncoding(encoding string) (ParseException error) 23 | 24 | /** 25 | * Gets the encoding of an EncodingHeader. Returns null if no 26 | * encoding is defined in an EncodingHeader. 27 | * 28 | * @return the string value identifing the encoding 29 | */ 30 | GetEncoding() string 31 | } 32 | -------------------------------------------------------------------------------- /sip/header/ErrorInfoList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * Error Info sip header. 9 | *@see ErrorInfoList 10 | *

11 | *
12 | * 6.24 Error-Info
13 | *
14 | *   The Error-Info response header provides a pointer to additional
15 | *   information about the error status response. This header field is
16 | *   only contained in 3xx, 4xx, 5xx and 6xx responses.
17 | *
18 | *
19 | *
20 | *       Error-Info  =  "Error-Info" ":" # ( "<" URI ">" *( ";" generic-param ))
21 | *
22 | * 23 | */ 24 | type ErrorInfoList struct { 25 | SIPHeaderList 26 | } 27 | 28 | /** Default constructor. 29 | */ 30 | func NewErrorInfoList() *ErrorInfoList { 31 | this := &ErrorInfoList{} 32 | this.SIPHeaderList.super(core.SIPHeaderNames_ERROR_INFO) 33 | return this 34 | } 35 | -------------------------------------------------------------------------------- /sip/header/ExpiresImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | "strconv" 7 | ) 8 | 9 | /** 10 | * Expires SIP Header. 11 | */ 12 | type Expires struct { 13 | SIPHeader 14 | 15 | /** expires field 16 | */ 17 | expires int 18 | } 19 | 20 | /** default constructor 21 | */ 22 | func NewExpires() *Expires { 23 | this := &Expires{} 24 | this.SIPHeader.super(core.SIPHeaderNames_EXPIRES) 25 | return this 26 | } 27 | 28 | func (this *Expires) String() string { 29 | return this.headerName + core.SIPSeparatorNames_COLON + 30 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 31 | } 32 | 33 | /** 34 | * Return canonical form. 35 | * @return String 36 | */ 37 | func (this *Expires) EncodeBody() string { 38 | return strconv.Itoa(this.expires) 39 | } 40 | 41 | /** 42 | * Gets the expires value of the ExpiresHeader. This expires value is 43 | * 44 | * relative time. 45 | * 46 | * 47 | * 48 | * @return the expires value of the ExpiresHeader. 49 | * 50 | */ 51 | func (this *Expires) GetExpires() int { 52 | return this.expires 53 | } 54 | 55 | /** 56 | * Sets the relative expires value of the ExpiresHeader. 57 | * The expires value MUST be greater than zero and MUST be 58 | * less than 2**31. 59 | * 60 | * @param expires - the new expires value of this ExpiresHeader 61 | * 62 | * @throws InvalidArgumentException if supplied value is less than zero. 63 | * 64 | */ 65 | func (this *Expires) SetExpires(expires int) (InvalidArgumentException error) { 66 | if expires < 0 { 67 | return errors.New("InvalidArgumentException: bad argument") 68 | } 69 | this.expires = expires 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /sip/header/ExtensionHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * This interface represents an Extension SIP header that is not currently 5 | * defined by JAIN SIP. Extension Headers can be added as required by extending 6 | * this interface assuming other endpoints understand the Header. Any Header that 7 | * extends this class must define a "NAME" String constant identifying the name 8 | * of the extension Header. A server must ignore Headers that it does not 9 | * understand. A proxy must not remove or modify Headers that it does not 10 | * understand. 11 | */ 12 | 13 | type ExtensionHeader interface { 14 | Header 15 | 16 | /** 17 | * Sets the value parameter of the ExtensionHeader. 18 | * 19 | * @param value - the new value of the ExtensionHeader 20 | * @throws ParseException which signals that an error has been reached 21 | * unexpectedly while parsing the value parameter. 22 | */ 23 | SetValue(value string) (ParseException error) 24 | 25 | /** 26 | * Gets the value of the ExtensionHeader. 27 | * 28 | * @return the string of the value parameter. 29 | */ 30 | //GetValue() string //redefine in Header 31 | } 32 | -------------------------------------------------------------------------------- /sip/header/ExtensionList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "bytes" 4 | 5 | type ExtensionHeaderLister interface { 6 | SIPHeaderLister 7 | } 8 | 9 | /** 10 | * A generic extension header list. 11 | */ 12 | 13 | type ExtensionHeaderList struct { 14 | SIPHeaderList 15 | } 16 | 17 | func NewExtensionHeaderList(hName string) *ExtensionHeaderList { 18 | this := &ExtensionHeaderList{} 19 | this.SIPHeaderList.super(hName) 20 | return this 21 | } 22 | 23 | func (this *ExtensionHeaderList) String() string { 24 | var encoding bytes.Buffer 25 | for e := this.Front(); e != nil; e = e.Next() { 26 | eh := e.Value.(*Extension) 27 | encoding.WriteString(eh.String()) 28 | } 29 | return encoding.String() 30 | } 31 | -------------------------------------------------------------------------------- /sip/header/InReplyToHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The In-Reply-To header field enumerates the Call-IDs that this call 5 | * references or returns. These Call-IDs may have been cached by the client 6 | * then included in this header field in a return call. 7 | *

8 | * This allows automatic call distribution systems to route return calls to the 9 | * originator of the first call. This also allows callees to filter calls, so 10 | * that only return calls for calls they originated will be accepted. This 11 | * field is not a substitute for request authentication. 12 | *

13 | * For Example:
14 | * In-Reply-To: 70710@saturn.jcp.org, 17320@saturn.jcp.org 15 | */ 16 | type InReplyToHeader interface { 17 | Header 18 | 19 | /** 20 | * Sets the Call-Id of the InReplyToHeader. The CallId parameter uniquely 21 | * identifies a serious of messages within a dialogue. 22 | * 23 | * @param callId - the string value of the Call-Id of this InReplyToHeader. 24 | * @throws ParseException which signals that an error has been reached 25 | * unexpectedly while parsing the callId value. 26 | */ 27 | SetCallId(callId string) (ParseException error) 28 | 29 | /** 30 | * Returns the Call-Id of InReplyToHeader. The CallId parameter uniquely 31 | * identifies a series of messages within a dialogue. 32 | * 33 | * @return the String value of the Call-Id of this InReplyToHeader 34 | */ 35 | GetCallId() string 36 | } 37 | -------------------------------------------------------------------------------- /sip/header/InReplyToList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * In-Reply-To SIP header. Keeps a list of CallIdentifiers 9 | */ 10 | type InReplyToList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** Default constructor 15 | */ 16 | func NewInReplyToList() *InReplyToList { 17 | this := &InReplyToList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_IN_REPLY_TO) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/MediaRange.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * Media Range 9 | * @see Accept 10 | *

11 | * media-range    = ( "STAR/STAR"
12 | *                        | ( type "/" STAR )
13 | *                        | ( type "/" subtype )
14 | *                        ) *( ";" parameter )
15 | *
16 | * HTTP RFC 2616 Section 14.1
17 | * 
18 | */ 19 | type MediaRange struct { 20 | /** type field 21 | */ 22 | mtype string 23 | 24 | /** subtype field 25 | */ 26 | subtype string 27 | } 28 | 29 | /** Default constructor 30 | */ 31 | func NewMediaRange() *MediaRange { 32 | this := &MediaRange{} 33 | return this 34 | } 35 | 36 | /** get type field 37 | * @return String 38 | */ 39 | func (this *MediaRange) GetType() string { 40 | return this.mtype 41 | } 42 | 43 | /** get the subType field. 44 | * @return String 45 | */ 46 | func (this *MediaRange) GetSubtype() string { 47 | return this.subtype 48 | } 49 | 50 | /** 51 | * Set the type member 52 | * @param t String to set 53 | */ 54 | func (this *MediaRange) SetType(t string) { 55 | this.mtype = t 56 | } 57 | 58 | /** 59 | * Set the subtype member 60 | * @param s String to set 61 | */ 62 | func (this *MediaRange) SetSubtype(s string) { 63 | this.subtype = s 64 | } 65 | 66 | /** 67 | * Encode the object. 68 | * @return String 69 | */ 70 | func (this *MediaRange) String() string { 71 | encoding := this.mtype + core.SIPSeparatorNames_SLASH + this.subtype 72 | return encoding 73 | } 74 | -------------------------------------------------------------------------------- /sip/header/MediaType.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import () 4 | 5 | /** 6 | * This interface represents media type methods for any header that contain 7 | * content type and content sub-type values. 8 | * 9 | * @see AcceptHeader 10 | * @see ContentTypeHeader 11 | */ 12 | 13 | type MediaType interface { 14 | 15 | /** 16 | * Sets value of media type of Header with Content Type. 17 | * 18 | * @param contentType - the new string value of the content type 19 | * @throws ParseException which signals that an error has been reached 20 | * unexpectedly while parsing the contentType value. 21 | */ 22 | SetContentType(contentType string) (ParseException error) 23 | 24 | /** 25 | * Gets media type of Header with Content type. 26 | * 27 | * @return media type of Header with Content type. 28 | */ 29 | GetContentType() string 30 | 31 | /** 32 | * Sets value of media subtype of Header with Content sub-type. 33 | * 34 | * @param contentSubType - the new string value of the content sub-type. 35 | * @throws ParseException which signals that an error has been reached 36 | * unexpectedly while parsing the contentSubType value. 37 | */ 38 | SetContentSubType(contentSubType string) (ParseException error) 39 | 40 | /** 41 | * Gets media sub-type of Header with Content sub-type. 42 | * 43 | * @return media sub-type of Header with Content sub-type. 44 | */ 45 | GetContentSubType() string 46 | } 47 | -------------------------------------------------------------------------------- /sip/header/MimeVersionHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * SIP messages MAY include a single MIME-Version general-header field to 5 | * indicate what version of the MIME protocol was used to construct the 6 | * message. Use of the MIME-Version header field indicates that the message is 7 | * in full compliance with the MIME protocol as defined in 8 | * RFC2045. Proxies/gateways 9 | * are responsible for ensuring full compliance (where possible) when exporting 10 | * SIP messages to strict MIME environments. 11 | *

12 | * For Example:
13 | * MIME-Version: 1.0 14 | */ 15 | type MimeVersionHeader interface { 16 | Header 17 | 18 | /** 19 | * Gets the Minor version value of this MimeVersionHeader. 20 | * 21 | * @return the Minor version of this MimeVersionHeader 22 | */ 23 | GetMinorVersion() int 24 | 25 | /** 26 | * Sets the Minor-Version argument of this MimeVersionHeader to the supplied 27 | * minorVersion value. 28 | * 29 | * @param minorVersion - the new minor MIME version 30 | * @throws InvalidArgumentException if the supplied value is less than zero. 31 | */ 32 | SetMinorVersion(minorVersion int) (InvalidArgumentException error) 33 | 34 | /** 35 | * Gets the Major version value of this MimeVersionHeader. 36 | * 37 | * @return the Major version of this MimeVersionHeader 38 | */ 39 | GetMajorVersion() int 40 | 41 | /** 42 | * Sets the Major-Version argument of this MimeVersionHeader to the supplied 43 | * majorVersion value. 44 | * 45 | * @param majorVersion - the new major MIME version 46 | * @throws InvalidArgumentException if the supplied version is less than zero. 47 | */ 48 | SetMajorVersion(majorVersion int) (InvalidArgumentException error) 49 | } 50 | -------------------------------------------------------------------------------- /sip/header/MinExpiresHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Min-Expires header field conveys the minimum refresh interval supported 6 | 7 | * for soft-state elements managed by that server. This includes Contact 8 | 9 | * header fields that are stored by a registrar. The header field contains a 10 | 11 | * decimal integer number of seconds from 0 to (2**32)-1. 12 | 13 | *

14 | 15 | * Allowing the registrar to set the registration interval protects it against 16 | 17 | * excessively frequent registration refreshes while limiting the state that it 18 | 19 | * needs to maintain and decreasing the likelihood of registrations going 20 | 21 | * stale. The expiration interval of a registration is frequently used in the 22 | 23 | * creation of services. An example is a follow-me service, where the user may 24 | 25 | * only be available at a terminal for a brief period. Therefore, registrars 26 | 27 | * should accept brief registrations; a request should only be rejected if the 28 | 29 | * interval is so short that the refreshes would degrade registrar performance. 30 | 31 | *

32 | 33 | * If a User Agent receives a 423 (Interval Too Brief) response to a REGISTER request, 34 | 35 | * it MAY retry the registration after making the expiration interval of all 36 | 37 | * contact addresses in the REGISTER request equal to or greater than the 38 | 39 | * expiration interval within the Min-Expires header field of the 423 40 | 41 | * (Interval Too Brief) response. The Min-Expires header field that states the 42 | 43 | * minimum expiration interval the registrar is willing to honor. 44 | 45 | *

46 | 47 | * For Example:
48 | 49 | * Min-Expires: 60 50 | 51 | */ 52 | 53 | type MinExpiresHeader interface { 54 | ExpiresHeader 55 | } 56 | -------------------------------------------------------------------------------- /sip/header/MinExpiresImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | "strconv" 7 | ) 8 | 9 | /** 10 | * MinExpires SIP Header. 11 | */ 12 | type MinExpires struct { 13 | SIPHeader 14 | 15 | /** expires field 16 | */ 17 | expires int 18 | } 19 | 20 | /** default constructor 21 | */ 22 | func NewMinExpires() *MinExpires { 23 | this := &MinExpires{} 24 | this.SIPHeader.super(core.SIPHeaderNames_MIN_EXPIRES) 25 | return this 26 | } 27 | 28 | func (this *MinExpires) String() string { 29 | return this.headerName + core.SIPSeparatorNames_COLON + 30 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 31 | } 32 | 33 | /** 34 | * Return canonical form. 35 | * @return String 36 | */ 37 | func (this *MinExpires) EncodeBody() string { 38 | return strconv.Itoa(this.expires) 39 | } 40 | 41 | /** 42 | * Gets the expires value of the ExpiresHeader. This expires value is 43 | * 44 | * relative time. 45 | * 46 | * 47 | * 48 | * @return the expires value of the ExpiresHeader. 49 | * 50 | */ 51 | func (this *MinExpires) GetExpires() int { 52 | return this.expires 53 | } 54 | 55 | /** 56 | * Sets the relative expires value of the ExpiresHeader. 57 | * The expires value MUST be greater than zero and MUST be 58 | * less than 2**31. 59 | * 60 | * @param expires - the new expires value of this ExpiresHeader 61 | * 62 | * @throws InvalidArgumentException if supplied value is less than zero. 63 | * 64 | */ 65 | func (this *MinExpires) SetExpires(expires int) (InvalidArgumentException error) { 66 | if expires < 0 { 67 | return errors.New("InvalidArgumentException: bad argument") 68 | } 69 | this.expires = expires 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /sip/header/OptionTag.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * This interface represents methods for manipulating OptionTags 5 | * values for any header that contains an OptionTag value. Option tags are 6 | * unique identifiers used to designate new options (extensions) in SIP. Note 7 | * that these options appear as parameters in those header fields in an 8 | * option-tag = token form. Option tags are defined in standards track RFCs. 9 | * This is a change from past practice, and is instituted to ensure continuing 10 | * multi-vendor interoperability. 11 | * 12 | * @see ProxyRequireHeader 13 | * @see RequireHeader 14 | * @see UnsupportedHeader 15 | * @see SupportedHeader 16 | */ 17 | 18 | type OptionTag interface { 19 | 20 | /** 21 | * Sets the option tag value to the new supplied optionTag 22 | * parameter. 23 | * 24 | * @param optionTag - the new string value of the option tag. 25 | * @throws ParseException which signals that an error has been reached 26 | * unexpectedly while parsing the optionTag value. 27 | */ 28 | SetOptionTag(optionTag string) (ParseException error) 29 | 30 | /** 31 | * Gets the option tag of this OptionTag class. 32 | * 33 | * @return the string that identifies the option tag value. 34 | */ 35 | GetOptionTag() string 36 | } 37 | -------------------------------------------------------------------------------- /sip/header/OrganizationHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The OrganizationHeader conveys the name of the organization to which the 6 | 7 | * entity issuing the Request or Response belongs. It may be used by client 8 | 9 | * software to filter calls. 10 | 11 | */ 12 | 13 | type OrganizationHeader interface { 14 | Header 15 | 16 | /** 17 | 18 | * Sets the organization value of the OrganizationHeader to the 19 | 20 | * organization parameter supplied. 21 | 22 | * 23 | 24 | * @param organization - the new string organization value 25 | 26 | * @throws ParseException which signals that an error has been reached 27 | 28 | * unexpectedly while parsing the organization value. 29 | 30 | */ 31 | 32 | SetOrganization(organization string) (ParseException error) 33 | 34 | /** 35 | 36 | * Gets the organization value of OrganizationHeader. 37 | 38 | * 39 | 40 | * @return organization of OrganizationHeader 41 | 42 | */ 43 | 44 | GetOrganization() string 45 | } 46 | -------------------------------------------------------------------------------- /sip/header/OrganizationImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | *Organization SIP Header. 10 | */ 11 | type Organization struct { 12 | SIPHeader 13 | 14 | /** organization field 15 | */ 16 | organization string 17 | } 18 | 19 | /** Default constructor 20 | */ 21 | func NewOrganization() *Organization { 22 | this := &Organization{} 23 | this.SIPHeader.super(core.SIPHeaderNames_ORGANIZATION) 24 | return this 25 | } 26 | 27 | func (this *Organization) String() string { 28 | return this.headerName + core.SIPSeparatorNames_COLON + 29 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 30 | } 31 | 32 | /** 33 | * Return encoding of value of the header. 34 | * @return String 35 | */ 36 | func (this *Organization) EncodeBody() string { 37 | return this.organization 38 | } 39 | 40 | /** get the organization field. 41 | * @return String 42 | */ 43 | func (this *Organization) GetOrganization() string { 44 | return this.organization 45 | } 46 | 47 | /** 48 | * Set the organization member 49 | * @param o String to set 50 | */ 51 | func (this *Organization) SetOrganization(o string) (ParseException error) { 52 | if o == "" { 53 | return errors.New("NullPointerException: the organization parameter is null") 54 | } 55 | this.organization = o 56 | return nil 57 | } 58 | -------------------------------------------------------------------------------- /sip/header/ParametersHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "container/list" 5 | "gosips/core" 6 | ) 7 | 8 | type ParametersHeader interface { 9 | Header 10 | GetParameter(name string) string 11 | GetParameterValue(name string) string //interface{} TODO 12 | GetParameterNames() *list.List 13 | HasParameters() bool 14 | RemoveParameter(name string) 15 | SetParameter(name, value string) (ParseException error) 16 | SetQuotedParameter(name, value string) 17 | HasParameter(parameterName string) bool 18 | RemoveParameters() 19 | GetParameters() *core.NameValueList 20 | SetParameters(parameters *core.NameValueList) 21 | GetNameValue(parameterName string) *core.NameValue 22 | } 23 | -------------------------------------------------------------------------------- /sip/header/PriorityHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Priority header field indicates the urgency of the request as perceived 6 | 7 | * by the client. The Priority header field describes the priority that the 8 | 9 | * SIP request should have to the receiving human or its agent. For example, 10 | 11 | * it may be factored into decisions about call routing and acceptance. For 12 | 13 | * these decisions, a message containing no Priority header field SHOULD be 14 | 15 | * treated as if it specified a Priority of "Normal". 16 | 17 | *

18 | 19 | * The Priority header field does not influence the use of communications 20 | 21 | * resources such as packet forwarding priority in routers or access to 22 | 23 | * circuits in PSTN gateways. 24 | 25 | *

26 | 27 | * The currently defined priority values are: 28 | 29 | *

40 | 41 | * For Example:
42 | 43 | * Subject: Weekend plans
44 | 45 | * Priority: non-urgent
46 | 47 | */ 48 | 49 | type PriorityHeader interface { 50 | Header 51 | 52 | /** 53 | 54 | * Set priority of PriorityHeader 55 | 56 | * 57 | 58 | * @param priority - the new string priority value 59 | 60 | * @throws ParseException which signals that an error has been reached 61 | 62 | * unexpectedly while parsing the priority value. 63 | 64 | */ 65 | 66 | SetPriority(priority string) (ParseException error) 67 | 68 | /** 69 | 70 | * Gets the string priority value of the PriorityHeader. 71 | 72 | * 73 | 74 | * @return the string priority value of the PriorityHeader 75 | 76 | */ 77 | 78 | GetPriority() string 79 | } 80 | -------------------------------------------------------------------------------- /sip/header/PriorityImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | * the Priority header. 10 | */ 11 | type Priority struct { 12 | SIPHeader 13 | 14 | /** priority field 15 | */ 16 | priority string 17 | } 18 | 19 | /** Default constructor 20 | */ 21 | func NewPriority() *Priority { 22 | this := &Priority{} 23 | this.SIPHeader.super(core.SIPHeaderNames_PRIORITY) 24 | return this 25 | } 26 | 27 | func (this *Priority) String() string { 28 | return this.headerName + core.SIPSeparatorNames_COLON + 29 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 30 | } 31 | 32 | /** 33 | * Encode into canonical form. 34 | * @return String 35 | */ 36 | func (this *Priority) EncodeBody() string { 37 | return this.priority 38 | } 39 | 40 | /** 41 | * get the priority value. 42 | * @return String 43 | */ 44 | func (this *Priority) GetPriority() string { 45 | return this.priority 46 | } 47 | 48 | /** 49 | * Set the priority member 50 | * @param p String to set 51 | */ 52 | func (this *Priority) SetPriority(p string) (ParseException error) { 53 | if p == "" { 54 | return errors.New("NullPointerException: the priority parameter is null") 55 | } 56 | this.priority = p 57 | return nil 58 | } 59 | -------------------------------------------------------------------------------- /sip/header/ProxyAuthenticateImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * Proxy Authenticate SIP (HTTP ) header. 9 | */ 10 | type ProxyAuthenticate struct { 11 | Authentication 12 | } 13 | 14 | /** Default Constructor 15 | */ 16 | func NewProxyAuthenticate() *ProxyAuthenticate { 17 | this := &ProxyAuthenticate{} 18 | this.Authentication.super(core.SIPHeaderNames_PROXY_AUTHENTICATE) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/ProxyAuthenticateList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * List of ProxyAuthenticate headers. 7 | */ 8 | type ProxyAuthenticateList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** Default constructor 13 | */ 14 | func NewProxyAuthenticateList() *ProxyAuthenticateList { 15 | this := &ProxyAuthenticateList{} 16 | this.SIPHeaderList.super(core.SIPHeaderNames_PROXY_AUTHENTICATE) 17 | return this 18 | } 19 | -------------------------------------------------------------------------------- /sip/header/ProxyAuthorizationImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * ProxyAuthorization SIP header. 7 | */ 8 | type ProxyAuthorization struct { 9 | Authentication 10 | } 11 | 12 | /** Default constructor. 13 | */ 14 | func NewProxyAuthorization() *ProxyAuthorization { 15 | this := &ProxyAuthorization{} 16 | this.Authentication.super(core.SIPHeaderNames_PROXY_AUTHORIZATION) 17 | return this 18 | } 19 | -------------------------------------------------------------------------------- /sip/header/ProxyRequireHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Proxy-Require header field is used to indicate proxy-sensitive features 6 | 7 | * that must be supported by the proxy. The Proxy-Require header field contains 8 | 9 | * a list of option tags. Each option tag defines a SIP extension that MUST be 10 | 11 | * understood by the proxy to process the request. Any ProxyRequireHeader 12 | 13 | * features that are not supported by the proxy must be negatively acknowledged 14 | 15 | * by the proxy to the client if not supported. Proxy servers treat this field 16 | 17 | * identically to the RequireHeader. 18 | 19 | *

20 | 21 | * For Example:
22 | 23 | * Proxy-Require: foo 24 | 25 | * 26 | 27 | * @see RequireHeader 28 | 29 | */ 30 | 31 | type ProxyRequireHeader interface { 32 | RequireHeader 33 | } 34 | -------------------------------------------------------------------------------- /sip/header/ProxyRequireImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | * ProxyRequire Header. 10 | */ 11 | type ProxyRequire struct { 12 | SIPHeader 13 | 14 | /** optiontag field 15 | */ 16 | optionTag string 17 | } 18 | 19 | /** Default Constructor 20 | * @param s String to set 21 | */ 22 | func NewProxyRequire() *ProxyRequire { 23 | this := &ProxyRequire{} 24 | this.SIPHeader.super(core.SIPHeaderNames_PROXY_REQUIRE) 25 | return this 26 | } 27 | 28 | /** Constructor 29 | * @param s String to set 30 | */ 31 | func NewProxyRequireFromString(s string) *ProxyRequire { 32 | this := &ProxyRequire{} 33 | this.SIPHeader.super(core.SIPHeaderNames_PROXY_REQUIRE) 34 | this.optionTag = s 35 | return this 36 | } 37 | 38 | func (this *ProxyRequire) String() string { 39 | return this.headerName + core.SIPSeparatorNames_COLON + 40 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 41 | } 42 | 43 | /** 44 | * Encode in canonical form. 45 | * @return String 46 | */ 47 | func (this *ProxyRequire) EncodeBody() string { 48 | return this.optionTag 49 | } 50 | 51 | /** 52 | * Sets the option tag value to the new supplied optionTag 53 | * parameter. 54 | * 55 | * @param optionTag - the new string value of the option tag. 56 | * @throws ParseException which signals that an error has been reached 57 | * unexpectedly while parsing the optionTag value. 58 | */ 59 | func (this *ProxyRequire) SetOptionTag(optionTag string) (ParseException error) { 60 | if optionTag == "" { 61 | return errors.New("NullPointerException: the optionTag parameter is null") 62 | } 63 | this.optionTag = optionTag 64 | return nil 65 | } 66 | 67 | /** 68 | * Gets the option tag of this OptionTag class. 69 | * 70 | * @return the string that identifies the option tag value. 71 | */ 72 | func (this *ProxyRequire) GetOptionTag() string { 73 | return this.optionTag 74 | } 75 | -------------------------------------------------------------------------------- /sip/header/ProxyRequireList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * Proxy Require SIPSIPObject (list of option tags) 7 | */ 8 | type ProxyRequireList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** Default Constructor 13 | */ 14 | func NewProxyRequireList() *ProxyRequireList { 15 | this := &ProxyRequireList{} 16 | this.SIPHeaderList.super(core.SIPHeaderNames_PROXY_REQUIRE) 17 | return this 18 | } 19 | -------------------------------------------------------------------------------- /sip/header/QValue.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | type QValue interface { 4 | 5 | /** 6 | 7 | * Gets q-value of the media-range in AcceptLanguageHeader. A value of 8 | 9 | * -1 indicates theq-value is not set. 10 | 11 | * 12 | 13 | * @return q-value of media-range, -1 if q-value is not set. 14 | 15 | */ 16 | 17 | GetQValue() float32 18 | 19 | /** 20 | 21 | * Sets q-value for media-range in AcceptLanguageHeader. Q-values allow the 22 | 23 | * user to indicate the relative degree of preference for that media-range, 24 | 25 | * using the qvalue scale from 0 to 1. If no q-value is present, the 26 | 27 | * media-range should be treated as having a q-value of 1. 28 | 29 | * 30 | 31 | * @param qValue - the new float value of the q-value 32 | 33 | * @throws InvalidArgumentException if the q parameter value is not between 0 and 1. 34 | 35 | */ 36 | 37 | SetQValue(qValue float32) (InvalidArgumentException error) 38 | 39 | RemoveQValue() 40 | 41 | HasQValue() bool 42 | } 43 | -------------------------------------------------------------------------------- /sip/header/RSeqHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * This interface represents the RSeq header, as defined by 5 | * RFC3262, this 6 | * header is not part of RFC3261. 7 | *

8 | * The RSeq header is used in provisional responses in order to transmit them 9 | * reliably. It contains a single numeric value from 1 to 2**32-1. The value of 10 | * the RSeq in each subsequent reliable provisional response for the same request 11 | * MUST be greater by exactly one. RSeq numbers MUST NOT wrap around. Because 12 | * the initial one is chosen to be less than 2**31 - 1, but the maximum is 13 | * 2**32 - 1, there can be up to 2**31 reliable provisional responses per 14 | * request, which is more than sufficient. As the RSeq numbering space is within 15 | * a single transaction. This means that provisional responses for different 16 | * requests MAY use the same values for the RSeq number. 17 | *

18 | * A server must ignore Headers that it does not understand. A proxy must not 19 | * remove or modify Headers that it does not understand. 20 | */ 21 | 22 | type RSeqHeader interface { 23 | Header 24 | 25 | /** 26 | * Sets the sequence number value of the RSeqHeader of the provisional 27 | * response. The sequence number MUST be expressible as a 32-bit unsigned 28 | * integer and MUST be less than 2**31. 29 | * 30 | * @param sequenceNumber - the new Sequence number of this RSeqHeader 31 | * @throws InvalidArgumentException if supplied value is less than zero. 32 | */ 33 | SetSequenceNumber(sequenceNumber int) (InvalidArgumentException error) 34 | 35 | /** 36 | * Gets the sequence number of this RSeqHeader. 37 | * 38 | * @return the integer value of the Sequence number of the RSeqHeader 39 | */ 40 | GetSequenceNumber() int 41 | } 42 | -------------------------------------------------------------------------------- /sip/header/RSeqImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | "strconv" 7 | ) 8 | 9 | type RSeq struct { 10 | SIPHeader 11 | 12 | sequenceNumber int 13 | } 14 | 15 | /** Creates a new instance of RSeq */ 16 | func NewRSeq() *RSeq { 17 | this := &RSeq{} 18 | this.SIPHeader.super(core.SIPHeaderNames_RSEQ) 19 | return this 20 | } 21 | 22 | /** Gets the sequence number of this RSeqHeader. 23 | * 24 | * @return the integer value of the Sequence number of the RSeqHeader 25 | */ 26 | func (this *RSeq) GetSequenceNumber() int { 27 | return this.sequenceNumber 28 | } 29 | 30 | /** Sets the sequence number value of the RSeqHeader of the provisional 31 | * response. The sequence number MUST be expressible as a 32-bit unsigned 32 | * integer and MUST be less than 2**31. 33 | * 34 | * @param sequenceNumber - the new Sequence number of this RSeqHeader 35 | * @throws InvalidArgumentException if supplied value is less than zero. 36 | */ 37 | func (this *RSeq) SetSequenceNumber(sequenceNumber int) (InvalidArgumentException error) { 38 | if sequenceNumber <= 0 { 39 | return errors.New("InvalidArgumentException: Bad seq number") 40 | } 41 | this.sequenceNumber = sequenceNumber 42 | return nil 43 | } 44 | 45 | func (this *RSeq) String() string { 46 | return this.headerName + core.SIPSeparatorNames_COLON + 47 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 48 | } 49 | 50 | /** Encode the body of this header (the stuff that follows headerName). 51 | * A.K.A headerValue. 52 | */ 53 | func (this *RSeq) EncodeBody() string { 54 | return strconv.Itoa(this.sequenceNumber) 55 | } 56 | -------------------------------------------------------------------------------- /sip/header/ReasonList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * List of Reason headers. 7 | */ 8 | type ReasonList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** Default constructor 13 | */ 14 | func NewReasonList() *ReasonList { 15 | this := &ReasonList{} 16 | this.SIPHeaderList.super(core.SIPHeaderNames_REASON) 17 | return this 18 | } 19 | -------------------------------------------------------------------------------- /sip/header/RecordRouteHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Record-Route header field is inserted by proxies in a request to force 5 | * future requests in the dialog to be routed through the proxy. The 6 | * SipProvider (as opposed to the application) should attach Record-Route 7 | * headers to messages explicitly when forwarding them if necessary. 8 | *

9 | * The RecordRouteHeader is added to a Request by any proxy that insists on being 10 | * in the path of subsequent Requests for the same call leg. It contains 11 | * a globally reachable RequestURI that identifies the proxy server. Each proxy 12 | * server adds its Address URI to the beginning of the list. 13 | *

14 | * The calling user agent client copies the RecordRouteHeaders into 15 | * RouteHeaders of subsequent Requests within the same call leg, reversing the 16 | * order, so that the first entry is closest to the user agent client. If the 17 | * Response contained a ContactHeader field, the calling user agent adds its 18 | * content as the last RouteHeader. Unless this would cause a loop, a client 19 | * must send subsequent Requests for this call leg to the Address URI in the 20 | * first RouteHeader and remove that entry. 21 | *

22 | * Some proxies, such as those controlling firewalls or in an automatic call 23 | * distribution (ACD) system, need to maintain call state and thus need to 24 | * receive any BYE and ACK Requests for the call. 25 | *

26 | * For Example:
27 | * Record-Route: sip:server10.jcp.org;lr, 28 | * sip:bigbox3.duke.jcp.org;lr 29 | * 30 | * @see RouteHeader 31 | * @see AddressHeader 32 | * @see Parameters 33 | */ 34 | type RecordRouteHeader interface { 35 | AddressHeader 36 | ParametersHeader 37 | } 38 | -------------------------------------------------------------------------------- /sip/header/RecordRouteImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "bytes" 5 | "gosips/core" 6 | "gosips/sip/address" 7 | ) 8 | 9 | /** The Request-Route header is added to a request by any proxy that insists on 10 | * being in the path of subsequent requests for the same call leg. 11 | */ 12 | type RecordRoute struct { 13 | AddressParameters 14 | } 15 | 16 | /** constructor 17 | * @param addr address to set 18 | */ 19 | func NewRecordRouteFromAddress(addr address.Address) *RecordRoute { 20 | this := &RecordRoute{} 21 | this.AddressParameters.super(core.SIPHeaderNames_RECORD_ROUTE) 22 | this.addr = addr 23 | return this 24 | } 25 | 26 | /** default constructor 27 | */ 28 | func NewRecordRoute() *RecordRoute { 29 | this := &RecordRoute{} 30 | this.AddressParameters.super(core.SIPHeaderNames_RECORD_ROUTE) 31 | return this 32 | } 33 | 34 | func (this *RecordRoute) String() string { 35 | return this.headerName + core.SIPSeparatorNames_COLON + 36 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 37 | } 38 | 39 | /** Encode into canonical form. 40 | *@return String containing the canonicaly encoded header. 41 | */ 42 | func (this *RecordRoute) EncodeBody() string { 43 | var encoding bytes.Buffer 44 | addr, _ := this.addr.(*address.AddressImpl) 45 | if addr.GetAddressType() == address.ADDRESS_SPEC { 46 | encoding.WriteString(core.SIPSeparatorNames_LESS_THAN) 47 | } 48 | encoding.WriteString(this.addr.String()) 49 | if addr.GetAddressType() == address.ADDRESS_SPEC { 50 | encoding.WriteString(core.SIPSeparatorNames_GREATER_THAN) 51 | } 52 | 53 | if this.parameters != nil && this.parameters.Len() > 0 { 54 | encoding.WriteString(core.SIPSeparatorNames_SEMICOLON) 55 | encoding.WriteString(this.parameters.String()) 56 | } 57 | return encoding.String() 58 | } 59 | -------------------------------------------------------------------------------- /sip/header/RecordRouteList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * RecordRoute List of SIP headers (a collection of Addresses) 7 | */ 8 | type RecordRouteList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** Default constructor 13 | */ 14 | func NewRecordRouteList() *RecordRouteList { 15 | this := &RecordRouteList{} 16 | this.SIPHeaderList.super(core.SIPHeaderNames_RECORD_ROUTE) 17 | return this 18 | } 19 | -------------------------------------------------------------------------------- /sip/header/ReferToHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * This interface represents the ReferTo SIP header, as defined by 5 | * RFC3515, this header is 6 | * not part of RFC3261. 7 | *

8 | * A ReferToHeader only appears in a REFER request. It provides a URL to 9 | * reference. The ReferToHeader field MAY be encrypted as part of end-to-end 10 | * encryption. The resource identified by the Refer-To URI is contacted using 11 | * the normal mechanisms for that URI type. 12 | */ 13 | type ReferToHeader interface { 14 | AddressHeader 15 | ParametersHeader 16 | } 17 | -------------------------------------------------------------------------------- /sip/header/ReferToImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "bytes" 5 | "gosips/core" 6 | "gosips/sip/address" 7 | ) 8 | 9 | /** 10 | *ReferTo SIP Header. 11 | */ 12 | 13 | type ReferTo struct { 14 | AddressParameters 15 | } 16 | 17 | /** default Constructor. 18 | */ 19 | func NewReferTo() *ReferTo { 20 | this := &ReferTo{} 21 | this.AddressParameters.super(core.SIPHeaderNames_REFER_TO) 22 | return this 23 | } 24 | 25 | func (this *ReferTo) String() string { 26 | return this.headerName + core.SIPSeparatorNames_COLON + 27 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 28 | } 29 | 30 | /** 31 | * Encode the header content into a String. 32 | * @return String 33 | */ 34 | func (this *ReferTo) EncodeBody() string { 35 | var encoding bytes.Buffer 36 | addr, _ := this.addr.(*address.AddressImpl) 37 | if addr.GetAddressType() == address.ADDRESS_SPEC { 38 | encoding.WriteString(core.SIPSeparatorNames_LESS_THAN) 39 | } 40 | encoding.WriteString(this.addr.String()) 41 | if addr.GetAddressType() == address.ADDRESS_SPEC { 42 | encoding.WriteString(core.SIPSeparatorNames_GREATER_THAN) 43 | } 44 | 45 | if this.parameters != nil && this.parameters.Len() > 0 { 46 | encoding.WriteString(core.SIPSeparatorNames_SEMICOLON) 47 | encoding.WriteString(this.parameters.String()) 48 | } 49 | return encoding.String() 50 | } 51 | -------------------------------------------------------------------------------- /sip/header/ReplyToHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Reply-To header field contains a logical return URI that may be 6 | 7 | * different from the From header field. For example, the URI MAY be used to 8 | 9 | * return missed calls or unestablished sessions. If the user wished to remain 10 | 11 | * anonymous, the header field SHOULD either be omitted from the request or 12 | 13 | * populated in such a way that does not reveal any private information. 14 | 15 | *

16 | 17 | * For Example:
18 | 19 | * Reply-To: Bob sip:bob@biloxi.com 20 | 21 | * 22 | 23 | * @see AddressHeader 24 | 25 | * @see Parameters 26 | 27 | */ 28 | 29 | type ReplyToHeader interface { 30 | AddressHeader 31 | ParametersHeader 32 | } 33 | -------------------------------------------------------------------------------- /sip/header/RequireHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Require header field is used by UACs to tell UASs about options that 6 | 7 | * the UAC expects the UAS to support in order to process the request. 8 | 9 | * Although an optional header field, the Require MUST NOT be ignored if it 10 | 11 | * is present. 12 | 13 | *

14 | 15 | * The Require header field contains a list of option tags. Each option tag 16 | 17 | * defines a SIP extension that MUST be understood to process the request. 18 | 19 | * Frequently, this is used to indicate that a specific set of extension 20 | 21 | * header fields need to be understood. A UAC compliant to this specification 22 | 23 | * MUST only include option tags corresponding to standards-track RFCs. 24 | 25 | *

26 | 27 | * If a server does not understand the option, it must respond by returning a 28 | 29 | * BAD_EXTENSION Response and list those options it does not understand in 30 | 31 | * the UnsupportedHeader. 32 | 33 | *

34 | 35 | * Proxy and redirect servers must ignore features that are not understood. If 36 | 37 | * a particular extension requires that intermediate devices support it, the 38 | 39 | * extension must be tagged in the ProxyRequireHeader as well. 40 | 41 | *

42 | 43 | * For Example:
44 | 45 | * Require: 100rel 46 | 47 | * 48 | 49 | * @see ProxyRequireHeader 50 | 51 | * @see OptionTag 52 | 53 | */ 54 | 55 | type RequireHeader interface { 56 | OptionTag 57 | Header 58 | } 59 | -------------------------------------------------------------------------------- /sip/header/RequireImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | *Require SIP Header. 10 | */ 11 | type Require struct { 12 | SIPHeader 13 | 14 | /** optionTag field 15 | */ 16 | optionTag string 17 | } 18 | 19 | /** Default constructor 20 | * @param s String to set 21 | */ 22 | func NewRequire() *Require { 23 | this := &Require{} 24 | this.SIPHeader.super(core.SIPHeaderNames_REQUIRE) 25 | return this 26 | } 27 | 28 | /** constructor 29 | * @param s String to set 30 | */ 31 | func NewRequireFromString(s string) *Require { 32 | this := &Require{} 33 | this.SIPHeader.super(core.SIPHeaderNames_REQUIRE) 34 | this.optionTag = s 35 | return this 36 | } 37 | 38 | func (this *Require) String() string { 39 | return this.headerName + core.SIPSeparatorNames_COLON + 40 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 41 | } 42 | 43 | /** 44 | * Encode in canonical form. 45 | * @return String 46 | */ 47 | func (this *Require) EncodeBody() string { 48 | return this.optionTag 49 | } 50 | 51 | /** 52 | * Sets the option tag value to the new supplied optionTag 53 | * parameter. 54 | * 55 | * @param optionTag - the new string value of the option tag. 56 | * @throws ParseException which signals that an error has been reached 57 | * unexpectedly while parsing the optionTag value. 58 | */ 59 | func (this *Require) SetOptionTag(optionTag string) (ParseException error) { 60 | if optionTag == "" { 61 | return errors.New("NullPointerException: the optionTag parameter is null") 62 | } 63 | this.optionTag = optionTag 64 | return nil 65 | } 66 | 67 | /** 68 | * Gets the option tag of this OptionTag class. 69 | * 70 | * @return the string that identifies the option tag value. 71 | */ 72 | func (this *Require) GetOptionTag() string { 73 | return this.optionTag 74 | } 75 | -------------------------------------------------------------------------------- /sip/header/RequireList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * List of Require headers. 7 | *

 8 | * Require  =  "Require" ":" 1#option-tag
 9 | * 
10 | */ 11 | type RequireList struct { 12 | SIPHeaderList 13 | } 14 | 15 | /** Default constructor 16 | */ 17 | func NewRequireList() *RequireList { 18 | this := &RequireList{} 19 | this.SIPHeaderList.super(core.SIPHeaderNames_REQUIRE) 20 | return this 21 | } 22 | -------------------------------------------------------------------------------- /sip/header/RouteHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Route header field is used to force routing for a request through the 5 | * listed set of proxies. Each host removes the first entry and then proxies 6 | * the Request to the host listed in that entry using it as the RequestURI. 7 | *

8 | * Explicit Route assignment (if needed) for the initial dialog establishment 9 | * is the applications responsibility, but once established Routes are 10 | * maintained by the dialog layer and should not be manupulated by the 11 | * application. For example the SipProvider queries the dialog for Route 12 | * assignment and adds these to the outgoing message as needed. The 13 | * {@link javax.sip.address.Router} may be used by the application to determine 14 | * the initial Route of the message. 15 | * 16 | * @see RecordRouteHeader 17 | * @see AddressHeader 18 | * @see Parameters 19 | * 20 | */ 21 | type RouteHeader interface { 22 | AddressHeader 23 | ParametersHeader 24 | } 25 | -------------------------------------------------------------------------------- /sip/header/RouteList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * A list of Route Headers. 7 | */ 8 | type RouteList struct { 9 | SIPHeaderList 10 | 11 | //private HashSet routeSet; 12 | } 13 | 14 | /** default constructor 15 | */ 16 | func NewRouteList() *RouteList { 17 | this := &RouteList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_ROUTE) 19 | //this.routeSet = new HashSet(); 20 | return this 21 | } 22 | 23 | // public boolean add(Object rh) { 24 | // if (! routeSet.contains(rh) ) { 25 | // this.routeSet.add(rh); 26 | // return super.add(rh); 27 | // } else return false; 28 | // } 29 | 30 | /** Constructor 31 | * @param sip SIPObjectList to set 32 | */ 33 | // public RouteList (SIPObjectList sip) { 34 | // super(sip, RouteHeader.NAME); 35 | // } 36 | 37 | /** 38 | * Order is important when comparing route lists. 39 | */ 40 | // public boolean equals(Object other) { 41 | // if (!(other instanceof RouteList)) return false; 42 | // RouteList that = (RouteList) other; 43 | // if (this.size() != that.size()) return false; 44 | // ListIterator it = this.listIterator(); 45 | // ListIterator it1 = that.listIterator(); 46 | // while (it.hasNext()) { 47 | // Route route = (Route) it.next(); 48 | // Route route1 = (Route) it1.next(); 49 | // if (! route.equals(route1)) return false; 50 | // } 51 | // return true; 52 | // } 53 | -------------------------------------------------------------------------------- /sip/header/ServerHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "container/list" 4 | 5 | /** 6 | * The Server header field contains information about the software used by 7 | * the UAS to handle the request. Revealing the specific software version of 8 | * the server might allow the server to become more vulnerable to attacks 9 | * against software that is known to contain security holes. Implementers 10 | * SHOULD make the Server header field a configurable option. If the Response 11 | * is being forwarded through a proxy, the proxy application must not modify 12 | * the ServerHeaders. Instead, it should include a ViaHeader. 13 | *

14 | * For Example:
15 | * Server: HomeServer v2 16 | * 17 | * @see ViaHeader 18 | * @see UserAgentHeader 19 | */ 20 | type ServerHeader interface { 21 | Header 22 | 23 | /** 24 | * Returns a ListIterator over the List of product values. 25 | * 26 | * @return a ListIterator over the List of strings identifying the 27 | * software of this ServerHeader 28 | */ 29 | GetProduct() *list.List 30 | 31 | /** 32 | * Sets the List of product values of the ServerHeader. 33 | * 34 | * @param product - a List of Strings specifying the product values 35 | * @throws ParseException which signals that an error has been reached 36 | * unexpectedly while parsing the List of product value strings. 37 | */ 38 | SetProduct(product *list.List) (ParseException error) 39 | } 40 | -------------------------------------------------------------------------------- /sip/header/SubjectHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Subject header field provides a summary or indicates the nature of the 6 | 7 | * call, allowing call filtering without having to parse the session 8 | 9 | * description. The session description does not have to use the same subject 10 | 11 | * indication as the invitation. 12 | 13 | *

14 | 15 | * For Example:
16 | 17 | * Subject: Where is the Moscone? 18 | 19 | */ 20 | 21 | type SubjectHeader interface { 22 | Header 23 | 24 | /** 25 | 26 | * Sets the subject value of the SubjectHeader to the supplied string 27 | 28 | * subject value. 29 | 30 | * 31 | 32 | * @param subject - the new subject value of this header. 33 | 34 | * @throws ParseException which signals that an error has been reached 35 | 36 | * unexpectedly while parsing the subject value. 37 | 38 | */ 39 | 40 | SetSubject(subject string) (ParseException error) 41 | 42 | /** 43 | 44 | * Gets the subject value of SubjectHeader. 45 | 46 | * 47 | 48 | * @return subject of SubjectHeader. 49 | 50 | */ 51 | 52 | GetSubject() string 53 | } 54 | -------------------------------------------------------------------------------- /sip/header/SubjectImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | *Supported SIP Header. 10 | */ 11 | type Subject struct { 12 | SIPHeader 13 | 14 | /** subject field 15 | */ 16 | subject string 17 | } 18 | 19 | /** Default Constructor. 20 | */ 21 | func NewSubject() *Subject { 22 | this := &Subject{} 23 | this.SIPHeader.super(core.SIPHeaderNames_SUBJECT) 24 | return this 25 | } 26 | 27 | func (this *Subject) String() string { 28 | return this.headerName + core.SIPSeparatorNames_COLON + 29 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 30 | } 31 | 32 | /** 33 | * Generate the canonical form. 34 | * @return String. 35 | */ 36 | func (this *Subject) EncodeBody() string { 37 | return this.subject 38 | } 39 | 40 | /** 41 | 42 | * Sets the subject value of the SubjectHeader to the supplied string 43 | 44 | * subject value. 45 | 46 | * 47 | 48 | * @param subject - the new subject value of this header 49 | 50 | * @throws ParseException which signals that an error has been reached 51 | 52 | * unexpectedly while parsing the subject value. 53 | 54 | */ 55 | 56 | func (this *Subject) SetSubject(subject string) (ParseException error) { 57 | if subject == "" { 58 | return errors.New("NullPointerException: the subject parameter is null") 59 | } 60 | this.subject = subject 61 | return nil 62 | } 63 | 64 | /** 65 | 66 | * Gets the subject value of SubjectHeader 67 | 68 | * 69 | 70 | * @return subject of SubjectHeader 71 | 72 | */ 73 | 74 | func (this *Subject) GetSubject() string { 75 | return this.subject 76 | } 77 | -------------------------------------------------------------------------------- /sip/header/SupportedHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | 5 | * The Supported header field enumerates all the extensions supported by 6 | 7 | * the UAC or UAS. The Supported header field contains a list of option tags, 8 | 9 | * that are understood by the UAC or UAS. A User Agent compliant to this specification 10 | 11 | * MUST only include option tags corresponding to standards-track RFCs. If 12 | 13 | * empty, it means that no extensions are supported. 14 | 15 | *

16 | 17 | * For Example:
18 | 19 | * Supported: 100rel 20 | 21 | * 22 | 23 | * @see OptionTag 24 | 25 | * @see UnsupportedHeader 26 | 27 | */ 28 | 29 | type SupportedHeader interface { 30 | OptionTag 31 | Header 32 | } 33 | -------------------------------------------------------------------------------- /sip/header/SupportedList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * A list of supported headers. 7 | *@see Supported 8 | */ 9 | 10 | type SupportedList struct { 11 | SIPHeaderList 12 | } 13 | 14 | /** Default Constructor 15 | */ 16 | func NewSupportedList() *SupportedList { 17 | this := &SupportedList{} 18 | this.SIPHeaderList.super(core.SIPHeaderNames_SUPPORTED) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/UnsupportedHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | /** 4 | * The Unsupported header field lists the features not supported by the UAS. 5 | * If a server does not understand the option, it must respond by returning a 6 | * 420 (Bad Extension) Response and list those options it does not understand in 7 | * the UnsupportedHeader. 8 | * 9 | * @see SupportedHeader 10 | * @see RequireHeader 11 | */ 12 | 13 | type UnsupportedHeader interface { 14 | OptionTag 15 | Header 16 | } 17 | -------------------------------------------------------------------------------- /sip/header/UnsupportedImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | ) 7 | 8 | /** 9 | * the Unsupported header. 10 | */ 11 | type Unsupported struct { 12 | SIPHeader 13 | 14 | /** option-Tag field. 15 | */ 16 | optionTag string 17 | } 18 | 19 | /** Default Constructor. 20 | */ 21 | func NewUnsupported() *Unsupported { 22 | this := &Unsupported{} 23 | this.SIPHeader.super(core.SIPHeaderNames_UNSUPPORTED) 24 | return this 25 | } 26 | 27 | /** Constructor 28 | * @param ot String to set 29 | */ 30 | func NewUnsupportedFromString(ot string) *Unsupported { 31 | this := &Unsupported{} 32 | this.SIPHeader.super(core.SIPHeaderNames_UNSUPPORTED) 33 | this.optionTag = ot 34 | return this 35 | } 36 | 37 | func (this *Unsupported) String() string { 38 | return this.headerName + core.SIPSeparatorNames_COLON + 39 | core.SIPSeparatorNames_SP + this.EncodeBody() + core.SIPSeparatorNames_NEWLINE 40 | } 41 | 42 | /** 43 | * Return a canonical value. 44 | * @return String. 45 | */ 46 | func (this *Unsupported) EncodeBody() string { 47 | return this.optionTag 48 | } 49 | 50 | /** get the option tag field 51 | * @return option Tag field 52 | */ 53 | func (this *Unsupported) GetOptionTag() string { 54 | return this.optionTag 55 | } 56 | 57 | /** 58 | * Set the option member 59 | * @param o String to set 60 | */ 61 | func (this *Unsupported) SetOptionTag(o string) (ParseException error) { 62 | if o == "" { 63 | return errors.New("NullPointerException: The option tag parameter is null") 64 | } 65 | this.optionTag = o 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /sip/header/UnsupportedList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * List of Unsupported headers. 7 | */ 8 | type UnsupportedList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** Default Constructor 13 | */ 14 | func NewUnsupportedList() *UnsupportedList { 15 | this := &UnsupportedList{} 16 | this.SIPHeaderList.super(core.SIPHeaderNames_UNSUPPORTED) 17 | return this 18 | } 19 | -------------------------------------------------------------------------------- /sip/header/UserAgentHeader.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "container/list" 4 | 5 | /** 6 | * The User-Agent header field contains information about the UAC originating 7 | * the request. This is for statistical purposes, the tracing of protocol 8 | * violations, and automated recognition of user agents for the sake of 9 | * tailoring Responses to avoid particular user agent limitations. However 10 | * revealing the specific software version of the user agent might allow the 11 | * user agent to become more vulnerable to attacks against software that is 12 | * known to contain security holes. Implementers SHOULD make the User-Agent 13 | * header field a configurable option. 14 | *

15 | * For Example:
16 | * User-Agent: Softphone Beta1.5 17 | * 18 | * @see ServerHeader 19 | * @see ViaHeader 20 | */ 21 | type UserAgentHeader interface { 22 | Header 23 | 24 | /** 25 | * Returns the List of product values. 26 | * 27 | * @return the List of strings identifying the software of this ServerHeader 28 | */ 29 | GetProduct() *list.List 30 | 31 | /** 32 | * Sets the List of product values of the ServerHeader. 33 | * 34 | * @param product - a List of Strings specifying the product values 35 | * @throws ParseException which signals that an error has been reached 36 | * unexpectedly while parsing the List of product value strings. 37 | */ 38 | SetProduct(product *list.List) (ParseException error) 39 | } 40 | -------------------------------------------------------------------------------- /sip/header/ViaList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import ( 4 | "gosips/core" 5 | ) 6 | 7 | /** 8 | * Keeps a list and a hashtable of via header functions. 9 | */ 10 | type ViaList struct { 11 | SIPHeaderList 12 | 13 | stringRep string 14 | } 15 | 16 | /** 17 | * Default Constructor. 18 | */ 19 | func NewViaList() *ViaList { 20 | this := &ViaList{} 21 | this.SIPHeaderList.super(core.SIPHeaderNames_VIA) 22 | return this 23 | } 24 | 25 | func (this *ViaList) super(name string) { 26 | this.SIPHeaderList.super(name) 27 | } 28 | 29 | /** 30 | * make a clone of this header list. This supercedes the parent 31 | * function of the same signature - here for speed. Cloning based 32 | * on introspection is slower. 33 | * 34 | * @return clone of this Header list. 35 | */ 36 | func (this *ViaList) Clone() interface{} { 37 | vlist := NewViaList() 38 | //ListIterator it = this.listIterator(); 39 | for e := this.Front(); e != nil; e = e.Next() { 40 | v := e.Value.(*Via).Clone().(*Via) 41 | vlist.PushBack(v) 42 | } 43 | return vlist 44 | } 45 | -------------------------------------------------------------------------------- /sip/header/WWWAuthenticateImpl.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** The WWWAuthenticate SIP header. 6 | * @see WWWAuthenticateList SIPHeader which strings these together. 7 | */ 8 | 9 | type WWWAuthenticate struct { 10 | Authentication 11 | } 12 | 13 | /** 14 | * Default Constructor. 15 | */ 16 | func NewWWWAuthenticate() *WWWAuthenticate { 17 | this := &WWWAuthenticate{} 18 | this.Authentication.super(core.SIPHeaderNames_WWW_AUTHENTICATE) 19 | return this 20 | } 21 | -------------------------------------------------------------------------------- /sip/header/WWWAuthenticateList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * WWWAuthenticate SIPHeader (of which there can be several?) 7 | */ 8 | type WWWAuthenticateList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** 13 | * constructor. 14 | */ 15 | func NewWWWAuthenticateList() *WWWAuthenticateList { 16 | this := &WWWAuthenticateList{} 17 | this.SIPHeaderList.super(core.SIPHeaderNames_WWW_AUTHENTICATE) 18 | return this 19 | } 20 | -------------------------------------------------------------------------------- /sip/header/WarningList.go: -------------------------------------------------------------------------------- 1 | package header 2 | 3 | import "gosips/core" 4 | 5 | /** 6 | * A Warning SIPObject. (A list of Warning headers). 7 | */ 8 | type WarningList struct { 9 | SIPHeaderList 10 | } 11 | 12 | /** Constructor. 13 | * 14 | */ 15 | func NewWarningList() *WarningList { 16 | this := &WarningList{} 17 | this.SIPHeaderList.super(core.SIPHeaderNames_WARNING) 18 | return this 19 | } 20 | -------------------------------------------------------------------------------- /sip/parser/AcceptEncodingParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAcceptEncodingParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Accept-Encoding: compress,gzip\n", 10 | "Accept-Encoding:\n", 11 | "Accept-Encoding: *\n", 12 | "Accept-Encoding: compress;q=0.5,gzip;q=1.0\n", 13 | "Accept-Encoding: gzip;q=1.0,identity;q=0.5,*;q=0\n", 14 | } 15 | var tvo = []string{ 16 | "Accept-Encoding: compress,gzip\n", 17 | "Accept-Encoding:\n", 18 | "Accept-Encoding: *\n", 19 | "Accept-Encoding: compress;q=0.5,gzip;q=1\n", 20 | "Accept-Encoding: gzip;q=1,identity;q=0.5,*;q=0\n", 21 | } 22 | 23 | for i := 0; i < len(tvi); i++ { 24 | shp := NewAcceptEncodingParser(tvi[i]) 25 | testHeaderParser(t, shp, tvo[i]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sip/parser/AcceptLanguageParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAcceptLanguageParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Accept-Language: da \n", 10 | "Accept-Language: \n", 11 | "Accept-Language: da,en-gb;q=0.8\n", 12 | "Accept-Language: * \n"} 13 | var tvo = []string{ 14 | "Accept-Language: da \n", 15 | "Accept-Language: \n", 16 | "Accept-Language: da,en-gb;q=0.8\n", 17 | "Accept-Language: * \n"} 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewAcceptLanguageParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | 25 | /** 26 | public static void main(String args[]) throws ParseException { 27 | String acceptLanguage[] = { 28 | "Accept-Language: da \n", 29 | "Accept-Language:\n", 30 | "Accept-Language: da, en-gb;q=0.8\n", 31 | "Accept-Language: *\n" }; 32 | 33 | for (int i =0 ; i < acceptLanguage.length; i++) { 34 | AcceptLanguageParser alp = new AcceptLanguageParser 35 | (acceptLanguage[i]); 36 | AcceptLanguageList all = (AcceptLanguageList) 37 | alp.parse(); 38 | System.out.println(all.toString()); 39 | } 40 | } 41 | **/ 42 | -------------------------------------------------------------------------------- /sip/parser/AcceptParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAcceptParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Accept: application/sdp;level=1,application/x-private,text/html\n", 10 | } 11 | var tvo = []string{ 12 | "Accept: application/sdp;level=1,application/x-private,text/html\n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewAcceptParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sip/parser/AddressParametersParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/address" 6 | "gosips/sip/header" 7 | ) 8 | 9 | /** Address parameters parser. 10 | */ 11 | type AddressParametersParser struct { 12 | ParametersParser 13 | } 14 | 15 | func NewAddressParametersParserFromLexer(lexer core.Lexer) *AddressParametersParser { 16 | this := &AddressParametersParser{} 17 | this.ParametersParser.superFromLexer(lexer) 18 | return this 19 | } 20 | 21 | func NewAddressParametersParser(buffer string) *AddressParametersParser { 22 | this := &AddressParametersParser{} 23 | this.ParametersParser.super(buffer) 24 | return this 25 | } 26 | 27 | func (this *AddressParametersParser) super(buffer string) { 28 | this.ParametersParser.super(buffer) 29 | } 30 | 31 | func (this *AddressParametersParser) superFromLexer(lexer core.Lexer) { 32 | this.ParametersParser.superFromLexer(lexer) 33 | } 34 | 35 | func (this *AddressParametersParser) Parse(addressParametersHeader header.AddressParametersHeader) (ParseException error) { 36 | addressParser := NewAddressParserFromLexer(this.GetLexer()) 37 | var addr *address.AddressImpl 38 | if addr, ParseException = addressParser.Address(); ParseException != nil { 39 | return ParseException 40 | } 41 | addressParametersHeader.SetAddress(addr) 42 | ParseException = this.ParametersParser.Parse(addressParametersHeader) 43 | return ParseException 44 | } 45 | -------------------------------------------------------------------------------- /sip/parser/AddressParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | ) 7 | 8 | func TestAddressParser(t *testing.T) { 9 | var tvi = []string{ 10 | "", 11 | "\"M. Ranganathan\" ", 12 | "", 13 | "M. Ranganathan ", 14 | } 15 | var tvo = []string{ 16 | "", 17 | "\"M. Ranganathan\" ", 18 | "", 19 | "\"M. Ranganathan\" ", 20 | } 21 | 22 | for i := 0; i < len(tvi); i++ { 23 | addressParser := NewAddressParser(tvi[i]) 24 | if addr, err := addressParser.Address(); err != nil { 25 | t.Log(err) 26 | t.Fail() 27 | } else { 28 | d := addr.String() 29 | s := tvo[i] 30 | 31 | if strings.TrimSpace(d) != strings.TrimSpace(s) { 32 | t.Log("origin = " + s) 33 | t.Log("failed = " + d) 34 | t.Fail() 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sip/parser/AlertInfoParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAlertInfoParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Alert-Info: \n", 10 | } 11 | var tvo = []string{ 12 | "Alert-Info: \n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewAlertInfoParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sip/parser/AllowEventsParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAllowEventsParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Allow-Events: pack1.pack2,pack3,pack4\n", 10 | "Allow-Events: pack1\n", 11 | } 12 | var tvo = []string{ 13 | "Allow-Events: pack1.pack2,pack3,pack4\n", 14 | "Allow-Events: pack1\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewAllowEventsParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Allow-Events: pack1.pack2, pack3 , pack4\n", 27 | "Allow-Events: pack1\n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | AllowEventsParser parser = 32 | new AllowEventsParser(r[i]); 33 | AllowEventsList a= (AllowEventsList) parser.parse(); 34 | System.out.println("encoded = " + a.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/AllowParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Allow header. 9 | */ 10 | type AllowParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** 15 | * Creates a new instance of AllowParser 16 | * @param allow the header to parse 17 | */ 18 | func NewAllowParser(allow string) *AllowParser { 19 | this := &AllowParser{} 20 | this.HeaderParser.super(allow) 21 | return this 22 | } 23 | 24 | /** Constructor 25 | * @param lexer the lexer to use to parse the header 26 | */ 27 | func NewAllowParserFromLexer(lexer core.Lexer) *AllowParser { 28 | this := &AllowParser{} 29 | this.HeaderParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** parse the Allow String header 34 | * @return Header (AllowList object) 35 | * @throws SIPParseException if the message does not respect the spec. 36 | */ 37 | func (this *AllowParser) Parse() (sh header.Header, ParseException error) { 38 | allowList := header.NewAllowList() 39 | 40 | var ch byte 41 | 42 | lexer := this.GetLexer() 43 | this.HeaderName(TokenTypes_ALLOW) 44 | 45 | allow := header.NewAllow() 46 | allow.SetHeaderName(core.SIPHeaderNames_ALLOW) 47 | 48 | lexer.SPorHT() 49 | lexer.Match(TokenTypes_ID) 50 | token := lexer.GetNextToken() 51 | allow.SetMethod(token.GetTokenValue()) 52 | 53 | allowList.PushBack(allow) 54 | lexer.SPorHT() 55 | for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) { 56 | lexer.Match(',') 57 | lexer.SPorHT() 58 | 59 | allow = header.NewAllow() 60 | lexer.Match(TokenTypes_ID) 61 | token = lexer.GetNextToken() 62 | allow.SetMethod(token.GetTokenValue()) 63 | 64 | allowList.PushBack(allow) 65 | lexer.SPorHT() 66 | } 67 | lexer.SPorHT() 68 | lexer.Match('\n') 69 | 70 | return allowList, nil 71 | } 72 | -------------------------------------------------------------------------------- /sip/parser/AllowParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAllowParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Allow: INVITE,ACK,OPTIONS,CANCEL,BYE\n", 10 | "Allow: INVITE\n", 11 | } 12 | var tvo = []string{ 13 | "Allow: INVITE,ACK,OPTIONS,CANCEL,BYE\n", 14 | "Allow: INVITE\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewAllowParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Allow: INVITE, ACK, OPTIONS, CANCEL, BYE\n", 27 | "Allow: INVITE\n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | AllowParser parser = 32 | new AllowParser(r[i]); 33 | AllowList a= (AllowList) parser.parse(); 34 | System.out.println("encoded = " + a.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/AuthenticationInfoParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestAuthenticationInfoParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\"\n", 10 | "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\",rspauth=\"hello\"\n", 11 | } 12 | var tvo = []string{ 13 | "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\"\n", 14 | "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\",rspauth=\"hello\"\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewAuthenticationInfoParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\"\n", 27 | "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\",rspauth=\"hello\"\n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | AuthenticationInfoParser parser = 32 | new AuthenticationInfoParser(r[i]); 33 | AuthenticationInfo a= (AuthenticationInfo) parser.parse(); 34 | System.out.println("encoded = " + a.encode()); 35 | } 36 | } 37 | **/ 38 | -------------------------------------------------------------------------------- /sip/parser/AuthorizationParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for authorization headers. 9 | */ 10 | type AuthorizationParser struct { 11 | ChallengeParser 12 | } 13 | 14 | /** Constructor 15 | * @param String Authorization message to parse 16 | */ 17 | func NewAuthorizationParser(authorization string) *AuthorizationParser { 18 | this := &AuthorizationParser{} 19 | this.ChallengeParser.super(authorization) 20 | return this 21 | } 22 | 23 | /** Cosntructor 24 | * @param lexer to set 25 | */ 26 | func NewAuthorizationParserFromLexer(lexer core.Lexer) *AuthorizationParser { 27 | this := &AuthorizationParser{} 28 | this.ChallengeParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return Header (Authorization object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *AuthorizationParser) Parse() (sh header.Header, ParseException error) { 37 | this.HeaderName(TokenTypes_AUTHORIZATION) 38 | auth := header.NewAuthorization() 39 | ParseException = this.ChallengeParser.Parse(auth) 40 | return auth, ParseException 41 | } 42 | -------------------------------------------------------------------------------- /sip/parser/CSeqParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for CSeq headers. 9 | */ 10 | type CSeqParser struct { 11 | HeaderParser 12 | } 13 | 14 | func NewCSeqParser(cseq string) *CSeqParser { 15 | this := &CSeqParser{} 16 | this.HeaderParser.super(cseq) 17 | return this 18 | } 19 | 20 | func (this *CSeqParser) super(cseq string) { 21 | this.HeaderParser.super(cseq) 22 | } 23 | 24 | func NewCSeqParserFromLexer(lexer core.Lexer) *CSeqParser { 25 | this := &CSeqParser{} 26 | this.HeaderParser.superFromLexer(lexer) 27 | return this 28 | } 29 | 30 | func (this *CSeqParser) Parse() (sh header.Header, ParseException error) { 31 | lexer := this.GetLexer() 32 | lexer.Match(TokenTypes_CSEQ) 33 | lexer.SPorHT() 34 | lexer.Match(':') 35 | lexer.SPorHT() 36 | 37 | var number int 38 | var method string 39 | if number, ParseException = lexer.Number(); ParseException != nil { 40 | return nil, ParseException 41 | } 42 | lexer.SPorHT() 43 | if method, ParseException = this.Method(); ParseException != nil { 44 | return nil, ParseException 45 | } 46 | //c.SetMethod(m); 47 | lexer.SPorHT() 48 | lexer.Match('\n') 49 | 50 | c := header.NewCSeq(number, method) 51 | 52 | return c, nil 53 | } 54 | -------------------------------------------------------------------------------- /sip/parser/CSeqParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestCSeqParser(t *testing.T) { 8 | var tvi = []string{ 9 | "CSeq: 17 INVITE\n", 10 | "CSeq: 17 ACK\n", 11 | "CSeq: 18 BYE\n", 12 | "CSeq: 1 CANCEL\n", 13 | "CSeq: 3 BYE\n", 14 | } 15 | var tvo = []string{ 16 | "CSeq: 17 INVITE\n", 17 | "CSeq: 17 ACK\n", 18 | "CSeq: 18 BYE\n", 19 | "CSeq: 1 CANCEL\n", 20 | "CSeq: 3 BYE\n", 21 | } 22 | 23 | for i := 0; i < len(tvi); i++ { 24 | shp := NewCSeqParser(tvi[i]) 25 | testHeaderParser(t, shp, tvo[i]) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sip/parser/CallIdParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | "strings" 7 | ) 8 | 9 | /** SIPParser for CALL ID header. 10 | */ 11 | type CallIDParser struct { 12 | HeaderParser 13 | } 14 | 15 | /** Creates new CallIDParser 16 | * @param String callID message to parse to set 17 | */ 18 | func NewCallIDParser(callId string) *CallIDParser { 19 | this := &CallIDParser{} 20 | 21 | this.HeaderParser.super(callId) 22 | 23 | return this 24 | } 25 | 26 | func (this *CallIDParser) super(callId string) { 27 | this.HeaderParser.super(callId) 28 | } 29 | 30 | /** Constructor 31 | * @param lexer to set 32 | */ 33 | func NewCallIDParserFromLexer(lexer core.Lexer) *CallIDParser { 34 | this := &CallIDParser{} 35 | 36 | this.HeaderParser.superFromLexer(lexer) 37 | 38 | return this 39 | } 40 | 41 | /** parse the String message 42 | * @return Header (CallID object) 43 | * @throws ParseException if the message does not respect the spec. 44 | */ 45 | func (this *CallIDParser) Parse() (sh header.Header, ParseException error) { 46 | lexer := this.GetLexer() 47 | lexer.Match(TokenTypes_CALL_ID) 48 | lexer.SPorHT() 49 | lexer.Match(':') 50 | lexer.SPorHT() 51 | rest := strings.TrimSpace(lexer.GetRest()) 52 | 53 | callID, ParseException := header.NewCallID(rest) 54 | 55 | return callID, ParseException 56 | } 57 | -------------------------------------------------------------------------------- /sip/parser/CallIdParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestCallIdParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Call-ID: f0b40bcc-3485-49e7-ad1a-f1dfad2e39c9@10.5.0.53\n", 10 | "Call-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com\n", 11 | "i:f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com\n", 12 | "Call-ID: 1@10.0.0.1\n", 13 | "Call-ID: kl24ahsd546folnyt2vbak9sad98u23naodiunzds09a3bqw0sdfbsk34poouymnae0043nsed09mfkvc74bd0cuwnms05dknw87hjpobd76f\n", 14 | "Call-ID: 281794\n", 15 | } 16 | var tvo = []string{ 17 | "Call-ID: f0b40bcc-3485-49e7-ad1a-f1dfad2e39c9@10.5.0.53\n", 18 | "Call-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com\n", 19 | "Call-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com\n", 20 | "Call-ID: 1@10.0.0.1\n", 21 | "Call-ID: kl24ahsd546folnyt2vbak9sad98u23naodiunzds09a3bqw0sdfbsk34poouymnae0043nsed09mfkvc74bd0cuwnms05dknw87hjpobd76f\n", 22 | "Call-ID: 281794\n", 23 | } 24 | 25 | for i := 0; i < len(tvi); i++ { 26 | shp := NewCallIDParser(tvi[i]) 27 | testHeaderParser(t, shp, tvo[i]) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sip/parser/CallInfoParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestCallInfoParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Call-Info: ;purpose=icon," + 10 | ";purpose=info\n", 11 | "Call-Info: \n", 12 | } 13 | var tvo = []string{ 14 | "Call-Info: ;purpose=icon," + 15 | ";purpose=info\n", 16 | "Call-Info: \n", 17 | } 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewCallInfoParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | 25 | /** Test program 26 | public static void main(String args[]) throws ParseException { 27 | String r[] = { 28 | "Call-Info: ;purpose=icon,"+ 29 | " ;purpose=info\n", 30 | "Call-Info: \n" 31 | }; 32 | 33 | for (int i = 0; i < r.length; i++ ) { 34 | CallInfoParser parser = 35 | new CallInfoParser(r[i]); 36 | CallInfoList e= (CallInfoList) parser.parse(); 37 | System.out.println("encoded = " + e.encode()); 38 | } 39 | } 40 | */ 41 | -------------------------------------------------------------------------------- /sip/parser/ContactParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | "strconv" 7 | ) 8 | 9 | /** 10 | * A parser for The SIP contact header. 11 | */ 12 | 13 | type ContactParser struct { 14 | AddressParametersParser 15 | } 16 | 17 | func NewContactParser(contact string) *ContactParser { 18 | this := &ContactParser{} 19 | this.AddressParametersParser.super(contact) 20 | return this 21 | } 22 | 23 | func NewContactParserFromLexer(lexer core.Lexer) *ContactParser { 24 | this := &ContactParser{} 25 | this.AddressParametersParser.superFromLexer(lexer) 26 | return this 27 | } 28 | 29 | func (this *ContactParser) Parse() (sh header.Header, ParseException error) { 30 | retval := header.NewContactList() 31 | // past the header name and the colon. 32 | lexer := this.GetLexer() 33 | var la byte 34 | this.HeaderName(TokenTypes_CONTACT) 35 | for { 36 | contact := header.NewContact() 37 | if la, _ = lexer.LookAheadK(0); la == '*' { 38 | lexer.Match('*') 39 | contact.SetWildCardFlag(true) 40 | } else { 41 | if ParseException = this.AddressParametersParser.Parse(contact); ParseException != nil { 42 | return nil, ParseException 43 | } 44 | 45 | if contact.HasParameter(header.ParameterNames_EXPIRES) { 46 | if _, ParseException = strconv.Atoi(contact.GetParameter(header.ParameterNames_EXPIRES)); ParseException != nil { 47 | return nil, ParseException 48 | } 49 | } 50 | } 51 | retval.AddContact(contact) 52 | lexer.SPorHT() 53 | if la, _ = lexer.LookAheadK(0); la == ',' { 54 | lexer.Match(',') 55 | lexer.SPorHT() 56 | } else if la, _ = lexer.LookAheadK(0); la == '\n' { 57 | break 58 | } else { 59 | return nil, this.CreateParseException("unexpected char") 60 | } 61 | } 62 | return retval, nil 63 | } 64 | -------------------------------------------------------------------------------- /sip/parser/ContactParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestContactParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Contact:;expires=3600\n", 10 | "Contact:BigGuy;expires=3600\n", 11 | "Contact: sip:4855@166.35.224.216:5060\n", 12 | "Contact: sip:user@host.company.com\n", 13 | "Contact: Bo Bob Biggs\n< sip:user@example.com?Route=%3Csip:sip.example.com%3E >\n", 14 | "Contact: Joe Bob Briggs \n", 15 | "Contact: \"Mr. Watson\" " + 16 | " ; q=0.7; expires=3600,\"Mr. Watson\" " + 17 | ";q=0.1\n", 18 | "Contact: LittleGuy " + 19 | ",,tel:+1-972-555-2222" + 20 | "\n", 21 | "Contact:*\n", 22 | "Contact:BigGuy;Expires=3600\n", 23 | } 24 | var tvo = []string{ 25 | "Contact: ;expires=3600\n", 26 | "Contact: \"BigGuy\" ;expires=3600\n", 27 | "Contact: \n", 28 | "Contact: \n", 29 | "Contact: \"Bo Bob Biggs\" \n", 30 | "Contact: \"Joe Bob Briggs\" \n", 31 | "Contact: \"Mr. Watson\" " + 32 | ";q=0.7;expires=3600,\"Mr. Watson\" " + 33 | ";q=0.1\n", 34 | "Contact: \"LittleGuy\" " + 35 | ",," + 36 | "\n", 37 | "Contact: <*>\n", 38 | "Contact: \"BigGuy\" ;Expires=3600\n", 39 | } 40 | 41 | for i := 0; i < len(tvi); i++ { 42 | shp := NewContactParser(tvi[i]) 43 | testHeaderParser(t, shp, tvo[i]) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sip/parser/ContentDispositionParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for ContentLanguage header. 9 | */ 10 | type ContentDispositionParser struct { 11 | ParametersParser 12 | } 13 | 14 | /** 15 | * Creates a new instance of ContentDispositionParser 16 | * @param contentDisposition the header to parse 17 | */ 18 | func NewContentDispositionParser(contentDisposition string) *ContentDispositionParser { 19 | this := &ContentDispositionParser{} 20 | this.ParametersParser.super(contentDisposition) 21 | return this 22 | } 23 | 24 | /** Constructor 25 | * @param lexer the lexer to use to parse the header 26 | */ 27 | func NewContentDispositionParserFromLexer(lexer core.Lexer) *ContentDispositionParser { 28 | this := &ContentDispositionParser{} 29 | this.ParametersParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** parse the ContentDispositionHeader String header 34 | * @return Header (ContentDispositionList object) 35 | * @throws SIPParseException if the message does not respect the spec. 36 | */ 37 | func (this *ContentDispositionParser) Parse() (sh header.Header, ParseException error) { 38 | lexer := this.GetLexer() 39 | this.HeaderName(TokenTypes_CONTENT_DISPOSITION) 40 | 41 | cd := header.NewContentDisposition() 42 | cd.SetHeaderName(core.SIPHeaderNames_CONTENT_DISPOSITION) 43 | 44 | lexer.SPorHT() 45 | lexer.Match(TokenTypes_ID) 46 | 47 | token := lexer.GetNextToken() 48 | cd.SetDispositionType(token.GetTokenValue()) 49 | lexer.SPorHT() 50 | if ParseException = this.ParametersParser.Parse(cd); ParseException != nil { 51 | return nil, ParseException 52 | } 53 | 54 | lexer.SPorHT() 55 | lexer.Match('\n') 56 | 57 | return cd, nil 58 | } 59 | -------------------------------------------------------------------------------- /sip/parser/ContentDispositionParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestContentDispositionParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Content-Disposition: session\n", 10 | "Content-Disposition: render;handling=hand;optional=opt\n", 11 | } 12 | var tvo = []string{ 13 | "Content-Disposition: session\n", 14 | "Content-Disposition: render;handling=hand;optional=opt\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewContentDispositionParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Content-Disposition: session\n", 27 | "Content-Disposition: render;handling=hand;optional=opt \n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | ContentDispositionParser parser = 32 | new ContentDispositionParser(r[i]); 33 | ContentDisposition cd= (ContentDisposition) parser.parse(); 34 | System.out.println("encoded = " + cd.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/ContentEncodingParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestContentEncodingParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Content-Encoding: gzip \n", 10 | "Content-Encoding: gzip,tar \n", 11 | } 12 | var tvo = []string{ 13 | "Content-Encoding: gzip \n", 14 | "Content-Encoding: gzip,tar \n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewContentEncodingParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Content-Encoding: gzip \n", 27 | "Content-Encoding: gzip, tar \n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | ContentEncodingParser parser = 32 | new ContentEncodingParser(r[i]); 33 | ContentEncodingList e= (ContentEncodingList) parser.parse(); 34 | System.out.println("encoded = " + e.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/ContentLanguageParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestContentLanguageParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Content-Language: fr \n", 10 | "Content-Language: fr,he \n", 11 | } 12 | var tvo = []string{ 13 | "Content-Language: fr \n", 14 | "Content-Language: fr,he \n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewContentLanguageParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Content-Language: fr \n", 27 | "Content-Language: fr , he \n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | ContentLanguageParser parser = 32 | new ContentLanguageParser(r[i]); 33 | ContentLanguageList e= (ContentLanguageList) parser.parse(); 34 | System.out.println("encoded = " + e.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/ContentLengthParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Content-Length Header. 9 | */ 10 | type ContentLengthParser struct { 11 | HeaderParser 12 | } 13 | 14 | func NewContentLengthParser(contentLength string) *ContentLengthParser { 15 | this := &ContentLengthParser{} 16 | this.HeaderParser.super(contentLength) 17 | return this 18 | } 19 | 20 | func NewContentLengthParserFromLexer(lexer core.Lexer) *ContentLengthParser { 21 | this := &ContentLengthParser{} 22 | this.HeaderParser.superFromLexer(lexer) 23 | return this 24 | } 25 | 26 | func (this *ContentLengthParser) Parse() (sh header.Header, ParseException error) { 27 | var number int 28 | contentLength := header.NewContentLength() 29 | lexer := this.GetLexer() 30 | this.HeaderName(TokenTypes_CONTENT_LENGTH) 31 | if number, ParseException = lexer.Number(); ParseException != nil { 32 | return nil, ParseException 33 | } 34 | if ParseException = contentLength.SetContentLength(number); ParseException != nil { 35 | return nil, ParseException 36 | } 37 | lexer.SPorHT() 38 | lexer.Match('\n') 39 | return contentLength, nil 40 | } 41 | -------------------------------------------------------------------------------- /sip/parser/ContentLengthParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestContentLengthParser(t *testing.T) { 8 | var tvi = []string{ 9 | "l: 345\n", 10 | "Content-Length: 3495\n", 11 | "Content-Length: 0 \n", 12 | } 13 | var tvo = []string{ 14 | "Content-Length: 345\n", 15 | "Content-Length: 3495\n", 16 | "Content-Length: 0 \n", 17 | } 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewContentLengthParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | 25 | /** 26 | public static void main(String args[]) throws ParseException { 27 | String content[] = { 28 | "l: 345\n", 29 | "Content-Length: 3495\n", 30 | "Content-Length: 0 \n" 31 | }; 32 | 33 | for (int i = 0; i < content.length; i++ ) { 34 | ContentLengthParser cp = 35 | new ContentLengthParser(content[i]); 36 | ContentLength c = (ContentLength) cp.parse(); 37 | System.out.println("encoded = " + c.encode()); 38 | } 39 | 40 | } 41 | **/ 42 | -------------------------------------------------------------------------------- /sip/parser/ContentTypeParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for content type header. 9 | */ 10 | type ContentTypeParser struct { 11 | ParametersParser 12 | } 13 | 14 | func NewContentTypeParser(contentType string) *ContentTypeParser { 15 | this := &ContentTypeParser{} 16 | this.ParametersParser.super(contentType) 17 | return this 18 | } 19 | 20 | func NewContentTypeParserFromLexer(lexer core.Lexer) *ContentTypeParser { 21 | this := &ContentTypeParser{} 22 | this.ParametersParser.superFromLexer(lexer) 23 | return this 24 | } 25 | 26 | func (this *ContentTypeParser) Parse() (sh header.Header, ParseException error) { 27 | contentType := header.NewContentType() 28 | 29 | lexer := this.GetLexer() 30 | this.HeaderName(TokenTypes_CONTENT_TYPE) 31 | 32 | // The type: 33 | lexer.Match(TokenTypes_ID) 34 | t := lexer.GetNextToken() 35 | lexer.SPorHT() 36 | contentType.SetContentType(t.GetTokenValue()) 37 | 38 | // The sub-type: 39 | lexer.Match('/') 40 | lexer.Match(TokenTypes_ID) 41 | subType := lexer.GetNextToken() 42 | lexer.SPorHT() 43 | contentType.SetContentSubType(subType.GetTokenValue()) 44 | if ParseException = this.ParametersParser.Parse(contentType); ParseException != nil { 45 | return nil, ParseException 46 | } 47 | lexer.Match('\n') 48 | 49 | return contentType, nil 50 | } 51 | -------------------------------------------------------------------------------- /sip/parser/ContentTypeParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestContentTypeParser(t *testing.T) { 8 | var tvi = []string{ 9 | "c: text/html; charset=ISO-8859-4\n", 10 | "Content-Type: text/html;charset=ISO-8859-4\n", 11 | "Content-Type: application/sdp\n", 12 | "Content-Type: application/sdp;o=we;l=ek;i=end \n", 13 | } 14 | var tvo = []string{ 15 | "Content-Type: text/html;charset=ISO-8859-4\n", 16 | "Content-Type: text/html;charset=ISO-8859-4\n", 17 | "Content-Type: application/sdp\n", 18 | "Content-Type: application/sdp;o=we;l=ek;i=end \n", 19 | } 20 | 21 | for i := 0; i < len(tvi); i++ { 22 | shp := NewContentTypeParser(tvi[i]) 23 | testHeaderParser(t, shp, tvo[i]) 24 | } 25 | } 26 | 27 | /** 28 | public static void main(String args[]) throws ParseException { 29 | String content[] = { 30 | "c: text/html; charset=ISO-8859-4\n", 31 | "Content-Type: text/html; charset=ISO-8859-4\n", 32 | "Content-Type: application/sdp\n", 33 | "Content-Type: application/sdp; o=we ;l=ek ; i=end \n" 34 | }; 35 | 36 | for (int i = 0; i < content.length; i++ ) { 37 | ContentTypeParser cp = 38 | new ContentTypeParser(content[i]); 39 | ContentType c = (ContentType) cp.parse(); 40 | System.out.println("encoded = " + c.encode()); 41 | } 42 | 43 | } 44 | **/ 45 | -------------------------------------------------------------------------------- /sip/parser/DateParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | "gosips/sip/header" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | /** SIPParser for SIP Date field. Converts from SIP Date to the 12 | * internal storage (Calendar) 13 | */ 14 | type DateParser struct { 15 | HeaderParser 16 | } 17 | 18 | /** Constructor 19 | * @param String route message to parse to set 20 | */ 21 | func NewDateParser(date string) *DateParser { 22 | this := &DateParser{} 23 | this.HeaderParser.super(date) 24 | return this 25 | } 26 | 27 | func NewDateParserFromLexer(lexer core.Lexer) *DateParser { 28 | this := &DateParser{} 29 | this.HeaderParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** Parse method. 34 | * @throws ParseException 35 | * @return the parsed Date header/ 36 | */ 37 | func (this *DateParser) Parse() (sh header.Header, ParseException error) { 38 | lexer := this.GetLexer() 39 | this.HeaderName(TokenTypes_DATE) 40 | var t time.Time 41 | if t, ParseException = time.Parse(time.RFC1123, strings.TrimSpace(lexer.GetRest())); ParseException != nil { 42 | return nil, ParseException 43 | } 44 | if t.Location().String() != "GMT" { 45 | return nil, errors.New("GMT is only acceptable time zone") 46 | } 47 | retval := header.NewDate() 48 | retval.SetDate(&t) 49 | return retval, nil 50 | } 51 | -------------------------------------------------------------------------------- /sip/parser/DateParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestDateParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Date: Sun, 07 Jan 2001 19:05:06 GMT\n", 10 | "Date: Mon, 08 Jan 2001 19:05:06 GMT\n", 11 | } 12 | var tvo = []string{ 13 | "Date: Sun, 07 Jan 2001 19:05:06 GMT\n", 14 | "Date: Mon, 08 Jan 2001 19:05:06 GMT\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewDateParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** 24 | public static void main(String args[]) throws ParseException { 25 | String date[] = { 26 | "Date: Sun, 07 Jan 2001 19:05:06 GMT\n", 27 | "Date: Mon, 08 Jan 2001 19:05:06 GMT\n" }; 28 | 29 | for (int i = 0; i < date.length; i++ ) { 30 | System.out.println("Parsing " + date[i]); 31 | DateParser dp = 32 | new DateParser(date[i]); 33 | SIPDateHeader d = (SIPDateHeader) dp.parse(); 34 | System.out.println("encoded = " +d.encode()); 35 | } 36 | 37 | } 38 | **/ 39 | -------------------------------------------------------------------------------- /sip/parser/ErrorInfoParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestErrorInfoParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Error-Info: \n", 10 | "Error-Info: ;param1=oli\n", 11 | } 12 | var tvo = []string{ 13 | "Error-Info: \n", 14 | "Error-Info: ;param1=oli\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewErrorInfoParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Error-Info: \n", 27 | "Error-Info: ;param1=oli\n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | ErrorInfoParser parser = 32 | new ErrorInfoParser(r[i]); 33 | ErrorInfoList e= (ErrorInfoList) parser.parse(); 34 | System.out.println("encoded = " + e.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/EventParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Event header. 9 | */ 10 | type EventParser struct { 11 | ParametersParser 12 | } 13 | 14 | /** 15 | * Creates a new instance of EventParser 16 | * @param event the header to parse 17 | */ 18 | func NewEventParser(event string) *EventParser { 19 | this := &EventParser{} 20 | this.ParametersParser.super(event) 21 | return this 22 | } 23 | 24 | /** Cosntructor 25 | * @param lexer the lexer to use to parse the header 26 | */ 27 | func NewEventParserFromLexer(lexer core.Lexer) *EventParser { 28 | this := &EventParser{} 29 | this.ParametersParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** parse the String message 34 | * @return Header (Event object) 35 | * @throws SIPParseException if the message does not respect the spec. 36 | */ 37 | func (this *EventParser) Parse() (sh header.Header, ParseException error) { 38 | lexer := this.GetLexer() 39 | this.HeaderName(TokenTypes_EVENT) 40 | lexer.SPorHT() 41 | 42 | event := header.NewEvent() 43 | lexer.Match(TokenTypes_ID) 44 | token := lexer.GetNextToken() 45 | value := token.GetTokenValue() 46 | 47 | event.SetEventType(value) 48 | if ParseException = this.ParametersParser.Parse(event); ParseException != nil { 49 | return nil, ParseException 50 | } 51 | 52 | lexer.SPorHT() 53 | lexer.Match('\n') 54 | 55 | return event, nil 56 | } 57 | -------------------------------------------------------------------------------- /sip/parser/EventParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestEventParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Event: presence\n", 10 | "Event: foo;param=abcd;id=1234\n", 11 | "Event: foo.foo1;param=abcd;id=1234\n", 12 | } 13 | var tvo = []string{ 14 | "Event: presence\n", 15 | "Event: foo;param=abcd;id=1234\n", 16 | "Event: foo.foo1;param=abcd;id=1234\n", 17 | } 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewEventParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | 25 | /** 26 | public static void main(String args[]) throws ParseException { 27 | String r[] = { 28 | "Event: presence\n", 29 | "Event: foo; param=abcd; id=1234\n", 30 | "Event: foo.foo1; param=abcd; id=1234\n" 31 | }; 32 | 33 | for (int i = 0; i < r.length; i++ ) { 34 | EventParser parser = 35 | new EventParser(r[i]); 36 | Event e= (Event) parser.parse(); 37 | System.out.println("encoded = " + e.encode()); 38 | System.out.println("encoded = " + e.clone()); 39 | System.out.println(e.getEventId()); 40 | System.out.println(e.match(e)); 41 | } 42 | } 43 | **/ 44 | -------------------------------------------------------------------------------- /sip/parser/ExpiresParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | "strconv" 7 | ) 8 | 9 | /** SIPParser for SIP Expires SIPParser. Converts from SIP Date to the 10 | * internal storage (Calendar). 11 | */ 12 | type ExpiresParser struct { 13 | HeaderParser 14 | } 15 | 16 | /** protected constructor. 17 | *@param text is the text of the header to parse 18 | */ 19 | func NewExpiresParser(text string) *ExpiresParser { 20 | this := &ExpiresParser{} 21 | this.HeaderParser.super(text) 22 | return this 23 | } 24 | 25 | /** constructor. 26 | *@param lexer is the lexer passed in from the enclosing parser. 27 | */ 28 | func NewExpiresParserFromLexer(lexer core.Lexer) *ExpiresParser { 29 | this := &ExpiresParser{} 30 | this.HeaderParser.superFromLexer(lexer) 31 | return this 32 | } 33 | 34 | /** Parse the header. 35 | */ 36 | func (this *ExpiresParser) Parse() (sh header.Header, ParseException error) { 37 | expires := header.NewExpires() 38 | 39 | lexer := this.GetLexer() 40 | lexer.Match(TokenTypes_EXPIRES) 41 | lexer.SPorHT() 42 | lexer.Match(':') 43 | lexer.SPorHT() 44 | nextId := lexer.GetNextId() 45 | lexer.Match('\n') 46 | var delta int64 47 | if delta, ParseException = strconv.ParseInt(nextId, 10, 32); ParseException != nil { 48 | return nil, ParseException 49 | } 50 | expires.SetExpires(int(delta)) 51 | return expires, ParseException 52 | } 53 | -------------------------------------------------------------------------------- /sip/parser/ExpiresParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestExpiresParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Expires: 1000\n", 10 | } 11 | var tvo = []string{ 12 | "Expires: 1000\n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewExpiresParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program -- to be removed in final version. 22 | public static void main(String args[]) throws ParseException { 23 | String expires[] = { 24 | "Expires: 1000\n" }; 25 | 26 | for (int i = 0; i < expires.length; i++ ) { 27 | try { 28 | System.out.println("Parsing " + expires[i]); 29 | ExpiresParser ep = new ExpiresParser(expires[i]); 30 | Expires e = (Expires) ep.parse(); 31 | System.out.println("encoded = " +e.encode()); 32 | } catch (ParseException ex) { 33 | System.out.println(ex.getMessage()); 34 | } 35 | } 36 | 37 | } 38 | */ 39 | -------------------------------------------------------------------------------- /sip/parser/FromParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/address" 6 | "gosips/sip/header" 7 | ) 8 | 9 | /** From header parser. 10 | */ 11 | type FromParser struct { 12 | AddressParametersParser 13 | } 14 | 15 | func NewFromParser(from string) *FromParser { 16 | this := &FromParser{} 17 | this.AddressParametersParser.super(from) 18 | return this 19 | } 20 | 21 | func (this *FromParser) super(from string) { 22 | this.AddressParametersParser.super(from) 23 | } 24 | 25 | func NewFromParserFromLexer(lexer core.Lexer) *FromParser { 26 | this := &FromParser{} 27 | this.AddressParametersParser.superFromLexer(lexer) 28 | return this 29 | } 30 | 31 | func (this *FromParser) Parse() (sh header.Header, ParseException error) { 32 | from := header.NewFrom() 33 | this.HeaderName(TokenTypes_FROM) 34 | 35 | if ParseException = this.AddressParametersParser.Parse(from); ParseException != nil { 36 | return nil, ParseException 37 | } 38 | 39 | this.GetLexer().Match('\n') 40 | addr := from.GetAddress().(*address.AddressImpl) 41 | if addr.GetAddressType() == address.ADDRESS_SPEC { 42 | // the parameters are header parameters. 43 | if from.GetAddress().GetURI().IsSipURI() { 44 | sipUri, _ := from.GetAddress().GetURI().(*address.SipURIImpl) 45 | parms := sipUri.GetUriParms() 46 | if parms != nil && parms.Len() > 0 { 47 | from.SetParameters(parms) 48 | sipUri.RemoveUriParms() 49 | } 50 | } 51 | } 52 | 53 | return from, nil 54 | } 55 | -------------------------------------------------------------------------------- /sip/parser/FromParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestFromParser(t *testing.T) { 8 | var tvi = []string{ 9 | "From: token1~` token2'+_ token3*%!.- ;fromParam''~+*_!.-%=\"работающий\";tag=_token~1'+`*%!-.\n", 10 | "From: foobar at com;tag=1024181795\n", 11 | "From: sip:user@company.com\n", 12 | "From: sip:caller@university.edu\n", 13 | "From: sip:localhost\n", 14 | "From: \"A. G. Bell\" ;tag=a48s\n", 15 | } 16 | var tvo = []string{ 17 | "From: \"token1~` token2'+_ token3*%!.-\" ;fromParam''~+*_!.-%=\"работающий\";tag=_token~1'+`*%!-.\n", 18 | "From: \"foobar at com\" ;tag=1024181795\n", 19 | "From: \n", 20 | "From: \n", 21 | "From: \n", 22 | "From: \"A. G. Bell\" ;tag=a48s\n", 23 | } 24 | 25 | for i := 0; i < len(tvi); i++ { 26 | shp := NewFromParser(tvi[i]) 27 | testHeaderParser(t, shp, tvo[i]) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sip/parser/HeaderPareser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | ) 7 | 8 | func testHeaderParser(t *testing.T, hp Parser, s string) { 9 | if sh, err := hp.Parse(); err != nil { 10 | t.Log(err) 11 | t.Fail() 12 | } else { 13 | d := sh.String() 14 | 15 | if strings.TrimSpace(d) != strings.TrimSpace(s) { 16 | t.Log("golden = " + s) 17 | t.Log("failed = " + d) 18 | 19 | for j, k := 0, 0; j < len(s); j++ { 20 | if d[j] != s[j] { 21 | t.Logf("%d:%c vs %c", j, s[j], d[j]) 22 | k++ 23 | if k == 10 { 24 | break 25 | } 26 | } 27 | } 28 | 29 | t.Fail() 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sip/parser/InReplyToParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestInReplyToParser(t *testing.T) { 8 | var tvi = []string{ 9 | "In-Reply-To: 70710@saturn.bell-tel.com,17320@saturn.bell-tel.com\n", 10 | "In-Reply-To: 70710 \n", 11 | } 12 | var tvo = []string{ 13 | "In-Reply-To: 70710@saturn.bell-tel.com,17320@saturn.bell-tel.com\n", 14 | "In-Reply-To: 70710 \n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewInReplyToParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String p[] = { 26 | "In-Reply-To: 70710@saturn.bell-tel.com, 17320@saturn.bell-tel.com\n", 27 | "In-Reply-To: 70710 \n" 28 | }; 29 | 30 | for (int i = 0; i < p.length; i++ ) { 31 | InReplyToParser parser = 32 | new InReplyToParser(p[i]); 33 | InReplyToList in= (InReplyToList) parser.parse(); 34 | System.out.println("encoded = " + in.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/MaxForwardsParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Max Forwards Header.*/ 9 | type MaxForwardsParser struct { 10 | HeaderParser 11 | } 12 | 13 | func NewMaxForwardsParser(contentLength string) *MaxForwardsParser { 14 | this := &MaxForwardsParser{} 15 | this.HeaderParser.super(contentLength) 16 | return this 17 | } 18 | 19 | func NewMaxForwardsParserFromLexer(lexer core.Lexer) *MaxForwardsParser { 20 | this := &MaxForwardsParser{} 21 | this.HeaderParser.superFromLexer(lexer) 22 | return this 23 | } 24 | 25 | func (this *MaxForwardsParser) super(hname string) { 26 | this.HeaderParser.super(hname) 27 | } 28 | 29 | func (this *MaxForwardsParser) Parse() (sh header.Header, ParseException error) { 30 | contentLength := header.NewMaxForwards() 31 | this.HeaderName(TokenTypes_MAX_FORWARDS) 32 | lexer := this.GetLexer() 33 | 34 | var number int 35 | if number, ParseException = lexer.Number(); ParseException != nil { 36 | return nil, ParseException 37 | } 38 | if ParseException = contentLength.SetMaxForwards(number); ParseException != nil { 39 | return nil, ParseException 40 | } 41 | lexer.SPorHT() 42 | lexer.Match('\n') 43 | 44 | return contentLength, nil 45 | } 46 | -------------------------------------------------------------------------------- /sip/parser/MaxForwardsParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMaxForwardsParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Max-Forwards: 35\n", 10 | //"Max-Forwards: 3495\n", 11 | "Max-Forwards: 0 \n", 12 | } 13 | var tvo = []string{ 14 | "Max-Forwards: 35\n", 15 | //"Max-Forwards: 0\n", 16 | "Max-Forwards: 0 \n", 17 | } 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewMaxForwardsParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sip/parser/MimeVersionParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for MimeVersion header. 9 | */ 10 | type MimeVersionParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** Creates a new instance of MimeVersionParser 15 | * @param mimeVersion the header to parse 16 | */ 17 | func NewMimeVersionParser(mimeVersion string) *MimeVersionParser { 18 | this := &MimeVersionParser{} 19 | this.HeaderParser.super(mimeVersion) 20 | return this 21 | } 22 | 23 | /** Cosntructor 24 | * @param lexer the lexer to use to parse the header 25 | */ 26 | func NewMimeVersionParserFromLexer(lexer core.Lexer) *MimeVersionParser { 27 | this := &MimeVersionParser{} 28 | this.HeaderParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return Header (MimeVersion object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *MimeVersionParser) Parse() (sh header.Header, ParseException error) { 37 | mimeVersion := header.NewMimeVersion() 38 | 39 | lexer := this.GetLexer() 40 | this.HeaderName(TokenTypes_MIME_VERSION) 41 | 42 | mimeVersion.SetHeaderName(core.SIPHeaderNames_MIME_VERSION) 43 | 44 | var majorVersion, minorVersion int 45 | if majorVersion, ParseException = lexer.Number(); ParseException != nil { 46 | return nil, ParseException 47 | } 48 | mimeVersion.SetMajorVersion(majorVersion) 49 | lexer.Match('.') 50 | if minorVersion, ParseException = lexer.Number(); ParseException != nil { 51 | return nil, ParseException 52 | } 53 | mimeVersion.SetMinorVersion(minorVersion) 54 | 55 | lexer.SPorHT() 56 | 57 | lexer.Match('\n') 58 | 59 | return mimeVersion, nil 60 | } 61 | -------------------------------------------------------------------------------- /sip/parser/MimeVersionParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMimeVersionParser(t *testing.T) { 8 | var tvi = []string{ 9 | "MIME-Version: 1.0 \n", 10 | } 11 | var tvo = []string{ 12 | "MIME-Version: 1.0 \n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewMimeVersionParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program 22 | public static void main(String args[]) throws ParseException { 23 | String r[] = { 24 | "MIME-Version: 1.0 \n" 25 | }; 26 | 27 | for (int i = 0; i < r.length; i++ ) { 28 | MimeVersionParser parser = 29 | new MimeVersionParser(r[i]); 30 | MimeVersion m= (MimeVersion) parser.parse(); 31 | System.out.println("encoded = " +m.encode()); 32 | } 33 | } 34 | */ 35 | -------------------------------------------------------------------------------- /sip/parser/MinExpiresParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for MinExpires header. 9 | */ 10 | type MinExpiresParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** protected constructor. 15 | *@param text is the text of the header to parse 16 | */ 17 | func NewMinExpiresParser(minExpires string) *MinExpiresParser { 18 | this := &MinExpiresParser{} 19 | this.HeaderParser.super(minExpires) 20 | return this 21 | } 22 | 23 | /** constructor. 24 | *@param lexer is the lexer passed in from the enclosing parser. 25 | */ 26 | func NewMinExpiresParserFromLexer(lexer core.Lexer) *MinExpiresParser { 27 | this := &MinExpiresParser{} 28 | this.HeaderParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return Header (MinExpiresParser) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *MinExpiresParser) Parse() (sh header.Header, ParseException error) { 37 | minExpires := header.NewMinExpires() 38 | 39 | lexer := this.GetLexer() 40 | this.HeaderName(TokenTypes_MIN_EXPIRES) 41 | 42 | minExpires.SetHeaderName(core.SIPHeaderNames_MIN_EXPIRES) 43 | 44 | var number int 45 | if number, ParseException = lexer.Number(); ParseException != nil { 46 | return nil, ParseException 47 | } 48 | 49 | minExpires.SetExpires(number) 50 | 51 | lexer.SPorHT() 52 | 53 | lexer.Match('\n') 54 | 55 | return minExpires, nil 56 | } 57 | -------------------------------------------------------------------------------- /sip/parser/MinExpiresParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestMinExpiresParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Min-Expires: 60 \n", 10 | } 11 | var tvo = []string{ 12 | "Min-Expires: 60 \n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewMinExpiresParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program 22 | public static void main(String args[]) throws ParseException { 23 | String r[] = { 24 | "Min-Expires: 60 \n" 25 | }; 26 | 27 | for (int i = 0; i < r.length; i++ ) { 28 | MinExpiresParser parser = 29 | new MinExpiresParser(r[i]); 30 | MinExpires m= (MinExpires) parser.parse(); 31 | System.out.println("encoded = " +m.encode()); 32 | } 33 | } 34 | */ 35 | -------------------------------------------------------------------------------- /sip/parser/OrganizationParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | "strings" 7 | ) 8 | 9 | /** SIPParser for Organization header. 10 | */ 11 | type OrganizationParser struct { 12 | HeaderParser 13 | } 14 | 15 | /** Creates a new instance of OrganizationParser 16 | * @param organization the header to parse 17 | */ 18 | func NewOrganizationParser(organization string) *OrganizationParser { 19 | this := &OrganizationParser{} 20 | this.HeaderParser.super(organization) 21 | return this 22 | } 23 | 24 | /** Constructor 25 | * @param lexer the lexer to use to parse the header 26 | */ 27 | func NewOrganizationParserFromLexer(lexer core.Lexer) *OrganizationParser { 28 | this := &OrganizationParser{} 29 | this.HeaderParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** parse the String header 34 | * @return Header (Organization object) 35 | * @throws SIPParseException if the message does not respect the spec. 36 | */ 37 | func (this *OrganizationParser) Parse() (sh header.Header, ParseException error) { 38 | organization := header.NewOrganization() 39 | 40 | lexer := this.GetLexer() 41 | this.HeaderName(TokenTypes_ORGANIZATION) 42 | 43 | organization.SetHeaderName(core.SIPHeaderNames_ORGANIZATION) 44 | 45 | lexer.SPorHT() 46 | value := lexer.GetRest() 47 | 48 | organization.SetOrganization(strings.TrimSpace(value)) 49 | 50 | return organization, nil 51 | } 52 | -------------------------------------------------------------------------------- /sip/parser/OrganizationParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestOrganizationParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Organization: Boxes by Bob\n", 10 | } 11 | var tvo = []string{ 12 | "Organization: Boxes by Bob\n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewOrganizationParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program 22 | public static void main(String args[]) throws ParseException { 23 | String o[] = { 24 | "Organization: Boxes by Bob\n" 25 | }; 26 | 27 | for (int i = 0; i 17 | *

  • 1. Re-throwing an exception and aborting the parse. 18 | *
  • 2. Ignoring the header (attach the unparseable header to 19 | * the SIPMessage being parsed). 20 | *
  • 3. Re-Parsing the bad header and adding it to the sipMessage 21 | * 22 | * 23 | *@param ex - parse exception being processed. 24 | *@param sipMessage -- sip message being processed. 25 | *@param headerText -- header/RL/SL text being parsed. 26 | *@param messageText -- message where this header was detected. 27 | */ 28 | HandleException(err error, 29 | sipMessage message.Message, 30 | //headerClass interface{}, 31 | headerText string, 32 | messageText string) (ParseException error) 33 | } 34 | -------------------------------------------------------------------------------- /sip/parser/PriorityParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Priority header. 9 | */ 10 | type PriorityParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** Creates a new instance of PriorityParser 15 | * @param priority the header to parse 16 | */ 17 | func NewPriorityParser(priority string) *PriorityParser { 18 | this := &PriorityParser{} 19 | this.HeaderParser.super(priority) 20 | return this 21 | } 22 | 23 | /** Constructor 24 | * @param lexer the lexer to use to parse the header 25 | */ 26 | func NewPriorityParserFromLexer(lexer core.Lexer) *PriorityParser { 27 | this := &PriorityParser{} 28 | this.HeaderParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String header 33 | * @return SIPHeader (Priority object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *PriorityParser) Parse() (sh header.Header, ParseException error) { 37 | priority := header.NewPriority() 38 | 39 | lexer := this.GetLexer() 40 | this.HeaderName(TokenTypes_PRIORITY) 41 | 42 | priority.SetHeaderName(core.SIPHeaderNames_PRIORITY) 43 | 44 | lexer.SPorHT() 45 | lexer.Match(TokenTypes_ID) 46 | token := lexer.GetNextToken() 47 | 48 | priority.SetPriority(token.GetTokenValue()) 49 | 50 | lexer.SPorHT() 51 | lexer.Match('\n') 52 | 53 | return priority, nil 54 | } 55 | -------------------------------------------------------------------------------- /sip/parser/PriorityParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestPriorityParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Priority: emergency\n", 10 | } 11 | var tvo = []string{ 12 | "Priority: emergency\n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewPriorityParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program 22 | public static void main(String args[]) throws ParseException { 23 | String p[] = { 24 | "Priority: emergency\n" 25 | }; 26 | 27 | for (int i = 0; i < p.length; i++ ) { 28 | PriorityParser parser = 29 | new PriorityParser(p[i]); 30 | Priority prio= (Priority) parser.parse(); 31 | System.out.println("encoded = " + prio.encode()); 32 | } 33 | } 34 | */ 35 | -------------------------------------------------------------------------------- /sip/parser/ProxyAuthenticateParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for ProxyAuthenticate headers. 9 | */ 10 | type ProxyAuthenticateParser struct { 11 | ChallengeParser 12 | } 13 | 14 | /** Constructor 15 | * @param String paAuthenticate message to parse 16 | */ 17 | func NewProxyAuthenticateParser(proxyAuthenticate string) *ProxyAuthenticateParser { 18 | this := &ProxyAuthenticateParser{} 19 | this.ChallengeParser.super(proxyAuthenticate) 20 | return this 21 | } 22 | 23 | /** Cosntructor 24 | * @param lexer to set 25 | */ 26 | func NewProxyAuthenticateParserFromLexer(lexer core.Lexer) *ProxyAuthenticateParser { 27 | this := &ProxyAuthenticateParser{} 28 | this.ChallengeParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader (ProxyAuthenticate object) 34 | * @throws ParseException if the message does not respect the spec. 35 | */ 36 | func (this *ProxyAuthenticateParser) Parse() (sh header.Header, ParseException error) { 37 | this.HeaderName(TokenTypes_PROXY_AUTHENTICATE) 38 | proxyAuthenticate := header.NewProxyAuthenticate() 39 | ParseException = this.ChallengeParser.Parse(proxyAuthenticate) 40 | return proxyAuthenticate, ParseException 41 | } 42 | -------------------------------------------------------------------------------- /sip/parser/ProxyAuthenticateParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestProxyAuthenticateParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\"," + 10 | "domain=\"sip:ss2.wcom.com\", nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\"," + 11 | "opaque=\"\", stale=FALSE, algorithm=MD5\n", 12 | 13 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\"," + 14 | "qop=\"auth\" , nonce-value=\"oli\"\n", 15 | } 16 | var tvo = []string{ 17 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\"," + 18 | "domain=\"sip:ss2.wcom.com\",nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\"," + 19 | "opaque=\"\",stale=FALSE,algorithm=\"MD5\"\n", 20 | 21 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\"," + 22 | "qop=\"auth\",nonce-value=oli\n", 23 | } 24 | 25 | for i := 0; i < len(tvi); i++ { 26 | shp := NewProxyAuthenticateParser(tvi[i]) 27 | testHeaderParser(t, shp, tvo[i]) 28 | } 29 | } 30 | 31 | /** Test program 32 | public static void main(String args[]) throws ParseException { 33 | String paAuth[] = { 34 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\","+ 35 | "domain=\"sip:ss2.wcom.com\", nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\","+ 36 | "opaque=\"\", stale=FALSE, algorithm=MD5\n", 37 | 38 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\","+ 39 | "qop=\"auth\" , nonce-value=\"oli\"\n" 40 | }; 41 | 42 | for (int i = 0; i < paAuth.length; i++ ) { 43 | ProxyAuthenticateParser pap = 44 | new ProxyAuthenticateParser(paAuth[i]); 45 | ProxyAuthenticate pa= (ProxyAuthenticate) pap.parse(); 46 | System.out.println("encoded = " + pa.encode()); 47 | } 48 | 49 | } 50 | */ 51 | -------------------------------------------------------------------------------- /sip/parser/ProxyAuthorizationParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for ProxyAuthorization headers. 9 | */ 10 | type ProxyAuthorizationParser struct { 11 | ChallengeParser 12 | } 13 | 14 | /** Constructor 15 | * @param proxyAuthorization -- header to parse 16 | */ 17 | func NewProxyAuthorizationParser(proxyAuthorization string) *ProxyAuthorizationParser { 18 | this := &ProxyAuthorizationParser{} 19 | this.ChallengeParser.super(proxyAuthorization) 20 | return this 21 | } 22 | 23 | /** Cosntructor 24 | * @param lexer to set 25 | */ 26 | func NewProxyAuthorizationParserFromLexer(lexer core.Lexer) *ProxyAuthorizationParser { 27 | this := &ProxyAuthorizationParser{} 28 | this.ChallengeParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader (ProxyAuthenticate object) 34 | * @throws ParseException if the message does not respect the spec. 35 | */ 36 | func (this *ProxyAuthorizationParser) Parse() (sh header.Header, ParseException error) { 37 | this.HeaderName(TokenTypes_PROXY_AUTHORIZATION) 38 | proxyAuth := header.NewProxyAuthorization() 39 | ParseException = this.ChallengeParser.Parse(proxyAuth) 40 | return proxyAuth, ParseException 41 | } 42 | -------------------------------------------------------------------------------- /sip/parser/ProxyAuthorizationParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestProxyAuthorizationParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Proxy-Authorization: Digest realm=\"MCI WorldCom SIP\"," + 10 | "domain=\"sip:ss2.wcom.com\",nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\"," + 11 | "opaque=\"\",stale=FALSE,algorithm=MD5\n", 12 | 13 | "Proxy-Authorization: Digest realm=\"MCI WorldCom SIP\"," + 14 | "qop=\"auth\",nonce-value=\"oli\"\n", 15 | } 16 | var tvo = []string{ 17 | "Proxy-Authorization: Digest realm=\"MCI WorldCom SIP\"," + 18 | "domain=\"sip:ss2.wcom.com\",nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\"," + 19 | "opaque=\"\",stale=FALSE,algorithm=\"MD5\"\n", 20 | 21 | "Proxy-Authorization: Digest realm=\"MCI WorldCom SIP\"," + 22 | "qop=\"auth\",nonce-value=oli\n", 23 | } 24 | 25 | for i := 0; i < len(tvi); i++ { 26 | shp := NewProxyAuthorizationParser(tvi[i]) 27 | testHeaderParser(t, shp, tvo[i]) 28 | } 29 | } 30 | 31 | /** Test program 32 | public static void main(String args[]) throws ParseException { 33 | String paAuth[] = { 34 | "Proxy-Authorization: Digest realm=\"MCI WorldCom SIP\","+ 35 | "domain=\"sip:ss2.wcom.com\", nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\","+ 36 | "opaque=\"\", stale=FALSE, algorithm=MD5\n", 37 | 38 | "Proxy-Authenticate: Digest realm=\"MCI WorldCom SIP\","+ 39 | "qop=\"auth\" , nonce-value=\"oli\"\n" 40 | }; 41 | 42 | for (int i = 0; i < paAuth.length; i++ ) { 43 | ProxyAuthorizationParser pap = 44 | new ProxyAuthorizationParser(paAuth[i]); 45 | ProxyAuthorization pa= (ProxyAuthorization) pap.parse(); 46 | System.out.println("encoded = " + pa.encode()); 47 | } 48 | 49 | } 50 | */ 51 | -------------------------------------------------------------------------------- /sip/parser/ProxyRequireParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestProxyRequireParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Proxy-Require: foo \n", 10 | "Proxy-Require: foo1,foo2,389\n", 11 | } 12 | var tvo = []string{ 13 | "Proxy-Require: foo \n", 14 | "Proxy-Require: foo1,foo2,389\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewProxyRequireParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Proxy-Require: foo \n", 27 | "Proxy-Require: foo1, foo2 , 389\n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | ProxyRequireParser parser = 32 | new ProxyRequireParser(r[i]); 33 | ProxyRequireList rl= (ProxyRequireList) parser.parse(); 34 | System.out.println("encoded = " + rl.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/RAckParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for RAck header. 9 | */ 10 | type RAckParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** Creates a new instance of RAckParser 15 | *@param rack the header to parse 16 | */ 17 | func NewRAckParser(rack string) *RAckParser { 18 | this := &RAckParser{} 19 | this.HeaderParser.super(rack) 20 | return this 21 | } 22 | 23 | /** Constructor 24 | * @param lexer the lexer to use to parse the header 25 | */ 26 | func NewRAckParserFromLexer(lexer core.Lexer) *RAckParser { 27 | this := &RAckParser{} 28 | this.HeaderParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader (RAck object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *RAckParser) Parse() (sh header.Header, ParseException error) { 37 | rack := header.NewRAck() 38 | 39 | lexer := this.GetLexer() 40 | this.HeaderName(TokenTypes_RACK) 41 | 42 | rack.SetHeaderName(core.SIPHeaderNames_RACK) 43 | 44 | var number int 45 | if number, ParseException = lexer.Number(); ParseException != nil { 46 | return nil, ParseException 47 | } 48 | rack.SetRSeqNumber(number) 49 | lexer.SPorHT() 50 | if number, ParseException = lexer.Number(); ParseException != nil { 51 | return nil, ParseException 52 | } 53 | rack.SetCSeqNumber(number) 54 | lexer.SPorHT() 55 | lexer.Match(TokenTypes_ID) 56 | token := lexer.GetNextToken() 57 | rack.SetMethod(token.GetTokenValue()) 58 | 59 | lexer.SPorHT() 60 | lexer.Match('\n') 61 | 62 | return rack, nil 63 | } 64 | -------------------------------------------------------------------------------- /sip/parser/RAckParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestRAckParser(t *testing.T) { 8 | var tvi = []string{ 9 | "RAck: 776656 1 INVITE\n", 10 | } 11 | var tvo = []string{ 12 | "RAck: 776656 1 INVITE\n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewRAckParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program 22 | public static void main(String args[]) throws ParseException { 23 | String r[] = { 24 | "RAck: 776656 1 INVITE\n" 25 | }; 26 | 27 | for (int i = 0; i < r.length; i++ ) { 28 | RAckParser parser = 29 | new RAckParser(r[i]); 30 | RAck ra= (RAck) parser.parse(); 31 | System.out.println("encoded = " + ra.encode()); 32 | } 33 | } 34 | */ 35 | -------------------------------------------------------------------------------- /sip/parser/RSeqParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for RSeq header. 9 | */ 10 | type RSeqParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** Creates a new instance of RSeqParser 15 | *@param rseq the header to parse 16 | */ 17 | func NewRSeqParser(rseq string) *RSeqParser { 18 | this := &RSeqParser{} 19 | this.HeaderParser.super(rseq) 20 | return this 21 | } 22 | 23 | /** Constructor 24 | * param lexer the lexer to use to parse the header 25 | */ 26 | func NewRSeqParserFromLexer(lexer core.Lexer) *RSeqParser { 27 | this := &RSeqParser{} 28 | this.HeaderParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader ( RSeq object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *RSeqParser) Parse() (sh header.Header, ParseException error) { 37 | rseq := header.NewRSeq() 38 | 39 | lexer := this.GetLexer() 40 | this.HeaderName(TokenTypes_RSEQ) 41 | 42 | rseq.SetHeaderName(core.SIPHeaderNames_RSEQ) 43 | 44 | var number int 45 | if number, ParseException = lexer.Number(); ParseException != nil { 46 | return nil, ParseException 47 | } 48 | rseq.SetSequenceNumber(number) 49 | 50 | lexer.SPorHT() 51 | lexer.Match('\n') 52 | 53 | return rseq, nil 54 | } 55 | -------------------------------------------------------------------------------- /sip/parser/RSeqParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestRSeqParser(t *testing.T) { 8 | var tvi = []string{ 9 | "RSeq: 988789 \n", 10 | } 11 | var tvo = []string{ 12 | "RSeq: 988789 \n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewRSeqParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** Test program 22 | public static void main(String args[]) throws ParseException { 23 | String r[] = { 24 | "RSeq: 988789 \n" 25 | }; 26 | 27 | for (int i = 0; i < r.length; i++ ) { 28 | RSeqParser parser = 29 | new RSeqParser(r[i]); 30 | RSeq rs= (RSeq) parser.parse(); 31 | System.out.println("encoded = " + rs.encode()); 32 | } 33 | } 34 | */ 35 | -------------------------------------------------------------------------------- /sip/parser/ReasonParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Reason header. 9 | */ 10 | type ReasonParser struct { 11 | ParametersParser 12 | } 13 | 14 | /** Creates a new instance of ReasonParser 15 | * @param reason the header to parse 16 | */ 17 | func NewReasonParser(reason string) *ReasonParser { 18 | this := &ReasonParser{} 19 | this.ParametersParser.super(reason) 20 | return this 21 | } 22 | 23 | /** Constructor 24 | * @param lexer the lexer to use to parse the header 25 | */ 26 | func NewReasonParserFromLexer(lexer core.Lexer) *ReasonParser { 27 | this := &ReasonParser{} 28 | this.ParametersParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader (ReasonParserList object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *ReasonParser) Parse() (sh header.Header, ParseException error) { 37 | reasonList := header.NewReasonList() 38 | 39 | var ch byte 40 | lexer := this.GetLexer() 41 | this.HeaderName(TokenTypes_REASON) 42 | lexer.SPorHT() 43 | for ch, _ = lexer.LookAheadK(0); ch != '\n'; ch, _ = lexer.LookAheadK(0) { 44 | reason := header.NewReason() 45 | lexer.Match(TokenTypes_ID) 46 | token := lexer.GetNextToken() 47 | value := token.GetTokenValue() 48 | 49 | reason.SetProtocol(value) 50 | if ParseException = this.ParametersParser.Parse(reason); ParseException != nil { 51 | return nil, ParseException 52 | } 53 | reasonList.PushBack(reason) 54 | if ch, _ = lexer.LookAheadK(0); ch == ',' { 55 | lexer.Match(',') 56 | lexer.SPorHT() 57 | } else { 58 | lexer.SPorHT() 59 | } 60 | 61 | } 62 | 63 | return reasonList, nil 64 | } 65 | -------------------------------------------------------------------------------- /sip/parser/ReasonParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestReasonParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Reason: SIP ;cause=200 ;text=\"Call completed elsewhere\"\n", 10 | "Reason: Q.850 ;cause=16 ;text=\"Terminated\"\n", 11 | "Reason: SIP ;cause=600 ;text=\"Busy Everywhere\"\n", 12 | "Reason: SIP ;cause=580 ;text=\"Precondition Failure\"," + 13 | "SIP ;cause=530 ;text=\"Pre Failure\"\n", 14 | "Reason: SIP \n", 15 | } 16 | var tvo = []string{ 17 | "Reason: SIP;cause=200;text=\"Call completed elsewhere\"\n", 18 | "Reason: Q.850;cause=16;text=\"Terminated\"\n", 19 | "Reason: SIP;cause=600;text=\"Busy Everywhere\"\n", 20 | "Reason: SIP;cause=580;text=\"Precondition Failure\"," + 21 | "SIP;cause=530;text=\"Pre Failure\"\n", 22 | "Reason: SIP \n", 23 | } 24 | 25 | for i := 0; i < len(tvi); i++ { 26 | shp := NewReasonParser(tvi[i]) 27 | testHeaderParser(t, shp, tvo[i]) 28 | } 29 | } 30 | 31 | /** Test program 32 | public static void main(String args[]) throws ParseException { 33 | String r[] = { 34 | "Reason: SIP ;cause=200 ;text=\"Call completed elsewhere\"\n", 35 | "Reason: Q.850 ;cause=16 ;text=\"Terminated\"\n", 36 | "Reason: SIP ;cause=600 ;text=\"Busy Everywhere\"\n", 37 | "Reason: SIP ;cause=580 ;text=\"Precondition Failure\","+ 38 | "SIP ;cause=530 ;text=\"Pre Failure\"\n", 39 | "Reason: SIP \n" 40 | }; 41 | 42 | for (int i = 0; i < r.length; i++ ) { 43 | ReasonParser parser = 44 | new ReasonParser(r[i]); 45 | ReasonList rl= (ReasonList) parser.parse(); 46 | System.out.println("encoded = " + rl.encode()); 47 | } 48 | } 49 | */ 50 | -------------------------------------------------------------------------------- /sip/parser/RecordRouteParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for a list of route headers. 9 | */ 10 | type RecordRouteParser struct { 11 | AddressParametersParser 12 | } 13 | 14 | /** Constructor 15 | * @param String recordRoute message to parse to set 16 | */ 17 | func NewRecordRouteParser(recordRoute string) *RecordRouteParser { 18 | this := &RecordRouteParser{} 19 | this.AddressParametersParser.super(recordRoute) 20 | return this 21 | } 22 | 23 | func NewRecordRouteParserFromLexer(lexer core.Lexer) *RecordRouteParser { 24 | this := &RecordRouteParser{} 25 | this.AddressParametersParser.superFromLexer(lexer) 26 | return this 27 | } 28 | 29 | /** parse the String message and generate the RecordRoute List Object 30 | * @return SIPHeader the RecordRoute List object 31 | * @throws ParseException if errors occur during the parsing 32 | */ 33 | func (this *RecordRouteParser) Parse() (sh header.Header, ParseException error) { 34 | recordRouteList := header.NewRecordRouteList() 35 | 36 | var ch byte 37 | lexer := this.GetLexer() 38 | lexer.Match(TokenTypes_RECORD_ROUTE) 39 | lexer.SPorHT() 40 | lexer.Match(':') 41 | lexer.SPorHT() 42 | for { 43 | recordRoute := header.NewRecordRoute() 44 | this.AddressParametersParser.Parse(recordRoute) 45 | recordRouteList.PushBack(recordRoute) 46 | lexer.SPorHT() 47 | if ch, _ = lexer.LookAheadK(0); ch == ',' { 48 | lexer.Match(',') 49 | lexer.SPorHT() 50 | } else if ch, _ = lexer.LookAheadK(0); ch == '\n' { 51 | break 52 | } else { 53 | return nil, this.CreateParseException("unexpected char") 54 | } 55 | } 56 | 57 | return recordRouteList, nil 58 | } 59 | -------------------------------------------------------------------------------- /sip/parser/ReferToParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** ReferTo Header parser. 9 | */ 10 | type ReferToParser struct { 11 | AddressParametersParser 12 | } 13 | 14 | /** Creates new ReferToParser 15 | * @param String to set 16 | */ 17 | func NewReferToParser(referTo string) *ReferToParser { 18 | this := &ReferToParser{} 19 | this.AddressParametersParser.super(referTo) 20 | return this 21 | } 22 | 23 | func NewReferToParserFromLexer(lexer core.Lexer) *ReferToParser { 24 | this := &ReferToParser{} 25 | this.AddressParametersParser.superFromLexer(lexer) 26 | return this 27 | } 28 | 29 | func (this *ReferToParser) Parse() (sh header.Header, ParseException error) { 30 | lexer := this.GetLexer() 31 | this.HeaderName(TokenTypes_REFER_TO) 32 | referTo := header.NewReferTo() 33 | if ParseException = this.AddressParametersParser.Parse(referTo); ParseException != nil { 34 | return nil, ParseException 35 | } 36 | lexer.Match('\n') 37 | return referTo, nil 38 | } 39 | -------------------------------------------------------------------------------- /sip/parser/ReferToParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestReferToParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Refer-To: ;tag=5617\n", 10 | "Refer-To: T. A. Watson \n", 11 | "Refer-To: LittleGuy \n", 12 | "Refer-To: sip:mranga@120.6.55.9\n", 13 | "Refer-To: sip:mranga@129.6.55.9 ; tag=696928473514.129.6.55.9\n", 14 | } 15 | var tvo = []string{ 16 | "Refer-To: ;tag=5617\n", 17 | "Refer-To: \"T. A. Watson\" \n", 18 | "Refer-To: \"LittleGuy\" \n", 19 | "Refer-To: \n", 20 | "Refer-To: ;tag=696928473514.129.6.55.9\n", 21 | } 22 | 23 | for i := 0; i < len(tvi); i++ { 24 | shp := NewReferToParser(tvi[i]) 25 | testHeaderParser(t, shp, tvo[i]) 26 | } 27 | } 28 | 29 | /* 30 | public static void main(String args[]) throws ParseException { 31 | String to[] = { 32 | "Refer-To: ;tag=5617\n", 33 | "Refer-To: T. A. Watson \n", 34 | "Refer-To: LittleGuy \n", 35 | "Refer-To: sip:mranga@120.6.55.9\n", 36 | "Refer-To: sip:mranga@129.6.55.9 ; tag=696928473514.129.6.55.9\n" 37 | }; 38 | 39 | for (int i = 0; i < to.length; i++ ) { 40 | ReferToParser tp = 41 | new ReferToParser(to[i]); 42 | ReferTo t = (ReferTo) tp.parse(); 43 | System.out.println("encoded = " + t.encode()); 44 | } 45 | 46 | }*/ 47 | -------------------------------------------------------------------------------- /sip/parser/ReplyToParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for a list of RelpyTo headers. 9 | */ 10 | 11 | type ReplyToParser struct { 12 | AddressParametersParser 13 | } 14 | 15 | /** Creates a new instance of ReplyToParser 16 | * @param replyTo the header to parse 17 | */ 18 | func NewReplyToParser(replyTo string) *ReplyToParser { 19 | this := &ReplyToParser{} 20 | this.AddressParametersParser.super(replyTo) 21 | return this 22 | } 23 | 24 | /** Cosntructor 25 | * param lexer the lexer to use to parse the header 26 | */ 27 | func NewReplyToParserFromLexer(lexer core.Lexer) *ReplyToParser { 28 | this := &ReplyToParser{} 29 | this.AddressParametersParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** parse the String message and generate the ReplyTo List Object 34 | * @return SIPHeader the ReplyTo List object 35 | * @throws SIPParseException if errors occur during the parsing 36 | */ 37 | func (this *ReplyToParser) Parse() (sh header.Header, ParseException error) { 38 | replyTo := header.NewReplyTo() 39 | 40 | this.HeaderName(TokenTypes_REPLY_TO) 41 | 42 | replyTo.SetHeaderName(core.SIPHeaderNames_REPLY_TO) 43 | 44 | ParseException = this.AddressParametersParser.Parse(replyTo) 45 | 46 | return replyTo, ParseException 47 | } 48 | -------------------------------------------------------------------------------- /sip/parser/ReplyToParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestReplyToParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Reply-To: Bob \n", 10 | } 11 | var tvo = []string{ 12 | "Reply-To: \"Bob\" \n", 13 | } 14 | 15 | for i := 0; i < len(tvi); i++ { 16 | shp := NewReplyToParser(tvi[i]) 17 | testHeaderParser(t, shp, tvo[i]) 18 | } 19 | } 20 | 21 | /** 22 | public static void main(String args[]) throws ParseException { 23 | String r[] = { 24 | "Reply-To: Bob \n" 25 | }; 26 | 27 | for (int i = 0; i < r.length; i++ ) { 28 | ReplyToParser rt = 29 | new ReplyToParser(r[i]); 30 | ReplyTo re = (ReplyTo) rt.parse(); 31 | System.out.println("encoded = " +re.encode()); 32 | } 33 | 34 | } 35 | */ 36 | -------------------------------------------------------------------------------- /sip/parser/RequestLineParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/address" 6 | "gosips/sip/header" 7 | ) 8 | 9 | /** SIPParser for the SIP request line. 10 | */ 11 | type RequestLineParser struct { 12 | SIPParser 13 | } 14 | 15 | func NewRequestLineParser(requestLine string) *RequestLineParser { 16 | this := &RequestLineParser{} 17 | this.CoreParser.Super(requestLine) 18 | this.SetLexer(NewSIPLexer("method_keywordLexer", requestLine)) 19 | return this 20 | } 21 | func NewRequestLineParserFromLexer(lexer core.Lexer) *RequestLineParser { 22 | this := &RequestLineParser{} 23 | this.SetLexer(lexer) 24 | this.GetLexer().SelectLexer("method_keywordLexer") 25 | return this 26 | } 27 | 28 | func (this *RequestLineParser) Parse() (rl *header.RequestLine, ParseException error) { 29 | var m, v string 30 | var url address.URI 31 | 32 | retval := header.NewRequestLine() 33 | lexer := this.GetLexer() 34 | 35 | if m, ParseException = this.Method(); ParseException != nil { 36 | return nil, ParseException 37 | } 38 | 39 | lexer.SPorHT() 40 | retval.SetMethod(m) 41 | lexer.SelectLexer("sip_urlLexer") 42 | urlParser := NewURLParserFromLexer(this.GetLexer()) 43 | if url, ParseException = urlParser.UriReference(); ParseException != nil { 44 | return nil, ParseException 45 | } 46 | lexer.SPorHT() 47 | retval.SetUri(url) 48 | lexer.SelectLexer("request_lineLexer") 49 | 50 | if v, ParseException = this.SipVersion(); ParseException != nil { 51 | return nil, ParseException 52 | } 53 | retval.SetSipVersion(v) 54 | lexer.SPorHT() 55 | lexer.Match('\n') 56 | 57 | return retval, nil 58 | } 59 | -------------------------------------------------------------------------------- /sip/parser/RequireParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for Require header. 9 | */ 10 | type RequireParser struct { 11 | HeaderParser 12 | } 13 | 14 | /** Creates a new instance of RequireParser 15 | * @param require the header to parse 16 | */ 17 | func NewRequireParser(require string) *RequireParser { 18 | this := &RequireParser{} 19 | this.HeaderParser.super(require) 20 | return this 21 | } 22 | 23 | /** Constructor 24 | * @param lexer the lexer to use to parse the header 25 | */ 26 | func NewRequireParserFromLexer(lexer core.Lexer) *RequireParser { 27 | this := &RequireParser{} 28 | this.HeaderParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader (RequireList object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *RequireParser) Parse() (sh header.Header, ParseException error) { 37 | requireList := header.NewRequireList() 38 | 39 | var ch byte 40 | lexer := this.GetLexer() 41 | this.HeaderName(TokenTypes_REQUIRE) 42 | 43 | for ch, _ = lexer.LookAheadK(0); ch != '\n'; ch, _ = lexer.LookAheadK(0) { 44 | r := header.NewRequire() 45 | r.SetHeaderName(core.SIPHeaderNames_REQUIRE) 46 | 47 | // Parsing the option tag 48 | lexer.Match(TokenTypes_ID) 49 | token := lexer.GetNextToken() 50 | r.SetOptionTag(token.GetTokenValue()) 51 | lexer.SPorHT() 52 | 53 | requireList.PushBack(r) 54 | 55 | for ch, _ = lexer.LookAheadK(0); ch == ','; ch, _ = lexer.LookAheadK(0) { 56 | lexer.Match(',') 57 | lexer.SPorHT() 58 | 59 | r = header.NewRequire() 60 | 61 | // Parsing the option tag 62 | lexer.Match(TokenTypes_ID) 63 | token = lexer.GetNextToken() 64 | r.SetOptionTag(token.GetTokenValue()) 65 | lexer.SPorHT() 66 | 67 | requireList.PushBack(r) 68 | } 69 | 70 | } 71 | 72 | return requireList, nil 73 | } 74 | -------------------------------------------------------------------------------- /sip/parser/RequireParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestRequireParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Require: 100rel \n", 10 | "Require: 100rel,200ok,389\n", 11 | } 12 | var tvo = []string{ 13 | "Require: 100rel \n", 14 | "Require: 100rel,200ok,389\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewRequireParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String r[] = { 26 | "Require: 100rel \n", 27 | "Require: 100rel, 200ok , 389\n" 28 | }; 29 | 30 | for (int i = 0; i < r.length; i++ ) { 31 | RequireParser parser = 32 | new RequireParser(r[i]); 33 | RequireList rl= (RequireList) parser.parse(); 34 | System.out.println("encoded = " + rl.encode()); 35 | } 36 | } 37 | */ 38 | -------------------------------------------------------------------------------- /sip/parser/RetryAfterParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestRetryAfterParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Retry-After: 18000;duration=3600\n", 10 | "Retry-After: 120;duration=3600;ra=oli\n", 11 | "Retry-After: 1220 (I'm in a meeting)\n", 12 | "Retry-After: 1230 (I'm in a meeting);fg=der;duration=23\n", 13 | } 14 | var tvo = []string{ 15 | "Retry-After: 18000;duration=3600\n", 16 | "Retry-After: 120;duration=3600;ra=oli\n", 17 | "Retry-After: 1220 (I'm in a meeting)\n", 18 | "Retry-After: 1230 (I'm in a meeting);fg=der;duration=23\n", 19 | } 20 | 21 | for i := 0; i < len(tvi); i++ { 22 | shp := NewRetryAfterParser(tvi[i]) 23 | testHeaderParser(t, shp, tvo[i]) 24 | } 25 | } 26 | 27 | /** Test program 28 | public static void main(String args[]) throws ParseException { 29 | String rr[] = { 30 | "Retry-After: 18000;duration=3600\n", 31 | "Retry-After: 120;duration=3600;ra=oli\n", 32 | "Retry-After: 1220 (I'm in a meeting)\n", 33 | "Retry-After: 1230 (I'm in a meeting);fg=der;duration=23\n" 34 | }; 35 | 36 | for (int i = 0; i < rr.length; i++ ) { 37 | RetryAfterParser parser = 38 | new RetryAfterParser(rr[i]); 39 | RetryAfter r= (RetryAfter) parser.parse(); 40 | System.out.println("encoded = " + r.encode()); 41 | } 42 | 43 | } 44 | */ 45 | -------------------------------------------------------------------------------- /sip/parser/RouteParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for a list of route headers. 9 | */ 10 | 11 | type RouteParser struct { 12 | AddressParametersParser 13 | } 14 | 15 | /** Constructor 16 | * @param String route message to parse to set 17 | */ 18 | func NewRouteParser(route string) *RouteParser { 19 | this := &RouteParser{} 20 | this.AddressParametersParser.super(route) 21 | return this 22 | } 23 | 24 | func NewRouteParserFromLexer(lexer core.Lexer) *RouteParser { 25 | this := &RouteParser{} 26 | this.AddressParametersParser.superFromLexer(lexer) 27 | return this 28 | } 29 | 30 | /** parse the String message and generate the Route List Object 31 | * @return SIPHeader the Route List object 32 | * @throws SIPParseException if errors occur during the parsing 33 | */ 34 | func (this *RouteParser) Parse() (sh header.Header, ParseException error) { 35 | routeList := header.NewRouteList() 36 | 37 | var ch byte 38 | lexer := this.GetLexer() 39 | lexer.Match(TokenTypes_ROUTE) 40 | lexer.SPorHT() 41 | lexer.Match(':') 42 | lexer.SPorHT() 43 | for { 44 | route := header.NewRoute() 45 | this.AddressParametersParser.Parse(route) 46 | routeList.PushBack(route) 47 | lexer.SPorHT() 48 | if ch, _ = lexer.LookAheadK(0); ch == ',' { 49 | lexer.Match(',') 50 | lexer.SPorHT() 51 | } else if ch, _ = lexer.LookAheadK(0); ch == '\n' { 52 | break 53 | } else { 54 | return nil, this.CreateParseException("unexpected char") 55 | } 56 | } 57 | 58 | return routeList, nil 59 | } 60 | -------------------------------------------------------------------------------- /sip/parser/RouteParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestRouteParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Route: \n", 10 | "Route: sip:bob@biloxi.com \n", 11 | "Route: sip:alice@atlanta.com, sip:bob@biloxi.com, sip:carol@chicago.com\n", 12 | } 13 | var tvo = []string{ 14 | "Route: \n", 15 | "Route: sip:bob@biloxi.com\n", 16 | "Route: sip:alice@atlanta.com,sip:bob@biloxi.com,sip:carol@chicago.com\n", 17 | } 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewRouteParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | 25 | /** 26 | public static void main(String args[]) throws ParseException { 27 | String rou[] = { 28 | "Route: \n", 29 | "Route: sip:bob@biloxi.com \n", 30 | "Route: sip:alice@atlanta.com, sip:bob@biloxi.com, sip:carol@chicago.com\n" 31 | }; 32 | 33 | for (int i = 0; i < rou.length; i++ ) { 34 | RouteParser rp = 35 | new RouteParser(rou[i]); 36 | RouteList routeList = (RouteList) rp.parse(); 37 | System.out.println("encoded = " +routeList.encode()); 38 | } 39 | 40 | } 41 | 42 | */ 43 | -------------------------------------------------------------------------------- /sip/parser/ServerParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "errors" 5 | "gosips/core" 6 | "gosips/sip/header" 7 | "strings" 8 | ) 9 | 10 | /** SIPParser for Server header. 11 | */ 12 | type ServerParser struct { 13 | HeaderParser 14 | } 15 | 16 | /** Creates a new instance of ServerParser 17 | * @param server the header to parse 18 | */ 19 | func NewServerParser(server string) *ServerParser { 20 | this := &ServerParser{} 21 | this.HeaderParser.super(server) 22 | return this 23 | } 24 | 25 | /** Constructor 26 | * @param lexer the lexer to use to parse the header 27 | */ 28 | func NewServerParserFromLexer(lexer core.Lexer) *ServerParser { 29 | this := &ServerParser{} 30 | this.HeaderParser.superFromLexer(lexer) 31 | return this 32 | } 33 | 34 | /** parse the String server 35 | * @return SIPHeader (Server object) 36 | * @throws SIPParseException if the message does not respect the spec. 37 | */ 38 | func (this *ServerParser) Parse() (sh header.Header, ParseException error) { 39 | server := header.NewServer() 40 | 41 | var ch byte 42 | lexer := this.GetLexer() 43 | this.HeaderName(TokenTypes_SERVER) 44 | if ch, _ = lexer.LookAheadK(0); ch == '\n' { 45 | return nil, errors.New("empty header") 46 | } 47 | 48 | // mandatory token: product[/product-version] | (comment) 49 | for ch, ParseException = lexer.LookAheadK(0); ch != '\n' && ParseException == nil; ch, ParseException = lexer.LookAheadK(0) { 50 | if ch == '(' { 51 | comment, _ := lexer.Comment() 52 | server.AddProductToken("(" + comment + ")") 53 | } else { 54 | var tok string 55 | tok, ParseException = lexer.GetString('/') 56 | if ParseException != nil { 57 | tok = lexer.GetRest() 58 | server.AddProductToken(tok) 59 | break 60 | } else { 61 | if tok[len(tok)-1] == '\n' { 62 | tok = strings.TrimSpace(tok) 63 | } 64 | server.AddProductToken(tok) 65 | } 66 | } 67 | } 68 | 69 | return server, nil 70 | } 71 | -------------------------------------------------------------------------------- /sip/parser/ServerParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestServerParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Server: Softphone/Beta1.5 \n", 10 | "Server: HomeServer v2\n", 11 | "Server: Nist/Beta1 (beta version) \n", 12 | "Server: Nist proxy (beta version)\n", 13 | "Server: Nist1.0/Beta2 UbiServer/vers.1.0 (new stuff) (Cool) \n", 14 | } 15 | var tvo = []string{ 16 | "Server: Softphone/Beta1.5 \n", 17 | "Server: HomeServer v2\n", 18 | "Server: Nist/Beta1 (beta version) \n", 19 | "Server: Nist proxy (beta version)\n", 20 | "Server: Nist1.0/Beta2 UbiServer/vers.1.0 (new stuff) (Cool) \n", 21 | } 22 | 23 | for i := 0; i < len(tvi); i++ { 24 | shp := NewServerParser(tvi[i]) 25 | testHeaderParser(t, shp, tvo[i]) 26 | } 27 | } 28 | 29 | /** Test program 30 | public static void main(String args[]) throws ParseException { 31 | String server[] = { 32 | "Server: Softphone/Beta1.5 \n", 33 | "Server: HomeServer v2\n", 34 | "Server: Nist/Beta1 (beta version) \n", 35 | "Server: Nist proxy (beta version)\n", 36 | "Server: Nist1.0/Beta2 UbiServer/vers.1.0 (new stuff) (Cool) \n" 37 | }; 38 | 39 | for (int i = 0; i < server.length; i++ ) { 40 | ServerParser parser = 41 | new ServerParser(server[i]); 42 | Server s= (Server) parser.parse(); 43 | System.out.println("encoded = " + s.encode()); 44 | } 45 | 46 | } 47 | */ 48 | -------------------------------------------------------------------------------- /sip/parser/StatusLineParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | "strings" 7 | ) 8 | 9 | /** SIPParser for the SIP status line. 10 | */ 11 | type StatusLineParser struct { 12 | SIPParser 13 | } 14 | 15 | func NewStatusLineParser(statusLine string) *StatusLineParser { 16 | this := &StatusLineParser{} 17 | this.CoreParser.Super(statusLine) 18 | this.SetLexer(NewSIPLexer("status_lineLexer", statusLine)) 19 | return this 20 | } 21 | 22 | func NewStatusLineParserFromLexer(lexer core.Lexer) *StatusLineParser { 23 | this := &StatusLineParser{} 24 | this.SetLexer(lexer) 25 | this.GetLexer().SelectLexer("status_lineLexer") 26 | return this 27 | } 28 | 29 | func (this *StatusLineParser) StatusCode() (scode int, ParseException error) { 30 | scode, ParseException = this.GetLexer().Number() 31 | return scode, ParseException 32 | } 33 | 34 | func (this *StatusLineParser) ReasonPhrase() string { 35 | return strings.TrimSpace(this.GetLexer().GetRest()) 36 | } 37 | 38 | func (this *StatusLineParser) Parse() (sl *header.StatusLine, ParseException error) { 39 | retval := header.NewStatusLine() 40 | lexer := this.GetLexer() 41 | 42 | var version string 43 | if version, ParseException = this.SipVersion(); ParseException != nil { 44 | return nil, ParseException 45 | } 46 | retval.SetSipVersion(version) 47 | lexer.SPorHT() 48 | 49 | var scode int 50 | if scode, ParseException = this.StatusCode(); ParseException != nil { 51 | return nil, ParseException 52 | } 53 | retval.SetStatusCode(scode) 54 | lexer.SPorHT() 55 | rp := this.ReasonPhrase() 56 | retval.SetReasonPhrase(rp) 57 | lexer.SPorHT() 58 | return retval, nil 59 | } 60 | -------------------------------------------------------------------------------- /sip/parser/StatusLineParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | //"strings" 5 | "testing" 6 | ) 7 | 8 | func TestStatusLineParser(t *testing.T) { 9 | var tvi = []string{ 10 | "SIP/2.0 100\x20\n", 11 | "SIP/2.0 200 OK\n", 12 | //"BOO 200 OK\n", 13 | "SIP/2.0 500 OK bad things happened \n", 14 | } 15 | var tvo = []string{ 16 | "SIP/2.0 100\x20\r\n", 17 | "SIP/2.0 200 OK\r\n", 18 | //"BOO 200 OK\n", 19 | "SIP/2.0 500 OK bad things happened\r\n", 20 | } 21 | 22 | for i := 0; i < len(tvi); i++ { 23 | rlp := NewStatusLineParser(tvi[i]) 24 | testStatusLineParser(t, rlp, tvo[i]) 25 | } 26 | } 27 | 28 | func testStatusLineParser(t *testing.T, rlp *StatusLineParser, s string) { 29 | if rl, err := rlp.Parse(); err != nil { 30 | t.Log(err) 31 | t.Fail() 32 | } else { 33 | d := rl.String() 34 | 35 | if (d) != (s) { 36 | t.Log("origin = " + s) 37 | t.Log("failed = " + d) 38 | t.Fail() 39 | } /*else { 40 | t.Log("passed = " + d) 41 | }*/ 42 | } 43 | } 44 | 45 | /** 46 | public static void main(String[] args) throws ParseException { 47 | String[] statusLines = { 48 | "SIP/2.0 200 OK\n", 49 | "BOO 200 OK\n", 50 | "SIP/2.0 500 OK bad things happened \n" 51 | }; 52 | for (int i = 0 ; i < statusLines.length; i++) { 53 | try { 54 | StatusLineParser slp = new StatusLineParser(statusLines[i]); 55 | StatusLine sl = slp.parse(); 56 | System.out.println("encoded = " + sl.encode()); 57 | } catch (ParseException ex) { 58 | System.out.println("error message " + ex.getMessage()); 59 | } 60 | } 61 | } 62 | */ 63 | -------------------------------------------------------------------------------- /sip/parser/SubjectParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | "strings" 7 | ) 8 | 9 | /** SIPParser for Subject header. 10 | */ 11 | type SubjectParser struct { 12 | HeaderParser 13 | } 14 | 15 | /** Creates a new instance of SubjectParser 16 | * @param subject the header to parse 17 | */ 18 | func NewSubjectParser(subject string) *SubjectParser { 19 | this := &SubjectParser{} 20 | this.HeaderParser.super(subject) 21 | return this 22 | } 23 | 24 | /** Cosntructor 25 | * @param lexer the lexer to use to parse the header 26 | */ 27 | func NewSubjectParserFromLexer(lexer core.Lexer) *SubjectParser { 28 | this := &SubjectParser{} 29 | this.HeaderParser.superFromLexer(lexer) 30 | return this 31 | } 32 | 33 | /** parse the String message 34 | * @return SIPHeader (Subject object) 35 | * @throws SIPParseException if the message does not respect the spec. 36 | */ 37 | func (this *SubjectParser) Parse() (sh header.Header, ParseException error) { 38 | subject := header.NewSubject() 39 | 40 | lexer := this.GetLexer() 41 | this.HeaderName(TokenTypes_SUBJECT) 42 | 43 | lexer.SPorHT() 44 | 45 | s := lexer.GetRest() 46 | subject.SetSubject(strings.TrimSpace(s)) 47 | 48 | return subject, nil 49 | } 50 | -------------------------------------------------------------------------------- /sip/parser/SubjectParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestSubjectParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Subject: Where is the Moscone?\n", 10 | "Subject: Need more boxes\n", 11 | } 12 | var tvo = []string{ 13 | "Subject: Where is the Moscone?\n", 14 | "Subject: Need more boxes\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewSubjectParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String subject[] = { 26 | "Subject: Where is the Moscone?\n", 27 | "Subject: Need more boxes\n" 28 | }; 29 | 30 | for (int i = 0; i < subject.length; i++ ) { 31 | SubjectParser parser = 32 | new SubjectParser(subject[i]); 33 | Subject s= (Subject) parser.parse(); 34 | System.out.println("encoded = " +s.encode()); 35 | } 36 | 37 | } 38 | */ 39 | -------------------------------------------------------------------------------- /sip/parser/SubscriptionStateParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestSubscriptionStateParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Subscription-State: active \n", 10 | "Subscription-State: terminated;reason=rejected \n", 11 | "Subscription-State: pending;reason=probation;expires=36\n", 12 | "Subscription-State: pending;retry-after=10;expires=36\n", 13 | "Subscription-State: pending;generic=void\n", 14 | } 15 | var tvo = []string{ 16 | "Subscription-State: active \n", 17 | "Subscription-State: terminated;reason=rejected \n", 18 | "Subscription-State: pending;reason=probation;expires=36\n", 19 | "Subscription-State: pending;retry-after=10;expires=36\n", 20 | "Subscription-State: pending;generic=void\n", 21 | } 22 | 23 | for i := 0; i < len(tvi); i++ { 24 | shp := NewSubscriptionStateParser(tvi[i]) 25 | testHeaderParser(t, shp, tvo[i]) 26 | } 27 | } 28 | 29 | /** Test program 30 | public static void main(String args[]) throws ParseException { 31 | String subscriptionState[] = { 32 | "Subscription-State: active \n", 33 | "Subscription-State: terminated;reason=rejected \n", 34 | "Subscription-State: pending;reason=probation;expires=36\n", 35 | "Subscription-State: pending;retry-after=10;expires=36\n", 36 | "Subscription-State: pending;generic=void\n" 37 | }; 38 | 39 | for (int i = 0; i < subscriptionState.length; i++ ) { 40 | SubscriptionStateParser parser = 41 | new SubscriptionStateParser(subscriptionState[i]); 42 | SubscriptionState ss= (SubscriptionState) parser.parse(); 43 | System.out.println("encoded = " + ss.encode()); 44 | } 45 | 46 | } 47 | */ 48 | -------------------------------------------------------------------------------- /sip/parser/SupportedParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestSupportedParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Supported: 100rel \n", 10 | "Supported: foo1, foo2 ,foo3 , foo4 \n", 11 | } 12 | var tvo = []string{ 13 | "Supported: 100rel \n", 14 | "Supported: foo1,foo2,foo3,foo4 \n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewSupportedParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String supported[] = { 26 | "Supported: 100rel \n", 27 | "Supported: foo1, foo2 ,foo3 , foo4 \n" 28 | }; 29 | 30 | for (int i = 0; i < supported.length; i++ ) { 31 | SupportedParser parser = 32 | new SupportedParser(supported[i]); 33 | SupportedList s= (SupportedList) parser.parse(); 34 | System.out.println("encoded = " + s.encode()); 35 | } 36 | 37 | } 38 | */ 39 | -------------------------------------------------------------------------------- /sip/parser/TimeStampParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestTimeStampParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Timestamp: 54 \n", 10 | "Timestamp: 52.34 34.5 \n", 11 | } 12 | var tvo = []string{ 13 | "Timestamp: 54 \n", 14 | "Timestamp: 52.34 34.5 \n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewTimeStampParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** Test program 24 | public static void main(String args[]) throws ParseException { 25 | String timeStamp[] = { 26 | "Timestamp: 54 \n", 27 | "Timestamp: 52.34 34.5 \n" 28 | }; 29 | 30 | for (int i = 0; i < timeStamp.length; i++ ) { 31 | TimeStampParser parser = 32 | new TimeStampParser(timeStamp[i]); 33 | TimeStamp ts= (TimeStamp) parser.parse(); 34 | System.out.println("encoded = " + ts.encode()); 35 | } 36 | 37 | } 38 | */ 39 | -------------------------------------------------------------------------------- /sip/parser/ToParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/address" 6 | "gosips/sip/header" 7 | ) 8 | 9 | /* To Header parser.*/ 10 | type ToParser struct { 11 | AddressParametersParser 12 | } 13 | 14 | /** Creates new ToParser 15 | * @param String to set 16 | */ 17 | func NewToParser(to string) *ToParser { 18 | this := &ToParser{} 19 | this.AddressParametersParser.super(to) 20 | return this 21 | } 22 | 23 | func NewToParserFromLexer(lexer core.Lexer) *ToParser { 24 | this := &ToParser{} 25 | this.AddressParametersParser.superFromLexer(lexer) 26 | return this 27 | } 28 | 29 | func (this *ToParser) Parse() (sh header.Header, ParseException error) { 30 | to := header.NewTo() 31 | this.HeaderName(TokenTypes_TO) 32 | 33 | if ParseException = this.AddressParametersParser.Parse(to); ParseException != nil { 34 | return nil, ParseException 35 | } 36 | 37 | this.GetLexer().Match('\n') 38 | addr := to.GetAddress().(*address.AddressImpl) 39 | if addr.GetAddressType() == address.ADDRESS_SPEC { 40 | // the parameters are header parameters. 41 | if to.GetAddress().GetURI().IsSipURI() { 42 | sipUri, _ := to.GetAddress().GetURI().(*address.SipURIImpl) 43 | parms := sipUri.GetUriParms() 44 | if parms != nil && parms.Len() > 0 { 45 | to.SetParameters(parms) 46 | sipUri.RemoveUriParms() 47 | } 48 | } 49 | } 50 | return to, nil 51 | } 52 | -------------------------------------------------------------------------------- /sip/parser/ToParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestToParser(t *testing.T) { 8 | var tvi = []string{ 9 | "To: \"BEL:\\ NUL:\\ DEL:\\\" \n", 10 | "To: ;tag=5617\n", 11 | "To: T. A. Watson \n", 12 | "To: LittleGuy \n", 13 | "To: sip:mranga@120.6.55.9\n", 14 | "To: sip:mranga@129.6.55.9 ; tag=696928473514.129.6.55.9\n", 15 | } 16 | var tvo = []string{ 17 | "To: \"BEL:\\ NUL:\\ DEL:\\\" \n", 18 | "To: ;tag=5617\n", 19 | "To: \"T. A. Watson\" \n", 20 | "To: \"LittleGuy\" \n", 21 | "To: \n", 22 | "To: ;tag=696928473514.129.6.55.9\n", 23 | } 24 | 25 | for i := 0; i < len(tvi); i++ { 26 | shp := NewToParser(tvi[i]) 27 | testHeaderParser(t, shp, tvo[i]) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sip/parser/UnsupportedParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestUnsupportedParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Unsupported: foo \n", 10 | "Unsupported: foo1, foo2 ,foo3 , foo4\n", 11 | } 12 | var tvo = []string{ 13 | "Unsupported: foo \n", 14 | "Unsupported: foo1,foo2,foo3,foo4\n", 15 | } 16 | 17 | for i := 0; i < len(tvi); i++ { 18 | shp := NewUnsupportedParser(tvi[i]) 19 | testHeaderParser(t, shp, tvo[i]) 20 | } 21 | } 22 | 23 | /** 24 | public static void main(String args[]) throws ParseException { 25 | String unsupported[] = { 26 | "Unsupported: foo \n", 27 | "Unsupported: foo1, foo2 ,foo3 , foo4\n" 28 | }; 29 | 30 | for (int i = 0; i < unsupported.length; i++ ) { 31 | UnsupportedParser parser = 32 | new UnsupportedParser(unsupported[i]); 33 | UnsupportedList u= (UnsupportedList) parser.parse(); 34 | System.out.println("encoded = " + u.encode()); 35 | } 36 | 37 | } 38 | */ 39 | -------------------------------------------------------------------------------- /sip/parser/UserAgentParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestUserAgentParser(t *testing.T) { 8 | var tvi = []string{ 9 | "User-Agent: Softphone/Beta1.5 \n", 10 | "User-Agent: Nist/Beta1 (beta version) \n", 11 | "User-Agent: Nist UA (beta version)\n", 12 | "User-Agent: Nist1.0/Beta2 Ubi/vers.1.0 (very cool) \n", 13 | } 14 | var tvo = []string{ 15 | "User-Agent: Softphone/Beta1.5 \n", 16 | "User-Agent: Nist/Beta1 (beta version) \n", 17 | "User-Agent: Nist UA (beta version)\n", 18 | "User-Agent: Nist1.0/Beta2 Ubi/vers.1.0 (very cool) \n", 19 | } 20 | 21 | for i := 0; i < len(tvi); i++ { 22 | shp := NewUserAgentParser(tvi[i]) 23 | testHeaderParser(t, shp, tvo[i]) 24 | } 25 | } 26 | 27 | /* 28 | public static void main(String args[]) throws ParseException { 29 | String userAgent[] = { 30 | "User-Agent: Softphone/Beta1.5 \n", 31 | "User-Agent: Nist/Beta1 (beta version) \n", 32 | "User-Agent: Nist UA (beta version)\n", 33 | "User-Agent: Nist1.0/Beta2 Ubi/vers.1.0 (very cool) \n" 34 | }; 35 | 36 | for (int i = 0; i < userAgent.length; i++ ) { 37 | UserAgentParser parser = 38 | new UserAgentParser(userAgent[i]); 39 | UserAgent ua= (UserAgent) parser.parse(); 40 | System.out.println("encoded = " + ua.encode()); 41 | } 42 | 43 | }*/ 44 | -------------------------------------------------------------------------------- /sip/parser/WWWAuthenticateParser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "gosips/core" 5 | "gosips/sip/header" 6 | ) 7 | 8 | /** SIPParser for WWW authenitcate header. 9 | */ 10 | type WWWAuthenticateParser struct { 11 | ChallengeParser 12 | } 13 | 14 | /** Constructor 15 | * @param wwwAuthenticate - message to parse 16 | */ 17 | func NewWWWAuthenticateParser(wwwAuthenticate string) *WWWAuthenticateParser { 18 | this := &WWWAuthenticateParser{} 19 | this.ChallengeParser.super(wwwAuthenticate) 20 | return this 21 | } 22 | 23 | /** Cosntructor 24 | * @param lexer - lexer to use. 25 | */ 26 | func NewWWWAuthenticateParserFromLexer(lexer core.Lexer) *WWWAuthenticateParser { 27 | this := &WWWAuthenticateParser{} 28 | this.ChallengeParser.superFromLexer(lexer) 29 | return this 30 | } 31 | 32 | /** parse the String message 33 | * @return SIPHeader (WWWAuthenticate object) 34 | * @throws SIPParseException if the message does not respect the spec. 35 | */ 36 | func (this *WWWAuthenticateParser) Parse() (sh header.Header, ParseException error) { 37 | this.HeaderName(TokenTypes_WWW_AUTHENTICATE) 38 | wwwAuthenticate := header.NewWWWAuthenticate() 39 | ParseException = this.ChallengeParser.Parse(wwwAuthenticate) 40 | return wwwAuthenticate, ParseException 41 | } 42 | -------------------------------------------------------------------------------- /sip/parser/WWWAuthenticateParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestWWWAuthenticateParser(t *testing.T) { 8 | var tvi = []string{ 9 | "WWW-Authenticate: Digest realm=\"MCI WorldCom SIP\"," + 10 | "domain=\"sip:ss2.wcom.com\",nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\"," + 11 | "opaque=\"\",stale=FALSE,algorithm=\"MD5\"\n", 12 | } 13 | var tvo = []string{ 14 | "WWW-Authenticate: Digest realm=\"MCI WorldCom SIP\"," + 15 | "domain=\"sip:ss2.wcom.com\",nonce=\"ea9c8e88df84f1cec4341ae6cbe5a359\"," + 16 | "opaque=\"\",stale=FALSE,algorithm=\"MD5\"\n", 17 | } 18 | 19 | for i := 0; i < len(tvi); i++ { 20 | shp := NewWWWAuthenticateParser(tvi[i]) 21 | testHeaderParser(t, shp, tvo[i]) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sip/parser/WarningParser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestWarningParser(t *testing.T) { 8 | var tvi = []string{ 9 | "Warning: 307 isi.edu \"Session parameter 'foo' not understood\"\n", 10 | "Warning: 301 isi.edu \"Incompatible network address type 'E.164'\"\n", 11 | "Warning: 312 ii.edu \"Soda\", " + 12 | " 351 i.edu \"I network address 'E.164'\" , 323 ii.edu \"Sodwea\"\n", 13 | } 14 | var tvo = []string{ 15 | "Warning: 307 isi.edu \"Session parameter 'foo' not understood\"\n", 16 | "Warning: 301 isi.edu \"Incompatible network address type 'E.164'\"\n", 17 | "Warning: 312 ii.edu \"Soda\"," + 18 | "351 i.edu \"I network address 'E.164'\",323 ii.edu \"Sodwea\"\n", 19 | } 20 | 21 | for i := 0; i < len(tvi); i++ { 22 | shp := NewWarningParser(tvi[i]) 23 | testHeaderParser(t, shp, tvo[i]) 24 | } 25 | } 26 | 27 | /** 28 | public static void main(String args[]) throws ParseException { 29 | String warning[] = { 30 | "Warning: 307 isi.edu \"Session parameter 'foo' not understood\"\n", 31 | "Warning: 301 isi.edu \"Incompatible network address type 'E.164'\"\n", 32 | "Warning: 312 ii.edu \"Soda\", "+ 33 | " 351 i.edu \"I network address 'E.164'\" , 323 ii.edu \"Sodwea\"\n" 34 | }; 35 | 36 | for (int i = 0; i < warning.length; i++ ) { 37 | WarningParser parser = 38 | new WarningParser(warning[i]); 39 | WarningList warningList= (WarningList) parser.parse(); 40 | System.out.println("encoded = " + warningList.encode()); 41 | } 42 | 43 | } 44 | */ 45 | --------------------------------------------------------------------------------