[TAPI32] Sync with Wine Staging 4.18. CORE-16441
[reactos.git] / dll / win32 / tapi32 / line.c
index 6ccdf13..17fecf3 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include "windef.h"
 #include "winbase.h"
+#include "wine/winternl.h"
 #include "wingdi.h"
 #include "winreg.h"
 #include "winnls.h"
@@ -133,6 +134,15 @@ DWORD WINAPI lineConfigDialogA(DWORD dwDeviceID, HWND hwndOwner, LPCSTR lpszDevi
     return 0;
 }
 
+/***********************************************************************
+ *             lineConfigDialogW (TAPI32.@)
+ */
+DWORD WINAPI lineConfigDialogW(DWORD dwDeviceID, HWND hwndOwner, LPCWSTR lpszDeviceClass)
+{
+    FIXME("(%08x, %p, %s): stub.\n", dwDeviceID, hwndOwner, debugstr_w(lpszDeviceClass));
+    return 0;
+}
+
 /***********************************************************************
  *             lineConfigDialogEdit (TAPI32.@)
  */
@@ -187,6 +197,15 @@ DWORD WINAPI lineDialA(HCALL hCall, LPCSTR lpszDestAddress, DWORD dwCountryCode)
     return 1;
 }
 
+/***********************************************************************
+ *             lineDialW (TAPI32.@)
+ */
+DWORD WINAPI lineDialW(HCALL hCall, LPCWSTR lpszDestAddress, DWORD dwCountryCode)
+{
+    FIXME("(%p, %s, %08x): stub.\n", hCall, debugstr_w(lpszDestAddress), dwCountryCode);
+    return 1;
+}
+
 /***********************************************************************
  *             lineDrop (TAPI32.@)
  */
@@ -295,18 +314,8 @@ DWORD WINAPI lineGetConfRelatedCalls(HCALL hCall, LPLINECALLLIST lpCallList)
     return 0;
 }
 
