summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-10-19 22:33:17 -0700
committerGarrett D'Amore <garrett@damore.org>2016-10-20 11:20:19 -0700
commitcadd0d933bc7fba435f5e857759c178c679c16e6 (patch)
treeff95f748c9cc3e071abc003b821602bdc2eb785b /src/utils
parent3d4bed9aa567852b21943fec1e1da55e32d7db2d (diff)
downloadnanomsg-cadd0d933bc7fba435f5e857759c178c679c16e6.tar.gz
fixes #783 WS transport - not connectable from Firefox
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/strcasecmp.c42
-rw-r--r--src/utils/strcasecmp.h28
-rw-r--r--src/utils/strcasestr.c40
-rw-r--r--src/utils/strcasestr.h28
-rw-r--r--src/utils/strncasecmp.c42
-rw-r--r--src/utils/strncasecmp.h28
6 files changed, 208 insertions, 0 deletions
diff --git a/src/utils/strcasecmp.c b/src/utils/strcasecmp.c
new file mode 100644
index 0000000..dec74c5
--- /dev/null
+++ b/src/utils/strcasecmp.c
@@ -0,0 +1,42 @@
+/*
+ Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#include <ctype.h>
+#include "strcasecmp.h"
+
+int
+nn_strcasecmp(const char *a, const char *b)
+{
+ int rv;
+ for (;;) {
+ if ((*a == 0) && (*b == 0)) {
+ return (0);
+ }
+ if ((rv = (tolower(*a) - tolower(*b))) != 0) {
+ return (rv);
+ }
+ a++;
+ b++;
+ }
+ return (0);
+}
+
diff --git a/src/utils/strcasecmp.h b/src/utils/strcasecmp.h
new file mode 100644
index 0000000..96d8d82
--- /dev/null
+++ b/src/utils/strcasecmp.h
@@ -0,0 +1,28 @@
+/*
+ Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#ifndef NN_STRCASECMP_INCLUDED
+#define NN_STRCASECMP_INCLUDED
+
+extern int nn_strcasecmp(const char *, const char *);
+
+#endif /* NN_STRCASECMP_INCLUDED */
diff --git a/src/utils/strcasestr.c b/src/utils/strcasestr.c
new file mode 100644
index 0000000..fe7fe76
--- /dev/null
+++ b/src/utils/strcasestr.c
@@ -0,0 +1,40 @@
+/*
+ Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include "strncasecmp.h"
+
+const char *
+nn_strcasestr(const char *str, const char *key)
+{
+ int len = strlen(key);
+
+ while (*str != '\0') {
+ if (nn_strncasecmp(str, key, len) == 0) {
+ return str;
+ }
+ str++;
+ }
+ return (NULL);
+}
diff --git a/src/utils/strcasestr.h b/src/utils/strcasestr.h
new file mode 100644
index 0000000..8c762c8
--- /dev/null
+++ b/src/utils/strcasestr.h
@@ -0,0 +1,28 @@
+/*
+ Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#ifndef NN_STRCASESTR_INCLUDED
+#define NN_STRCASESTR_INCLUDED
+
+extern const char *nn_strcasestr(const char *, const char *);
+
+#endif /* NN_STRCASESTR */
diff --git a/src/utils/strncasecmp.c b/src/utils/strncasecmp.c
new file mode 100644
index 0000000..fe88f58
--- /dev/null
+++ b/src/utils/strncasecmp.c
@@ -0,0 +1,42 @@
+/*
+ Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#include <ctype.h>
+#include "strncasecmp.h"
+
+int
+nn_strncasecmp(const char *a, const char *b, int len)
+{
+ int rv;
+ int count;
+ for (count = 0; count < len; count++) {
+ if ((*a == 0) && (*b == 0)) {
+ return (0);
+ }
+ if ((rv = tolower(*a) - tolower(*b)) != 0) {
+ return (rv);
+ }
+ a++;
+ b++;
+ }
+ return (0);
+}
diff --git a/src/utils/strncasecmp.h b/src/utils/strncasecmp.h
new file mode 100644
index 0000000..390b4ed
--- /dev/null
+++ b/src/utils/strncasecmp.h
@@ -0,0 +1,28 @@
+/*
+ Copyright 2016 Garrett D'Amore <garrett@damore.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom
+ the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+*/
+
+#ifndef NN_STRNCASECMP_INCLUDED
+#define NN_STRNCASECMP_INCLUDED
+
+extern int nn_strncasecmp(const char *, const char *, int);
+
+#endif /* NN_STRNCASECMP_INCLUDED */