|
1 // wsp_protocol.cpp |
|
2 // |
|
3 // Copyright (c) 2002 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 |
|
14 #include <winsockprt.h> |
|
15 #include "wsp_protocol.h" |
|
16 #include "wsp_provider.h" |
|
17 #include "wsp_factory.h" |
|
18 #include "wsp_resolver.h" |
|
19 #include "wsp_panic.h" |
|
20 #include "wsp_def.h" |
|
21 #include "wsp_log.h" |
|
22 |
|
23 |
|
24 CWinSockProtocol::~CWinSockProtocol() |
|
25 { |
|
26 } |
|
27 |
|
28 CWinSockProtocol::CWinSockProtocol(TUint aSocketType, RWin32Factory& aWin32Factory) |
|
29 : iSocketType(aSocketType), iWin32Factory(aWin32Factory) |
|
30 { |
|
31 } |
|
32 |
|
33 CWinSockProtocol* CWinSockProtocol::NewL(TUint aSocketType, RWin32Factory& aWin32Factory) |
|
34 { |
|
35 CWinSockProtocol* self = new(ELeave) CWinSockProtocol(aSocketType, aWin32Factory); |
|
36 return self; |
|
37 } |
|
38 |
|
39 void CWinSockProtocol::ProtocolIdentity(TServerProtocolDesc* aDesc, TUint aSocketType, TUint aProtocol) |
|
40 { |
|
41 switch (aSocketType) |
|
42 { |
|
43 case KSockStream: |
|
44 { |
|
45 aDesc->iName = (aProtocol == KProtocolWinsockTcp) ? _S("winsocktcp") : _S("tcp"); |
|
46 aDesc->iAddrFamily = KAfInet; |
|
47 aDesc->iSockType = KSockStream; |
|
48 aDesc->iProtocol = aProtocol; |
|
49 aDesc->iVersion = TVersion(KWspMajorVersionNumber, KWspMinorVersionNumber, KWspBuildVersionNumber); |
|
50 aDesc->iByteOrder = EBigEndian; |
|
51 aDesc->iServiceInfo = KSIStreamBased | KSIInOrder | KSIReliable | KSIGracefulClose; |
|
52 aDesc->iNamingServices = KNSNameResolution; |
|
53 aDesc->iSecurity = KSocketNoSecurity; |
|
54 aDesc->iMessageSize = KSocketMessageSizeIsStream; |
|
55 aDesc->iServiceTypeInfo = ESocketSupport | EUseCanSend; |
|
56 aDesc->iNumSockets = KUnlimitedSockets; |
|
57 return; |
|
58 } |
|
59 case KSockDatagram: |
|
60 { |
|
61 if (aProtocol == KProtocolWinsockUdp) |
|
62 { |
|
63 aDesc->iName = _S("winsockudp"); |
|
64 } |
|
65 else if (aProtocol == KProtocolInetUdp) |
|
66 { |
|
67 aDesc->iName = _S("udp"); |
|
68 } |
|
69 else if (aProtocol == KProtocolInetIp) |
|
70 { |
|
71 aDesc->iName = _S("ip"); |
|
72 } |
|
73 aDesc->iAddrFamily = KAfInet; |
|
74 aDesc->iSockType = KSockDatagram; |
|
75 aDesc->iProtocol = aProtocol; |
|
76 aDesc->iVersion = TVersion(KWspMajorVersionNumber, KWspMinorVersionNumber, KWspBuildVersionNumber); |
|
77 aDesc->iByteOrder = EBigEndian; |
|
78 aDesc->iServiceInfo = KSIConnectionLess | KSIDatagram | KSIGracefulClose; |
|
79 aDesc->iNamingServices = KNSNameResolution; |
|
80 aDesc->iSecurity = KSocketNoSecurity; |
|
81 aDesc->iMessageSize = 65536-128; /*KSocketMessageSizeUndefined;*/ |
|
82 aDesc->iServiceTypeInfo = ESocketSupport | EUseCanSend; |
|
83 aDesc->iNumSockets = KUnlimitedSockets; |
|
84 return; |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 CServProviderBase* CWinSockProtocol::NewSAPL(TUint aProtocol) |
|
90 { |
|
91 WSP_LOG(WspLog::Write(_L("CWinSockProtocol::NewSAPL"))); |
|
92 |
|
93 CWinSockProviderBase* provider = NULL; |
|
94 |
|
95 switch (iSocketType) |
|
96 { |
|
97 case KSockStream: |
|
98 { |
|
99 provider = CWinSockTcpProvider::NewL(iWin32Factory); |
|
100 break; |
|
101 } |
|
102 case KSockDatagram: |
|
103 { |
|
104 provider = CWinSockUdpProvider::NewL(iWin32Factory); |
|
105 break; |
|
106 } |
|
107 default: |
|
108 { |
|
109 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtCWinSockProtocolNewSAPLInvalidProtocol)); |
|
110 } |
|
111 } |
|
112 |
|
113 iProtocol = aProtocol; |
|
114 |
|
115 return provider; |
|
116 } |
|
117 |
|
118 void CWinSockProtocol::Identify(TServerProtocolDesc* aDesc) const |
|
119 { |
|
120 CWinSockProtocol::ProtocolIdentity(aDesc, iSocketType, iProtocol); |
|
121 } |
|
122 |
|
123 void CWinSockProtocol::BindL(CProtocolBase* /*aProtocol*/, TUint /*anId*/) |
|
124 { |
|
125 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedBindRequestFromPeer)); |
|
126 } |
|
127 |
|
128 void CWinSockProtocol::BindToL(CProtocolBase* /*protocol*/) |
|
129 { |
|
130 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedBindToRequestFromSocketServer)); |
|
131 } |
|
132 |
|
133 TInt CWinSockProtocol::Send(RMBufChain &,CProtocolBase* /*aSourceProtocol*/) |
|
134 { |
|
135 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedSendDownCallFromBindee)); |
|
136 return 0; |
|
137 } |
|
138 |
|
139 void CWinSockProtocol::Process(RMBufChain &,CProtocolBase* /*aSourceProtocol*/) |
|
140 { |
|
141 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedProcessUpCallFromBindee)); |
|
142 } |
|
143 |
|
144 TInt CWinSockProtocol::Send(TDes8 &, TSockAddr* /*to*/,TSockAddr* /*from*/,CProtocolBase* /*aSourceProtocol*/) |
|
145 { |
|
146 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedSendDownCallFromBindee)); |
|
147 return KErrNone; |
|
148 } |
|
149 |
|
150 void CWinSockProtocol::Process(TDes8&,TSockAddr* /*from*/,TSockAddr* /*to*/,CProtocolBase* /*aSourceProtocol*/) |
|
151 { |
|
152 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedProcessUpCallFromBindee)); |
|
153 } |
|
154 |
|
155 |
|
156 TInt CWinSockProtocol::GetOption(TUint aLevel,TUint aName,TDes8& aOption,CProtocolBase*) |
|
157 { |
|
158 if ((aLevel == KNifOptLevel) && (aName == KNifOptGetNifIfUser)) |
|
159 { |
|
160 static_cast<TNifIfUser&>(aOption) = this; |
|
161 return KErrNone; |
|
162 } |
|
163 return KErrNotSupported; |
|
164 } |
|
165 |
|
166 TInt CWinSockProtocol::SetOption(TUint /*level*/,TUint /*name*/,const TDesC8& /*option*/,CProtocolBase* /*aSourceProtocol*/) |
|
167 { |
|
168 return KErrNotSupported; |
|
169 } |
|
170 |
|
171 void CWinSockProtocol::Error(TInt /*anError*/,CProtocolBase* /*aSourceProtocol*/) |
|
172 { |
|
173 __ASSERT_DEBUG(EFalse, Panic(EWinSockPrtUnexpectedErrorUpCallFromBindee)); |
|
174 } |
|
175 |
|
176 CHostResolvProvdBase* CWinSockProtocol::NewHostResolverL() |
|
177 { |
|
178 WSP_LOG(WspLog::Write(_L("CWinSockProtocol::NewHostResolverL"))); |
|
179 return CWinSockResolver::NewL(iWin32Factory); |
|
180 } |
|
181 |
|
182 CServiceResolvProvdBase* CWinSockProtocol::NewServiceResolverL() |
|
183 { |
|
184 return NULL; |
|
185 } |
|
186 |
|
187 CNetDBProvdBase* CWinSockProtocol::NewNetDatabaseL() |
|
188 { |
|
189 return NULL; |
|
190 } |
|
191 |
|
192 void CWinSockProtocol::IfUserBindFailure(TInt, TAny*) |
|
193 { |
|
194 } |
|
195 |
|
196 void CWinSockProtocol::IfUserNewInterfaceL(CNifIfBase*, TAny*) |
|
197 { |
|
198 } |
|
199 |
|
200 void CWinSockProtocol::IfUserInterfaceDown(TInt, CNifIfBase*) |
|
201 { |
|
202 } |
|
203 |
|
204 void CWinSockProtocol::IfUserOpenNetworkLayer() |
|
205 { |
|
206 Open(); |
|
207 } |
|
208 |
|
209 void CWinSockProtocol::IfUserCloseNetworkLayer() |
|
210 { |
|
211 Close(); |
|
212 } |
|
213 |
|
214 CProtocolBase* CWinSockProtocol::IfUserProtocol() |
|
215 { |
|
216 return this; |
|
217 } |
|
218 |
|
219 TBool CWinSockProtocol::IfUserIsNetworkLayerActive() |
|
220 { |
|
221 } |
|
222 |