Windows: remove trailing whitespace
[openafs.git] / src / WINNT / client_creds / misc.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afsconfig.h>
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 #include <roken.h>
18 }
19
20 #include "afscreds.h"
21
22
23 /*
24  * REALLOC ____________________________________________________________________
25  *
26  */
27
28 BOOL AfsCredsReallocFunction (LPVOID *ppTarget, size_t cbElement, size_t *pcTarget, size_t cReq, size_t cInc)
29 {
30    LPVOID pNew;
31    size_t cNew;
32
33    if (cReq <= *pcTarget)
34       return TRUE;
35
36    if ((cNew = cInc * ((cReq + cInc-1) / cInc)) <= 0)
37       return FALSE;
38
39    if ((pNew = Allocate (cbElement * cNew)) == NULL)
40       return FALSE;
41    memset (pNew, 0x00, cbElement * cNew);
42
43    if (*pcTarget != 0)
44       {
45       memcpy (pNew, *ppTarget, cbElement * (*pcTarget));
46       Free (*ppTarget);
47       }
48
49    *ppTarget = pNew;
50    *pcTarget = cNew;
51    return TRUE;
52 }
53
54
55 /*
56  * REGISTRY SETTINGS __________________________________________________________
57  *
58  */
59
60 void LoadRemind (size_t iCreds)
61 {
62    g.aCreds[ iCreds ].fRemind = TRUE;
63
64    HKEY hk;
65    if (RegOpenKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY "\\Reminders", 0,
66                     (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hk) == 0)
67       {
68       DWORD dwValue = 1;
69       DWORD dwSize = sizeof(dwValue);
70       DWORD dwType = REG_DWORD;
71       if (RegQueryValueEx (hk, g.aCreds[ iCreds ].szCell, NULL, &dwType, (PBYTE)&dwValue, &dwSize) == 0)
72          g.aCreds[ iCreds ].fRemind = dwValue;
73       RegCloseKey (hk);
74       }
75 }
76
77
78 void SaveRemind (size_t iCreds)
79 {
80    HKEY hk;
81    if (RegCreateKeyEx (HKEY_CURRENT_USER, AFSREG_USER_OPENAFS_SUBKEY "\\Reminders", 0, NULL, 0,
82                       (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE, NULL, &hk, NULL) == 0)
83       {
84       DWORD dwValue = g.aCreds[ iCreds ].fRemind;
85       RegSetValueEx (hk, g.aCreds[ iCreds ].szCell, NULL, REG_DWORD, (PBYTE)&dwValue, sizeof(DWORD));
86       RegCloseKey (hk);
87       }
88 }
89
90
91 void TimeToSystemTime (SYSTEMTIME *pst, time_t TimeT)
92 {
93    memset (pst, 0x00, sizeof(SYSTEMTIME));
94
95    struct tm *pTime;
96    if ((pTime = localtime (&TimeT)) != NULL)
97       {
98       pst->wYear = pTime->tm_year + 1900;
99       pst->wMonth = pTime->tm_mon + 1;
100       pst->wDayOfWeek = pTime->tm_wday;
101       pst->wDay = pTime->tm_mday;
102       pst->wHour = pTime->tm_hour;
103       pst->wMinute = pTime->tm_min;
104       pst->wSecond = pTime->tm_sec;
105       pst->wMilliseconds = 0;
106       }
107 }
108
109
110 LPARAM GetTabParam (HWND hTab, int iTab)
111 {
112    TC_ITEM Item;
113    memset (&Item, 0x00, sizeof(Item));
114    Item.mask = TCIF_PARAM;
115    if (!TabCtrl_GetItem (hTab, iTab, &Item))
116       return NULL;
117    return Item.lParam;
118 }
119
120
121 HWND GetTabChild (HWND hTab)
122 {
123    for (HWND hChild = GetWindow (hTab, GW_CHILD);
124         hChild != NULL;
125         hChild = GetWindow (hChild, GW_HWNDNEXT))
126       {
127       TCHAR szClassName[ cchRESOURCE ];
128
129       if (GetClassName (hChild, szClassName, cchRESOURCE))
130          {
131          if (!lstrcmp (szClassName, TEXT("#32770"))) // WC_DIALOG
132             return hChild;
133          }
134       }
135
136    return NULL;
137 }