1 /* Copyright (c) 2011 Timothy Wall, All Rights Reserved
2  *
3  * The contents of this file is dual-licensed under 2
4  * alternative Open Source/Free licenses: LGPL 2.1 or later and
5  * Apache License 2.0. (starting with JNA version 4.0.0).
6  *
7  * You can freely decide which license you want to apply to
8  * the project.
9  *
10  * You may obtain a copy of the LGPL License at:
11  *
12  * http://www.gnu.org/licenses/licenses.html
13  *
14  * A copy is also included in the downloadable source code package
15  * containing JNA, in file "LGPL2.1".
16  *
17  * You may obtain a copy of the Apache License at:
18  *
19  * http://www.apache.org/licenses/
20  *
21  * A copy is also included in the downloadable source code package
22  * containing JNA, in file "AL2.0".
23  */
24 package com.sun.jna.platform.win32;
25 
26 import com.sun.jna.Native;
27 import com.sun.jna.Pointer;
28 import com.sun.jna.platform.win32.WinDef.BOOLByReference;
29 import com.sun.jna.platform.win32.WinNT.HANDLE;
30 import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
31 import com.sun.jna.platform.win32.WinRas.RASCONN;
32 import com.sun.jna.platform.win32.WinRas.RASCONNSTATUS;
33 import com.sun.jna.platform.win32.WinRas.RASCREDENTIALS;
34 import com.sun.jna.platform.win32.WinRas.RASDIALEXTENSIONS;
35 import com.sun.jna.platform.win32.WinRas.RASDIALPARAMS;
36 import com.sun.jna.platform.win32.WinRas.RASENTRY;
37 import com.sun.jna.platform.win32.WinRas.RAS_STATS;
38 import com.sun.jna.platform.win32.WinRas.RasDialFunc2;
39 import com.sun.jna.ptr.IntByReference;
40 import com.sun.jna.win32.StdCallLibrary;
41 import com.sun.jna.win32.W32APIOptions;
42 
43 /**
44  * Rasapi32.dll Interface.
45  */
46 public interface Rasapi32 extends StdCallLibrary {
47     Rasapi32 INSTANCE = Native.load("Rasapi32", Rasapi32.class, W32APIOptions.DEFAULT_OPTIONS);
48 
49     /**
50      * The RasDial function establishes a RAS connection between a RAS client and a RAS server.
51      * The connection data includes callback and user-authentication information.
52      *
53      * @param lpRasDialExtensions
54      *            Pointer to a RASDIALEXTENSIONS structure that specifies a set of RasDial extended features to enable.
55      *            Set this parameter to NULL if there is not a need to enable these features.
56      * @param lpszPhonebook
57      *            Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file.
58      *            If this parameter is NULL, the function uses the current default phone-book file.
59      *            The default phone-book file is the one selected by the user in the User Preferences property sheet of the
60      *            Dial-Up Networking dialog box.
61      * @param lpRasDialParams
62      *            Pointer to a RASDIALPARAMS structure that specifies calling parameters for the RAS connection.
63      *            Use the RasGetEntryDialParams function to retrieve a copy of this structure for a particular phone-book entry.
64      * @param dwNotifierType
65      *            Specifies the nature of the lpvNotifier parameter. If lpvNotifier is NULL, dwNotifierType is ignored.
66      *            If lpvNotifier is not NULL, set dwNotifierType to one of the following values.
67      * @param lpvNotifier
68      *            Specifies a window handle or a RasDialFunc, RasDialFunc1, or RasDialFunc2 callback function to receive
69      *            RasDial event notifications.
70      *            The dwNotifierType parameter specifies the nature of lpvNotifier. Please refer to its description preceding for further detail.
71      * @param lphRasConn
72      *            Pointer to a variable of type HRASCONN. Set the HRASCONN variable to NULL before calling RasDial.
73      *            If RasDial succeeds, it stores a handle to the RAS connection into *lphRasConn.
74      * @return If the function succeeds, the return value is ERROR_SUCCESS.
75      */
RasDial(RASDIALEXTENSIONS.ByReference lpRasDialExtensions, String lpszPhonebook, RASDIALPARAMS.ByReference lpRasDialParams, int dwNotifierType, RasDialFunc2 lpvNotifier, HANDLEByReference lphRasConn)76     int RasDial(RASDIALEXTENSIONS.ByReference lpRasDialExtensions, String lpszPhonebook, RASDIALPARAMS.ByReference lpRasDialParams, int dwNotifierType, RasDialFunc2 lpvNotifier, HANDLEByReference lphRasConn);
77 
78     /**
79      * The RasEnumConnections function lists all active RAS connections. It returns each connection's handle and phone-book entry name.
80      *
81      * @param lprasconn
82      *            Pointer to a buffer that receives, on output, an array of RASCONN structures, one for each RAS connection.
83      *            On input, an application must set the dwSize member of the first RASCONN structure in the buffer to sizeof(RASCONN)
84      *            in order to identify the version of the structure being passed.
85      * @param lpcb
86      *            Pointer to a variable that, on input, contains the size, in bytes, of the buffer specified by lprasconn.
87      *            On output, the function sets this variable to the number of bytes required to enumerate the RAS connections.
88      * @param lpcConnections
89      *            Pointer to a variable that receives the number of RASCONN structures written to the buffer specified by lprasconn.
90      * @return If the function succeeds, the return value is ERROR_SUCCESS.
91      */
RasEnumConnections(RASCONN[] lprasconn, IntByReference lpcb, IntByReference lpcConnections)92     int RasEnumConnections(RASCONN[] lprasconn, IntByReference lpcb, IntByReference lpcConnections);
93 
94     /**
95      * The RasGetConnectionStatistics function retrieves accumulated connection statistics for the specified connection.
96      *
97      * @param hrasconn
98      *            Handle to the connection. Use RasDial or RasEnumConnections to obtain this handle.
99      * @param lpStatistics
100      *            Pointer to the RASCONNSTATUS structure that, on output, receives the status information.
101      *            On input, set the dwSize member of the structure to sizeof(RASCONNSTATUS) in order to identify the version of the structure being passed.
102      * @return If the function succeeds, the return value is ERROR_SUCCESS.
103      */
RasGetConnectionStatistics(HANDLE hrasconn, RAS_STATS.ByReference lpStatistics)104     int RasGetConnectionStatistics(HANDLE hrasconn, RAS_STATS.ByReference lpStatistics);
105 
106     /**
107      * The RasGetConnectionStatistics function retrieves accumulated connection statistics for the specified connection.
108      *
109      * @param hrasconn
110      *            Specifies the remote access connection for which to retrieve the status. This handle must have been obtained from RasDial
111      *            or RasEnumConnections.
112      * @param lprasconnstatus
113      *            Pointer to the RASCONNSTATUS structure that, on output, receives the status information.
114      *            On input, set the dwSize member of the structure to sizeof(RASCONNSTATUS) in order to identify the version of the structure being passed.
115      * @return If the function succeeds, the return value is ERROR_SUCCESS.
116      */
RasGetConnectStatus(HANDLE hrasconn, RASCONNSTATUS.ByReference lprasconnstatus)117     int RasGetConnectStatus(HANDLE hrasconn, RASCONNSTATUS.ByReference lprasconnstatus);
118 
119     /**
120      * The RasGetCredentials function retrieves the user credentials associated with a specified RAS phone-book entry.
121      *
122      * @param lpszPhonebook
123      *            Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file.
124      *            If this parameter is NULL, the function uses the current default phone-book file. The default phone-book file is the
125      *            one selected by the user in the User Preferences property sheet of the Dial-Up Networking dialog box.
126      * @param lpszEntry
127      *            Pointer to a null-terminated string that specifies the name of a phone-book entry.
128      * @param lpCredentials
129      *            Pointer to the RASCREDENTIALS structure that, on output, receives the user credentials associated with the specified
130      *            phone-book entry.
131      *            On input, set the dwSize member of the structure to sizeof(RASCREDENTIALS), and set the dwMask member to indicate the
132      *            credential information to retrieve. When the function returns, dwMask indicates the members that were successfully retrieved.
133      * @return If the function succeeds, the return value is ERROR_SUCCESS.
134      */
RasGetCredentials(String lpszPhonebook, String lpszEntry, RASCREDENTIALS.ByReference lpCredentials)135     int RasGetCredentials(String lpszPhonebook, String lpszEntry, RASCREDENTIALS.ByReference lpCredentials);
136 
137     /**
138      * The RasGetEntryProperties function retrieves the properties of a phone-book entry.
139      *
140      * @param lpszPhonebook
141      *            Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file.
142      *            If this parameter is NULL, the function uses the current default phone-book file.
143      *            The default phone-book file is the one selected by the user in the User Preferences property sheet of the
144      *            Dial-Up Networking dialog box.
145      * @param lpszEntry
146      *            Pointer to a null-terminated string that specifies an existing entry name.
147      *            If an empty string is specified, the function returns default values in the buffers pointed to by the
148      *            lpRasEntry and lpbDeviceInfo parameters.
149      * @param lpRasEntry
150      *            Pointer to a RASENTRY structure followed by additional bytes for the alternate phone number list, if there is one.
151      * @param lpdwEntryInfoSize
152      *            Pointer to a variable that, on input, specifies the size, in bytes, of the lpRasEntry buffer.
153      * @param lpbDeviceInfo
154      *            This parameter is no longer used. The calling function should set this parameter to NULL.
155      * @param lpdwDeviceInfoSize
156      *            This parameter is unused. The calling function should set this parameter to NULL.
157      * @return If the function succeeds, the return value is ERROR_SUCCESS.
158      */
RasGetEntryProperties(String lpszPhonebook, String lpszEntry, RASENTRY.ByReference lpRasEntry, IntByReference lpdwEntryInfoSize, Pointer lpbDeviceInfo, Pointer lpdwDeviceInfoSize)159     int RasGetEntryProperties(String lpszPhonebook, String lpszEntry, RASENTRY.ByReference lpRasEntry, IntByReference lpdwEntryInfoSize, Pointer lpbDeviceInfo, Pointer lpdwDeviceInfoSize);
160 
161     /**
162      * The RasGetProjectionInfo function obtains information about a remote access projection operation for a specified remote access
163      * component protocol.
164      *
165      * @param hrasconn
166      *            Handle to the remote access connection of interest. An application obtains a RAS connection handle from the RasDial
167      *            or RasEnumConnections function.
168      * @param rasprojection
169      *            Specifies the RASPROJECTION enumerated type value that identifies the protocol of interest.
170      * @param lpprojection
171      *            Pointer to a buffer that receives the information specified by the rasprojection parameter. The information is in a
172      *            structure appropriate to the rasprojection value.
173      * @param lpcb
174      *            Pointer to a variable that, on input, specifies the size, in bytes, of the buffer pointed to by lpprojection.
175      *            On output, this variable receives the size, in bytes, of the lpprojection buffer.
176      * @return If the function succeeds, the return value is ERROR_SUCCESS.
177      */
RasGetProjectionInfo(HANDLE hrasconn, int rasprojection, Pointer lpprojection, IntByReference lpcb)178     int RasGetProjectionInfo(HANDLE hrasconn, int rasprojection, Pointer lpprojection, IntByReference lpcb);
179 
180     /**
181      * The RasHangUp function terminates a remote access connection. The connection is specified with a RAS connection handle.
182      * The function releases all RASAPI32.DLL resources associated with the handle.
183      *
184      * @param hrasconn
185      *            Specifies the remote access connection to terminate. This is a handle returned from a previous call to RasDial or RasEnumConnections.
186      * @return If the function succeeds, the return value is ERROR_SUCCESS.
187      */
RasHangUp(HANDLE hrasconn)188     int RasHangUp(HANDLE hrasconn);
189 
190     /**
191      * The RasSetEntryProperties function changes the connection information for an entry in the phone book or creates a new phone-book entry.
192      *
193      * @param lpszPhonebook
194      *            Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file.
195      *            If this parameter is NULL, the function uses the current default phone-book file.
196      *            The default phone-book file is the one selected by the user in the User Preferences property sheet of the Dial-Up
197      *            Networking dialog box.
198      * @param lpszEntry
199      *            Pointer to a null-terminated string that specifies an entry name.
200      * @param lpRasEntry
201      *            Pointer to the RASENTRY structure that specifies the new connection data to be associated with the
202      *            phone-book entry indicated by the lpszEntry parameter.
203      * @param dwEntryInfoSize
204      *            Specifies the size, in bytes, of the buffer identified by the lpRasEntry parameter.
205      * @param lpbDeviceInfo
206      *            Pointer to a buffer that specifies device-specific configuration information.
207      *            This is opaque TAPI device configuration information. For more information about TAPI device configuration,
208      *            see the lineGetDevConfig function in Telephony Application Programming Interfaces (TAPI) in the Platform SDK.
209      * @param dwDeviceInfoSize
210      *            Specifies the size, in bytes, of the lpbDeviceInfo buffer.
211      * @return If the function succeeds, the return value is ERROR_SUCCESS.
212      */
RasSetEntryProperties(String lpszPhonebook, String lpszEntry, RASENTRY.ByReference lpRasEntry, int dwEntryInfoSize, byte[] lpbDeviceInfo, int dwDeviceInfoSize)213     int RasSetEntryProperties(String lpszPhonebook, String lpszEntry, RASENTRY.ByReference lpRasEntry, int dwEntryInfoSize, byte[] lpbDeviceInfo, int dwDeviceInfoSize);
214 
215     /**
216      * The RasGetEntryDialParams function retrieves the connection information saved by the last successful call to the RasDial or
217      * RasSetEntryDialParams function for a specified phone-book entry.
218      *
219      * @param lpszPhonebook
220      *           Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file.
221      *           If this parameter is NULL, the function uses the current default phone-book file.
222      *           The default phone-book file is the one selected by the user in the User Preferences property sheet of the
223      *           Dial-Up Networking dialog box.
224      * @param lprasdialparams
225      *            Pointer to a RASDIALPARAMS structure.
226      * @param lpfPassword
227      *            Pointer to a flag that indicates whether the function retrieved the password associated with the user
228      *            name for the phone-book entry. The lpfPassword parameter is TRUE if the system has saved a password for
229      *            the specified entry. If the system has no password saved for this entry, lpfPassword is FALSE.
230      * @return If the function succeeds, the return value is ERROR_SUCCESS.
231      */
RasGetEntryDialParams(String lpszPhonebook, RASDIALPARAMS.ByReference lprasdialparams, BOOLByReference lpfPassword)232     int RasGetEntryDialParams(String lpszPhonebook, RASDIALPARAMS.ByReference lprasdialparams, BOOLByReference lpfPassword);
233 
234     /**
235      * The RasGetErrorString function obtains an error message string for a specified RAS error value.
236      *
237      * @param uErrorValue
238      *           Specifies the error value of interest. These are values returned by one of the RAS functions:
239      *           those listed in the RasError.h header file.
240      * @param lpszErrorString
241      *            Pointer to a buffer that receives the error string. This parameter must not be NULL.
242      * @param cBufSize
243      *            Specifies the size, in characters, of the buffer pointed to by lpszErrorString.
244          * @return status
245      */
RasGetErrorString(int uErrorValue, char[] lpszErrorString, int cBufSize)246     int RasGetErrorString(int uErrorValue, char[] lpszErrorString, int cBufSize);
247 }
248