93 // |
93 // |
94 TInt CSvtUriParser::DisplayNameFromUri( |
94 TInt CSvtUriParser::DisplayNameFromUri( |
95 const TDesC& aData, |
95 const TDesC& aData, |
96 RBuf& aDisplayname ) const |
96 RBuf& aDisplayname ) const |
97 { |
97 { |
98 TInt ret( KErrNotFound ); |
98 TInt result = KErrNotFound; |
99 |
99 |
100 TPtrC resultStr( aData ); |
100 TRAPD( err, DisplayNameFromUriL( aData, aDisplayname, result ) ); |
|
101 if ( err ) |
|
102 { |
|
103 result = err; |
|
104 } |
|
105 return result; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // The inner logic for resolving display name from sip uri |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CSvtUriParser::DisplayNameFromUriL( |
|
113 const TDesC& aData, |
|
114 RBuf& aDisplayname, |
|
115 TInt& aResult ) const |
|
116 { |
|
117 aResult = KErrNotFound; |
|
118 |
|
119 TPtrC preResultStr( aData ); |
101 aDisplayname.Close(); |
120 aDisplayname.Close(); |
102 |
121 |
103 // resolves potential SIP Display info and removes it from uri |
122 HBufC* tempBuffer = preResultStr.AllocLC(); // CS:1 |
104 // also possible "<" and ">" character are removed around the SIP uri |
123 tempBuffer->Des().TrimAll(); |
105 TInt uriStartIndex = resultStr.LocateReverse( KStartBracket ); |
124 |
106 TInt uriEndIndex = resultStr.LocateReverse( KEndBracket ); |
125 if ( tempBuffer->Length() ) |
107 |
126 { |
108 if ( uriStartIndex > uriEndIndex ) |
127 TPtrC resultStr( tempBuffer->Des() ); |
109 { |
128 |
110 // Start and end separators in wrong order: "xxxx>xxxx<xxx" |
129 // resolves potential SIP Display info and removes it from uri |
111 return KErrArgument; |
130 // also possible "<" and ">" character are removed around the SIP uri |
112 } |
131 TInt uriStartIndex = resultStr.LocateReverse( KStartBracket ); |
113 |
132 TInt uriEndIndex = resultStr.LocateReverse( KEndBracket ); |
114 if ( KErrNotFound != uriStartIndex && KErrNotFound != uriEndIndex ) |
133 |
115 { |
134 if ( KErrNotFound != uriStartIndex && KErrNotFound != uriEndIndex ) |
116 // brackets found so modify descriptor and save the display info |
135 { |
117 |
136 if ( uriStartIndex < uriEndIndex ) |
118 // check if there is anything before "<" if there is use |
|
119 // it as displayname if match op fails. |
|
120 if ( uriStartIndex > 1 ) |
|
121 { |
|
122 TPtrC tempStr( resultStr.Left( uriStartIndex ) ); |
|
123 // remove possible quotation marks from displayname |
|
124 TInt index = tempStr.Locate( KQuotationMark ); |
|
125 if ( KErrNotFound != index ) |
|
126 { |
137 { |
127 // marks have to be removed |
138 // brackets found so modify descriptor and save the display info |
128 tempStr.Set( tempStr.Mid( ++index ) ); |
139 |
129 if ( tempStr[tempStr.Length() - 1] == KQuotationMark ) |
140 // check if there is anything before "<" if there is use |
|
141 // it as displayname if match op fails. |
|
142 if ( uriStartIndex > 1 ) |
|
143 { |
|
144 TPtrC tempStr( resultStr.Left( uriStartIndex ) ); |
|
145 // remove possible quotation marks from displayname |
|
146 TInt index = tempStr.Locate( KQuotationMark ); |
|
147 if ( KErrNotFound != index ) |
|
148 { |
|
149 // marks have to be removed |
|
150 tempStr.Set( tempStr.Mid( ++index ) ); |
|
151 if ( tempStr[tempStr.Length() - 1] == KQuotationMark ) |
|
152 { |
|
153 tempStr.Set( tempStr.Left( tempStr.Length() - 1 ) ); |
|
154 } |
|
155 } |
|
156 aResult = aDisplayname.Create( tempStr ); |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 // Start and end separators in wrong order: "xxxx>xxxx<xxx" |
|
162 aResult = KErrArgument; |
|
163 } |
|
164 } |
|
165 else |
|
166 { |
|
167 // it is also possible that displayname is included |
|
168 // in, in case that there is no brackets around the uri. So if there is something |
|
169 // inside quotationMarks it should be used as displayname |
|
170 |
|
171 // check if displayname is found |
|
172 TInt displayNameStart = resultStr.Locate( KQuotationMark ); |
|
173 TInt displayNameEnd = resultStr.LocateReverse( KQuotationMark ); |
|
174 |
|
175 if ( displayNameStart != KErrNotFound |
|
176 && displayNameEnd != KErrNotFound |
|
177 && displayNameStart < displayNameEnd ) |
|
178 { |
|
179 // displayname is included |
|
180 // ++, to remove quotationMark from the start |
|
181 aResult = aDisplayname.Create( resultStr.Mid( ++displayNameStart, |
|
182 // -1, to remove quotationMark from the end |
|
183 displayNameEnd - displayNameStart - 1 ) ); |
|
184 } |
|
185 else |
|
186 { |
|
187 // check if there is spaces in the uri, if there is |
|
188 // everything before it belongs to display name |
|
189 TInt index = resultStr.LocateReverse( KSpaceMark ); |
|
190 |
|
191 if ( KErrNotFound != index ) |
130 { |
192 { |
131 tempStr.Set( tempStr.Left( tempStr.Length() - 1 ) ); |
193 // set displayname |
132 } |
194 aResult = aDisplayname.Create( resultStr.Left( index ) ); |
|
195 } |
133 } |
196 } |
134 ret = aDisplayname.Create( tempStr ); |
197 } |
135 } |
198 } |
136 } |
199 else |
137 else |
200 { |
138 { |
201 // Invalid data length |
139 // it is also possible that displayname is included |
202 aResult = KErrArgument; |
140 // in, in case that there is no brackets around the uri. So if there is something |
203 } |
141 // inside quotationMarks it should be used as displayname |
204 |
142 |
205 CleanupStack::PopAndDestroy( tempBuffer ); // CS:0 |
143 // check if displayname is found |
|
144 TInt displayNameStart = resultStr.Locate( KQuotationMark ); |
|
145 TInt displayNameEnd = resultStr.LocateReverse( KQuotationMark ); |
|
146 |
|
147 if ( displayNameStart != KErrNotFound |
|
148 && displayNameEnd != KErrNotFound |
|
149 && displayNameStart < displayNameEnd ) |
|
150 { |
|
151 // displayname is included |
|
152 // ++, to remove quotationMark from the start |
|
153 ret = aDisplayname.Create( resultStr.Mid( ++displayNameStart, |
|
154 // -1, to remove quotationMark from the end |
|
155 displayNameEnd - displayNameStart - 1 ) ); |
|
156 } |
|
157 else |
|
158 { |
|
159 // check if there is spaces in the uri, if there is |
|
160 // everything before it belongs to display name |
|
161 TInt index = resultStr.LocateReverse( KSpaceMark ); |
|
162 |
|
163 if ( KErrNotFound != index ) |
|
164 { |
|
165 // set displayname |
|
166 ret = aDisplayname.Create( resultStr.Left( index ) ); |
|
167 } |
|
168 |
|
169 } |
|
170 } |
|
171 |
|
172 return ret; |
|
173 } |
206 } |
174 |
207 |
175 // --------------------------------------------------------------------------- |
208 // --------------------------------------------------------------------------- |
176 // Check original address for spaces. |
209 // Check original address for spaces. |
177 // --------------------------------------------------------------------------- |
210 // --------------------------------------------------------------------------- |