diff cinst/windowsstore.c @ 163:8cfcd38a9bb3

Change coding style for cinst main / windowsstore to GNU The kdelibs / qt coding style is not really suited for plain C and looks irritiating when combined with standard C functions.
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 25 Mar 2014 10:29:12 +0000
parents a4b1c77f3e6a
children ee37c085b9f7
line wrap: on
line diff
--- a/cinst/windowsstore.c	Tue Mar 25 10:08:56 2014 +0000
+++ b/cinst/windowsstore.c	Tue Mar 25 10:29:12 2014 +0000
@@ -7,82 +7,95 @@
 #include "listutil.h"
 #include "strhelp.h"
 
-static LPWSTR getLastErrorMsg() {
-    LPWSTR bufPtr = NULL;
-    DWORD err = GetLastError();
-    FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                   FORMAT_MESSAGE_FROM_SYSTEM |
-                   FORMAT_MESSAGE_IGNORE_INSERTS,
-                   NULL, err, 0, (LPWSTR)&bufPtr, 0, NULL);
-    if (!bufPtr) {
-        HMODULE hWinhttp = GetModuleHandleW(L"winhttp");
-        if (hWinhttp) {
-            FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                           FORMAT_MESSAGE_FROM_HMODULE |
-                           FORMAT_MESSAGE_IGNORE_INSERTS,
-                           hWinhttp, HRESULT_CODE(err), 0,
-                           (LPWSTR)&bufPtr, 0, NULL);
+static LPWSTR getLastErrorMsg()
+{
+  LPWSTR bufPtr = NULL;
+  DWORD err = GetLastError();
+  FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                  FORMAT_MESSAGE_FROM_SYSTEM |
+                  FORMAT_MESSAGE_IGNORE_INSERTS,
+                  NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL);
+  if (!bufPtr)
+    {
+      HMODULE hWinhttp = GetModuleHandleW (L"winhttp");
+      if (hWinhttp)
+        {
+          FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                          FORMAT_MESSAGE_FROM_HMODULE |
+                          FORMAT_MESSAGE_IGNORE_INSERTS,
+                          hWinhttp, HRESULT_CODE (err), 0,
+                          (LPWSTR) &bufPtr, 0, NULL);
         }
     }
-    if (!bufPtr)
-        printf("Error getting last error\n");
-    return bufPtr;
+  if (!bufPtr)
+    printf ("Error getting last error\n");
+  return bufPtr;
 }
 
-int write_stores_win(char **to_install, char **to_remove, bool user_store)
+int write_stores_win (char **to_install, char **to_remove, bool user_store)
 {
-    int i = 0;
-    int ret = -1;
-    HCERTSTORE hStore = NULL;
+  int i = 0;
+  int ret = -1;
+  HCERTSTORE hStore = NULL;
 
-    if (user_store) {
-        hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0,
-                               0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
-    } else {
-        hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0,
-                               0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root");
+  if (user_store)
+    {
+      hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0,
+                              0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
+    }
+  else
+    {
+      hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0,
+                              0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root");
     }
 
-    if (!hStore) {
-        return ERR_STORE_ACCESS_DENIED;
+  if (!hStore)
+    {
+      return ERR_STORE_ACCESS_DENIED;
     }
 
-    for (i=0; to_install[i]; i++) {
-        size_t cert_len = strnlen(to_install[i], MAX_LINE_LENGTH),
-               buf_size = 0;
-        char *buf = NULL;
+  for (i=0; to_install[i]; i++)
+    {
+      size_t cert_len = strnlen (to_install[i], MAX_LINE_LENGTH),
+             buf_size = 0;
+      char *buf = NULL;
 
-        ret = str_base64_decode(&buf, &buf_size, to_install[i], cert_len);
+      ret = str_base64_decode (&buf, &buf_size, to_install[i], cert_len);
 
-        if (ret != 0) {
-            return ERR_INVALID_INSTRUCTIONS;
+      if (ret != 0)
+        {
+          return ERR_INVALID_INSTRUCTIONS;
         }
 
-        ret = CertAddEncodedCertificateToStore (hStore,
-                                                X509_ASN_ENCODING,
-                                                (PBYTE)buf,
-                                                buf_size,
-                                                CERT_STORE_ADD_ALWAYS,
-                                                NULL);
+      ret = CertAddEncodedCertificateToStore (hStore,
+                                              X509_ASN_ENCODING,
+                                              (PBYTE) buf,
+                                              buf_size,
+                                              CERT_STORE_ADD_ALWAYS,
+                                              NULL);
 
-        if (ret == 0) {
-            LPWSTR error = getLastErrorMsg();
-            if (error) {
-                printf("Failed to add certificate: %S \n", error);
-                LocalFree(error);
+      if (ret == 0)
+        {
+          LPWSTR error = getLastErrorMsg();
+          if (error)
+            {
+              printf ("Failed to add certificate: %S \n", error);
+              LocalFree (error);
             }
         }
-        i++;
-        free(buf);
+      i++;
+      free (buf);
     }
 
-    for (i=0; to_remove[i]; i++) {
-        // TODO
+  for (i=0; to_remove[i]; i++)
+    {
+      // TODO
     }
 
-    if(hStore) {
-        CertCloseStore(hStore, 0);
+  if (hStore)
+    {
+      CertCloseStore (hStore, 0);
     }
-    return 0;
+  return 0;
 }
 #endif // WIN32

http://wald.intevation.org/projects/trustbridge/