summaryrefslogtreecommitdiffstats
path: root/other-licenses/nsis/Contrib/CityHash/CityHash.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /other-licenses/nsis/Contrib/CityHash/CityHash.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'other-licenses/nsis/Contrib/CityHash/CityHash.cpp')
-rw-r--r--other-licenses/nsis/Contrib/CityHash/CityHash.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.cpp b/other-licenses/nsis/Contrib/CityHash/CityHash.cpp
new file mode 100644
index 000000000..9998fb627
--- /dev/null
+++ b/other-licenses/nsis/Contrib/CityHash/CityHash.cpp
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "CityHash.h"
+#include "cityhash/city.h"
+#include <tchar.h>
+
+#define MAX_STRLEN 1024
+
+typedef struct _stack_t {
+ struct _stack_t *next;
+ TCHAR text[MAX_STRLEN];
+} stack_t;
+
+stack_t **g_stacktop;
+char *g_variables;
+
+BOOL APIENTRY DllMain(HMODULE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved)
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+
+bool popString(TCHAR *result)
+{
+ stack_t *th;
+ if (!g_stacktop || !*g_stacktop) return false;
+ th = (*g_stacktop);
+ lstrcpyn(result, th->text, MAX_STRLEN);
+ *g_stacktop = th->next;
+ GlobalFree((HGLOBAL)th);
+ return true;
+}
+
+void pushString(const TCHAR *str)
+{
+ stack_t *th;
+ int strLen = wcslen(str)+1;
+ if (!g_stacktop) return;
+ th = (stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + (MAX_STRLEN*sizeof(TCHAR)));
+ lstrcpyn(th->text, str, strLen);
+ th->next = *g_stacktop;
+ *g_stacktop = th;
+}
+
+extern "C"
+{
+
+void GetCityHash64(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)
+{
+ TCHAR hashString[MAX_STRLEN];
+ TCHAR hexResult[18] = { _T('\0') };
+
+ g_stacktop = stacktop;
+ g_variables = variables;
+
+ memset(hashString, 0, sizeof(hashString));
+ memset(hexResult, 0, sizeof(hexResult));
+
+ if (!popString(hashString)) {
+ pushString(L"error");
+ return;
+ }
+ uint64 result = CityHash64((const char*)&hashString[0], wcslen(hashString)*sizeof(TCHAR));
+ // If the hash happens to work out to less than 16 hash digits it will just
+ // use less of the buffer.
+ swprintf(hexResult, L"%I64X", result);
+ pushString(hexResult);
+}
+
+}