-typedef struct tagTAPI_CountryInfo
-{
-    DWORD  dwCountryID;
-    DWORD  dwCountryCode;
-    LPSTR  lpCountryName;
-    LPSTR  lpSameAreaRule;
-    LPSTR  lpLongDistanceRule;
-    LPSTR  lpInternationalRule;
-} TAPI_CountryInfo;
-
 /***********************************************************************
- *             lineGetCountry (TAPI32.@)
+ *             lineGetCountryA (TAPI32.@)
  */
 DWORD WINAPI lineGetCountryA(DWORD dwCountryID, DWORD dwAPIVersion, LPLINECOUNTRYLIST lpLineCountryList)
 {
@@ -465,13 +474,152 @@ DWORD WINAPI lineGetCountryA(DWORD dwCountryID, DWORD dwAPIVersion, LPLINECOUNTR
     return 0;
 }
 
+/***********************************************************************
+ *             lineGetCountryW (TAPI32.@)
+ */
+DWORD WINAPI lineGetCountryW(DWORD id, DWORD version, LPLINECOUNTRYLIST list)
+{
+    static const WCHAR country_listW[] =
+        {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
+         'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+         'T','e','l','e','p','h','o','n','y','\\','C','o','u','n','t','r','y',' ','L','i','s','t',0};
+    static const WCHAR international_ruleW[] =
+        {'I','n','t','e','r','n','a','t','i','o','n','a','l','R','u','l','e',0};
+    static const WCHAR longdistance_ruleW[] =
+        {'L','o','n','g','D','i','s','t','a','n','c','e','R','u','l','e',0};
+    static const WCHAR samearea_ruleW[] =
+        {'S','a','m','e','A','r','e','a','R','u','l','e',0};
+    static const WCHAR nameW[] =
+        {'N','a','m','e',0};
+    static const WCHAR country_codeW[] =
+        {'C','o','u','n','t','r','y','C','o','d','e',0};
+    DWORD total_size, offset, i, num_countries, max_subkey_len;
+    LINECOUNTRYENTRY *entry;
+    WCHAR *subkey_name;
+    HKEY hkey;
+
+    if (!list) return LINEERR_INVALPOINTER;
+    TRACE("(%08x, %08x, %p(%d))\n", id, version, list, list->dwTotalSize);
+
+    if (RegOpenKeyW(HKEY_LOCAL_MACHINE, country_listW, &hkey) != ERROR_SUCCESS)
+        return LINEERR_INIFILECORRUPT;
+
+    total_size = list->dwTotalSize;
+    offset = sizeof(LINECOUNTRYLIST);
+    if (total_size < offset) return LINEERR_STRUCTURETOOSMALL;
+
+    memset(list, 0, total_size);
+    list->dwTotalSize         = total_size;
+    list->dwUsedSize          = offset;
+    list->dwNumCountries      = 0;
+    list->dwCountryListSize   = 0;
+    list->dwCountryListOffset = offset;
+
+    entry = (LINECOUNTRYENTRY *)(list + 1);
+
+    if (RegQueryInfoKeyW(hkey, NULL, NULL, NULL, &num_countries, &max_subkey_len,
+                         NULL, NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
+    {
+        RegCloseKey(hkey);
+        return LINEERR_OPERATIONFAILED;
+    }
+    if (id) offset = sizeof(LINECOUNTRYENTRY);
+    else offset += num_countries * sizeof(LINECOUNTRYENTRY);
+
+    max_subkey_len++;
+    if (!(subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len * sizeof(WCHAR))))
+    {
+        RegCloseKey(hkey);
+        return LINEERR_NOMEM;
+    }
+    for (i = 0; i < num_countries; i++)
+    {
+        DWORD len, size, size_int, size_long, size_name, size_same;
+        HKEY hsubkey;
+
+        if (RegEnumKeyW(hkey, i, subkey_name, max_subkey_len) != ERROR_SUCCESS) continue;
+        if (id && (wcstol(subkey_name, NULL, 10) != id)) continue;
+        if (RegOpenKeyW(hkey, subkey_name, &hsubkey) != ERROR_SUCCESS) continue;
+
+        RegQueryValueExW(hsubkey, international_ruleW, NULL, NULL, NULL, &size_int);
+        len = size_int;
+
+        RegQueryValueExW(hsubkey, longdistance_ruleW, NULL, NULL, NULL, &size_long);
+        len += size_long;
+
+        RegQueryValueExW(hsubkey, nameW, NULL, NULL, NULL, &size_name);
+        len += size_name;
+
+        RegQueryValueExW(hsubkey, samearea_ruleW, NULL, NULL, NULL, &size_same);
+        len += size_same;
+
+        if (total_size < offset + len)
+        {
+            offset += len;
+            RegCloseKey(hsubkey);
+            if (id) break;
+            continue;
+        }
+        list->dwNumCountries++;
+        list->dwCountryListSize += sizeof(LINECOUNTRYENTRY);
+        list->dwUsedSize += len + sizeof(LINECOUNTRYENTRY);
+
+        if (id) i = 0;
+        entry[i].dwCountryID = wcstol(subkey_name, NULL, 10);
+        size = sizeof(DWORD);
+        RegQueryValueExW(hsubkey, country_codeW, NULL, NULL, (BYTE *)&entry[i].dwCountryCode, &size);
+        entry[i].dwNextCountryID = 0;
+
+        if (i > 0) entry[i - 1].dwNextCountryID = entry[i].dwCountryID;
+
+        /* add country name */
+        entry[i].dwCountryNameSize = size_name;
+        entry[i].dwCountryNameOffset = offset;
+        RegQueryValueExW(hsubkey, nameW, NULL, NULL, (BYTE *)list + offset, &size_name);
+        offset += size_name;
+
+        /* add Same Area Rule */
+        entry[i].dwSameAreaRuleSize = size_same;
+        entry[i].dwSameAreaRuleOffset = offset;
+        RegQueryValueExW(hsubkey, samearea_ruleW, NULL, NULL, (BYTE *)list + offset, &size_same);
+        offset += size_same;
+
+        /* add Long Distance Rule */
+        entry[i].dwLongDistanceRuleSize = size_long;
+        entry[i].dwLongDistanceRuleOffset = offset;
+        RegQueryValueExW(hsubkey, longdistance_ruleW, NULL, NULL, (BYTE *)list + offset, &size_long);
+        offset += size_long;
+
+        /* add Long Distance Rule */
+        entry[i].dwInternationalRuleSize = size_int;
+        entry[i].dwInternationalRuleOffset = offset;
+        RegQueryValueExW(hsubkey, international_ruleW, NULL, NULL, (BYTE *)list + offset, &size_int);
+        offset += size_int;
+        RegCloseKey(hsubkey);
+
+        TRACE("added country %s at %p\n",
+              debugstr_w((const WCHAR *)((const char *)list + entry[i].dwCountryNameOffset)), &entry[i]);
+        if (id) break;
+    }
+    list->dwNeededSize = offset;
+
+    TRACE("%d available %d required\n", total_size, offset);
+
+    HeapFree(GetProcessHeap(), 0, subkey_name);
+    RegCloseKey(hkey);
+    return 0;
+}
+
 /***********************************************************************
  *             lineGetDevCapsW (TAPI32.@)
  */
 DWORD WINAPI lineGetDevCapsW(HLINEAPP hLineApp, DWORD dwDeviceID, DWORD dwAPIVersion,
                              DWORD dwExtVersion, LPLINEDEVCAPS lpLineDevCaps)
 {
-    FIXME("(%p, %08x, %08x, %08x, %p): stub.\n", hLineApp, dwDeviceID, dwAPIVersion,
+    static int warn_once;
+
+    if(!warn_once++)
+        FIXME("(%p, %08x, %08x, %08x, %p): stub.\n", hLineApp, dwDeviceID, dwAPIVersion,
                                                  dwExtVersion, lpLineDevCaps);
     return LINEERR_OPERATIONFAILED;
 }
@@ -482,7 +630,10 @@ DWORD WINAPI lineGetDevCapsW(HLINEAPP hLineApp, DWORD dwDeviceID, DWORD dwAPIVer
 DWORD WINAPI lineGetDevCapsA(HLINEAPP hLineApp, DWORD dwDeviceID, DWORD dwAPIVersion,
                              DWORD dwExtVersion, LPLINEDEVCAPS lpLineDevCaps)
 {
-    FIXME("(%p, %08x, %08x, %08x, %p): stub.\n", hLineApp, dwDeviceID, dwAPIVersion,
+    static int warn_once;
+
+    if(!warn_once++)
+        FIXME("(%p, %08x, %08x, %08x, %p): stub.\n", hLineApp, dwDeviceID, dwAPIVersion,
                                                  dwExtVersion, lpLineDevCaps);
     return LINEERR_OPERATIONFAILED;
 }
@@ -537,6 +688,15 @@ DWORD WINAPI lineGetLineDevStatusA(HLINE hLine, LPLINEDEVSTATUS lpLineDevStatus)
     return 0;
 }
 
+/***********************************************************************
+ *              lineGetMessage (TAPI32.@)
+ */
+DWORD WINAPI lineGetMessage(HLINEAPP hLineApp, LPLINEMESSAGE lpMessage, DWORD dwTimeout)
+{
+    FIXME("(%p, %p, %08x): stub.\n", hLineApp, lpMessage, dwTimeout);
+    return 0;
+}
+
 /***********************************************************************
  *             lineGetNewCalls (TAPI32.@)
  */
@@ -685,7 +845,7 @@ DWORD WINAPI lineGetTranslateCapsA(HLINEAPP hLineApp, DWORD dwAPIVersion,
             == ERROR_SUCCESS){
         DWORD size_val;
         i++;
-        if( strncasecmp(loc_key_name, "location", 8)  ||
+        if( _strnicmp(loc_key_name, "location", 8)  ||
                 (RegOpenKeyA(hkLocations, loc_key_name, &hsubkey)
                  != ERROR_SUCCESS))
             continue;
@@ -747,7 +907,7 @@ DWORD WINAPI lineGetTranslateCapsA(HLINEAPP hLineApp, DWORD dwAPIVersion,
                     ERROR_SUCCESS){
                 DWORD size_val;
                 i++;
-                if( strncasecmp(card_key_name, "card", 4)  || ERROR_SUCCESS !=
+                if( _strnicmp(card_key_name, "card", 4)  || ERROR_SUCCESS !=
                         (RegOpenKeyA(hkCards, card_key_name, &hsubkey) ))
                     continue;
                 numcards++;
@@ -814,7 +974,7 @@ DWORD WINAPI lineGetTranslateCapsA(HLINEAPP hLineApp, DWORD dwAPIVersion,
     strptr = ((LPBYTE) lpTranslateCaps) +
         lpTranslateCaps->dwCardListOffset + lpTranslateCaps->dwCardListSize;
     pLocEntry = (LPLINELOCATIONENTRY) (lpTranslateCaps + 1);
-    /* key with Preferred CardID's */
+    /* key with Preferred CardIDs */
     if( RegOpenKeyA(HKEY_CURRENT_USER, szLocationsKey, &hkCardLocations)
             != ERROR_SUCCESS ) 
         hkCardLocations = 0;
@@ -824,7 +984,7 @@ DWORD WINAPI lineGetTranslateCapsA(HLINEAPP hLineApp, DWORD dwAPIVersion,
             == ERROR_SUCCESS){
         DWORD size_val;
         i++;
-        if( strncasecmp(loc_key_name, "location", 8)  ||
+        if( _strnicmp(loc_key_name, "location", 8)  ||
                 (RegOpenKeyA(hkLocations, loc_key_name, &hsubkey)
                  != ERROR_SUCCESS))
             continue;
@@ -917,7 +1077,7 @@ DWORD WINAPI lineGetTranslateCapsA(HLINEAPP hLineApp, DWORD dwAPIVersion,
                 ERROR_SUCCESS){
             DWORD size_val;
             i++;
-            if( strncasecmp(card_key_name, "card", 4)  ||
+            if( _strnicmp(card_key_name, "card", 4)  ||
                     (RegOpenKeyA(hkCards, card_key_name, &hsubkey) != ERROR_SUCCESS))
                 continue;
             size_val=sizeof(DWORD);
@@ -1018,6 +1178,16 @@ LONG WINAPI lineInitializeExA(LPHLINEAPP lphLineApp, HINSTANCE hInstance, LINECA
     return 0;
 }
 
+/***********************************************************************
+ *              lineInitializeExW (TAPI32.@)
+ */
+LONG WINAPI lineInitializeExW(LPHLINEAPP lphLineApp, HINSTANCE hInstance, LINECALLBACK lpfnCallback, LPCWSTR lpszFriendlyAppName, LPDWORD lpdwNumDevs, LPDWORD lpdwAPIVersion, LPLINEINITIALIZEEXPARAMS lpLineInitializeExParams)
+{
+    FIXME("(%p, %p, %p, %s, %p, %p, %p): stub.\n", lphLineApp, hInstance,
+          lpfnCallback, debugstr_w(lpszFriendlyAppName), lpdwNumDevs, lpdwAPIVersion, lpLineInitializeExParams);
+    return 0;
+}
+
 /***********************************************************************
  *             lineMakeCallW (TAPI32.@)
  */
@@ -1079,8 +1249,11 @@ DWORD WINAPI lineNegotiateAPIVersion(
   LPLINEEXTENSIONID lpExtensionID
 )
 {
-    FIXME("(%p, %d, %d, %d, %p, %p): stub.\n", hLineApp, dwDeviceID,
-         dwAPILowVersion, dwAPIHighVersion, lpdwAPIVersion, lpExtensionID);
+    static int warn_once;
+
+    if(!warn_once++)
+        FIXME("(%p, %d, %d, %d, %p, %p): stub.\n", hLineApp, dwDeviceID,
+              dwAPILowVersion, dwAPIHighVersion, lpdwAPIVersion, lpExtensionID);
     *lpdwAPIVersion = dwAPIHighVersion;
     return 0;
 }
@@ -1094,6 +1267,15 @@ DWORD WINAPI lineNegotiateExtVersion(HLINEAPP hLineApp, DWORD dwDeviceID, DWORD
     return 0;
 }
 
+/***********************************************************************
+ *             lineOpenW (TAPI32.@)
+ */
+DWORD WINAPI lineOpenW(HLINEAPP hLineApp, DWORD dwDeviceID, LPHLINE lphLine, DWORD dwAPIVersion, DWORD dwExtVersion, DWORD dwCallbackInstance, DWORD dwPrivileges, DWORD dwMediaModes, LPLINECALLPARAMS lpCallParams)
+{
+    FIXME("stub.\n");
+    return 0;
+}
+
 /***********************************************************************
  *             lineOpen (TAPI32.@)
  */
@@ -1361,6 +1543,18 @@ DWORD WINAPI lineTranslateAddressA(HLINEAPP hLineApp, DWORD dwDeviceID, DWORD dw
     return 0;
 }
 
+/***********************************************************************
+ *              lineTranslateAddressW (TAPI32.@)
+ */
+DWORD WINAPI lineTranslateAddressW(HLINEAPP hLineApp, DWORD dwDeviceID,
+        DWORD dwAPIVersion, LPCWSTR lpszAddressIn, DWORD dwCard,
+        DWORD dwTranslateOptions, LPLINETRANSLATEOUTPUT lpTranslateOutput)
+{
+    FIXME("(%p, %08x, %08x, %s, %08x, %08x, %p): stub.\n", hLineApp, dwDeviceID, dwAPIVersion,
+            debugstr_w(lpszAddressIn), dwCard, dwTranslateOptions, lpTranslateOutput);
+    return 0;
+}
+
 /***********************************************************************
  *             lineTranslateDialog (TAPI32.@)
  */
@@ -1370,6 +1564,17 @@ DWORD WINAPI lineTranslateDialogA(HLINEAPP hLineApp, DWORD dwDeviceID, DWORD dwA
     return 0;
 }
 
+/***********************************************************************
+ *              lineTranslateDialogW (TAPI32.@)
+ */
+DWORD WINAPI lineTranslateDialogW(HLINEAPP hLineApp, DWORD dwDeviceID,
+        DWORD dwAPIVersion, HWND hwndOwner, LPCWSTR lpszAddressIn)
+{
+    FIXME("(%p, %08x, %08x, %p, %s): stub.\n", hLineApp, dwDeviceID,
+            dwAPIVersion, hwndOwner, debugstr_w(lpszAddressIn));
+    return 0;
+}
+
 /***********************************************************************
  *             lineUncompleteCall (TAPI32.@)
  */