1 /******************************************************************************
2 *
3 * Copyright (C) 2009, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 ******************************************************************************/
13
14 define
15 {
16 RAS_MaxEntryName = 256
17 RAS_MaxDeviceName = 128
18 RAS_MaxDeviceType = 16
19 RAS_MaxPhoneNumber = 128
20 RAS_MaxCallbackNumber = $RAS_MaxPhoneNumber
21 MAX_PATH = 260
22 UNLEN = 256
23 PWLEN = 256
24 DNLEN = 18 //15
25 }
26
27 type RASCONN
28 {
29 uint dwSize
30 uint hrasconn
31 reserved szEntryName[ $RAS_MaxEntryName + 1 ]
32 reserved szDeviceType[ $RAS_MaxDeviceType + 1 ]
33 reserved szDeviceName[ $RAS_MaxDeviceName + 1 ]
34 reserved szPhonebook [ $MAX_PATH + 1 ]
35 uint dwSubEntry
36 reserved unknown[16]
37 }
38
39 type RASDIALDLG
40 {
41 uint dwSize
42 uint hwndOwner
43 uint dwFlags
44 uint xDlg
45 uint yDlg
46 uint dwSubEntry
47 uint dwError
48 uint reserved
49 uint reserved2
50 }
51
52 type RASDIALPARAMS
53 {
54 uint dwSize
55 reserved szEntryName[ $RAS_MaxEntryName + 1 ]
56 reserved szPhoneNumber[ $RAS_MaxPhoneNumber + 1 ]
57 reserved szCallbackNumber[ $RAS_MaxCallbackNumber + 1 ]
58 reserved szUserName[ $UNLEN + 1 ]
59 reserved szPassword[ $PWLEN + 1 ]
60 reserved szDomain[ $DNLEN + 1 ]
61 uint dwSubEntry
62 uint dwCallbackId
63 }
64
65 type RASENTRYNAME
66 {
67 uint dwSize
68 reserved szEntryName[ $RAS_MaxEntryName + 1 ]
69 uint dwFlags
70 reserved szPhonebookPath[ $MAX_PATH + 1 ]
71 reserved unknown[6]
72 }
73
74
75 import "rasapi32.dll"
76 {
77 uint RasDialA( uint, uint, RASDIALPARAMS, uint, uint, uint ) -> RasDial
78 uint RasEnumConnectionsA( uint, uint, uint ) -> RasEnumConnections
79 uint RasEnumEntriesA( uint, uint, uint, uint, uint ) -> RasEnumEntries
80 uint RasHangUpA( uint ) -> RasHangUp
81 }
82
83 func uint ras_enumconnect( buf rascon, uint pnum )
84 {
85 uint size pras
86 buf rascon
87
88 size = 20 * sizeof( RASCONN )
89 rascon.reserve( size )
90 pras = rascon.ptr()
91 pras->RASCONN.dwSize = sizeof( RASCONN )
92 return ?( !RasEnumConnections( pras, &size, pnum ), pras, 0 )
93 }
94
95 func uint ras_connections( arrstr entries )
96 {
97 uint ret num pras
98 buf rascon
99
100 entries.clear()
101 if pras = ras_enumconnect( rascon, &num )
102 {
103 while num--
104 {
105 str stemp
106
107 stemp.copy( &pras->RASCONN.szEntryName )
108 entries += stemp
109 pras += sizeof( RASCONN )
110 }
111 }
112 return ret
113 }
114
115 func uint ras_entries( arrstr entries )
116 {
117 uint size ret num pras
118 buf rascon
119
120 size = 20 * sizeof( RASENTRYNAME )
121 rascon.reserve( size )
122 entries.clear()
123 pras = rascon.ptr()
124 pras->RASENTRYNAME.dwSize = sizeof( RASENTRYNAME )
125 if !( ret = RasEnumEntries( 0, 0, pras, &size, &num ))
126 {
127 while num--
128 {
129 str stemp
130
131 stemp.copy( &pras->RASENTRYNAME.szEntryName )
132 entries += stemp
133 pras += sizeof( RASENTRYNAME )
134 }
135 }
136 return ret
137 }
138
139 func str ras_firstentry< result >( )
140 {
141 arrstr astr
142
143 ras_entries( astr )
144 if *astr : result = astr[0]
145 }
146
147 func uint ras_dialdlg( uint wnd, str entry )
148 {
149 RASDIALDLG rasdlg
150 uint lib proc ret
151
152 lib = LoadLibrary( "rasdlg.dll".ptr() )
153 if !lib : return 0
154 if !( proc = GetProcAddress( lib, "RasDialDlgA".ptr() )) : return 0
155
156 rasdlg.dwSize = sizeof( RASDIALDLG )
157 rasdlg.hwndOwner = wnd
158 if !*entry : entry = ras_firstentry()
159 ret = proc->stdcall( 0, entry.ptr(), 0, rasdlg )
160 return ret
161 }
162
163 func uint ras_dialup( str entry phone callback user psw domain )
164 {
165 uint hrascon
166 RASDIALPARAMS rdpar
167
168 rdpar.dwSize = sizeof( RASDIALPARAMS )
169 if !*entry : entry = ras_firstentry()
170 mcopy( &rdpar.szEntryName, entry.ptr(), *entry + 1 )
171 mcopy( &rdpar.szPhoneNumber, phone.ptr(), *phone + 1 )
172 mcopy( &rdpar.szCallbackNumber, callback.ptr(), *callback + 1 )
173 mcopy( &rdpar.szUserName, user.ptr(), *user + 1 )
174 mcopy( &rdpar.szPassword, psw.ptr(), *psw + 1 )
175 mcopy( &rdpar.szDomain, domain.ptr(), *domain + 1 )
176
177 return !RasDial( 0, 0, rdpar, 0, 0, &hrascon )
178 }
179
180 func uint ras_disconnect( str entry )
181 {
182 uint ret num pras
183 buf rascon
184
185 if pras = ras_enumconnect( rascon, &num )
186 {
187 while num--
188 {
189 str stemp
190
191 stemp.copy( &pras->RASCONN.szEntryName )
192 if !*entry || stemp %== entry || entry == "*"
193 {
194 ret = !RasHangUp( pras->RASCONN.hrasconn )
195 if entry != "*" : return ret
196 }
197 pras += sizeof( RASCONN )
198 }
199 }
200 return ret
201 }
202
203 func uint ras_isconnected( str entry )
204 {
205 uint num pras
206 buf rascon
207
208 if pras = ras_enumconnect( rascon, &num )
209 {
210 while num--
211 {
212 str stemp
213
214 stemp.copy( &pras->RASCONN.szEntryName )
215 if !*entry || stemp %== entry : return 1
216 pras += sizeof( RASCONN )
217 }
218 }
219 return 0
220 }
221