strophe / libstrophe

A simple, lightweight C library for writing XMPP clients
http://strophe.im/libstrophe
Other
401 stars 163 forks source link

How to use in visual studio? #192

Closed ughstudios closed 2 years ago

ughstudios commented 2 years ago

I have zero experience with cmake and I am primarily working from a windows background with visual studio, MSBuild and I was wondering if there is a vcpkg package for this? If not, how can I get this to work in visual studio?

ughstudios commented 2 years ago

What is this even compiling with? It doesn't even look like it's CMake?

pasis commented 2 years ago

libstrophe uses autotools as build system. There are multiple forks that use cmake as build system, you can check commit messages here to find them: https://github.com/strophe/libstrophe/network .

As for building process in general, sources in src/ should be build as a library (either static or dynamic). But only a single file must be included per list:

Project must be built with dependencies: openssl (if tls_openssl.c is chosen) and expat or libxml2 depending on what parser is chosen.

Compilation requires headers of the dependencies, so the paths must be configured in the project.

There are no windows experts among libstrophe maintainers, so, unfortunately, you will need to find external help with your issue. There are multiple projects that use libstrophe on windows, maybe you can check build systems there: e.g. UnrealEngine, NetXMS.

ughstudios commented 2 years ago

Getting tons of errors with compiling this on visual studio:

Build started...
1>------ Build started: Project: libstrophe-vs, Configuration: Debug Win32 ------
1>auth.c
1>conn.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1229,5): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1232,13): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1233,13): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1234,13): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1236,13): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1237,13): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\conn.c(1240,5): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>crypto.c
1>ctx.c
1>event.c
1>handler.c
1>hash.c
1>jid.c
1>md5.c
1>parser_expat.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\parser_expat.c(262,5): error C4996: 'strncat': This function or variable may be unsafe. Consider using strncat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>rand.c
1>resolver.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(691,43): warning C4133: 'function': incompatible types - from 'char [11]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(758,55): warning C4133: 'function': incompatible types - from 'char [13]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(793,73): warning C4133: 'function': incompatible types - from 'char [51]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(799,70): warning C4133: 'function': incompatible types - from 'char [44]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(807,61): warning C4133: 'function': incompatible types - from 'char [11]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(811,69): warning C4133: 'function': incompatible types - from 'char [15]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(847,57): warning C4133: 'function': incompatible types - from 'char [62]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(865,54): warning C4133: 'function': incompatible types - from 'char [512]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(867,74): warning C4133: 'function': incompatible types - from 'char [15]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(889,77): warning C4133: 'function': incompatible types - from 'char [11]' to 'LPCWSTR'
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(776,29): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(826,25): error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(880,33): error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(902,33): error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(932,13): error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\resolver.c(947,43): error C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
1>sasl.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\sasl.c(463,5): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\sasl.c(464,5): error C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>scram.c
1>sha1.c
1>sha256.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\sha.h(90,1): fatal error C1189: #error:  Unknown endianness not supported
1>sha512.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\sha.h(90,1): fatal error C1189: #error:  Unknown endianness not supported
1>snprintf.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\snprintf.c(349,35): warning C4267: '=': conversion from 'size_t' to 'short', possible loss of data
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\snprintf.c(555,20): warning C4244: '=': conversion from 'double' to 'long', possible loss of data
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\snprintf.c(604,22): warning C4244: '=': conversion from 'double' to 'long', possible loss of data
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\snprintf.c(620,36): warning C4244: '-=': conversion from 'double' to 'long', possible loss of data
1>stanza.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\stanza.c(272,13): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\stanza.c(276,13): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\stanza.c(280,13): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\stanza.c(284,13): error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>tls.c
1>Generating Code...
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\handler.c(706): error C4703: potentially uninitialized local pointer variable 'key2' used
1>Compiling...
1>tls_openssl.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\tls_openssl.c(25,10): fatal error C1083: Cannot open include file: 'openssl/ssl.h': No such file or directory
1>util.c
1>D:\repos\Perforce\orange_project\shared\vendor\libstrophe-vs\libstrophe-vs\util.c(168,9): error C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>uuid.c
1>Generating Code...
1>Done building project "libstrophe-vs.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I could probably fix these all myself, manually, but I don't want to break anything since I don't know what everything does. Do you think it would be a good idea to replace strcpy warnings, or replace it with strcpy_s? What about the other errors?

ughstudios commented 2 years ago

The unknown endianness is defined in sha.h image

Not sure what's going on here though?

#if defined(__BIG_ENDIAN__) ||                                   \
    (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
     __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)

#define STORE32H(x, y)      \
    do {                    \
        uint32_t __t = (x); \
        memcpy(y, &__t, 4); \
    } while (0)

#define LOAD32H(x, y)       \
    do {                    \
        memcpy(&(x), y, 4); \
        x &= 0xFFFFFFFF;    \
    } while (0)

#define STORE64H(x, y)      \
    do {                    \
        uint64_t __t = (x); \
        memcpy(y, &__t, 8); \
    } while (0)

#define LOAD64H(x, y)       \
    do {                    \
        memcpy(&(x), y, 8); \
    } while (0)

#elif defined(__LITTLE_ENDIAN__) ||                                 \
    (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
     __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)

#define STORE32H(x, y)                         \
    do {                                       \
        (y)[0] = (uint8_t)(((x) >> 24) & 255); \
        (y)[1] = (uint8_t)(((x) >> 16) & 255); \
        (y)[2] = (uint8_t)(((x) >> 8) & 255);  \
        (y)[3] = (uint8_t)((x)&255);           \
    } while (0)

#define LOAD32H(x, y)                                                     \
    do {                                                                  \
        x = ((uint32_t)((y)[0] & 255) << 24) |                            \
            ((uint32_t)((y)[1] & 255) << 16) |                            \
            ((uint32_t)((y)[2] & 255) << 8) | ((uint32_t)((y)[3] & 255)); \
    } while (0)

#define STORE64H(x, y)                         \
    do {                                       \
        (y)[0] = (uint8_t)(((x) >> 56) & 255); \
        (y)[1] = (uint8_t)(((x) >> 48) & 255); \
        (y)[2] = (uint8_t)(((x) >> 40) & 255); \
        (y)[3] = (uint8_t)(((x) >> 32) & 255); \
        (y)[4] = (uint8_t)(((x) >> 24) & 255); \
        (y)[5] = (uint8_t)(((x) >> 16) & 255); \
        (y)[6] = (uint8_t)(((x) >> 8) & 255);  \
        (y)[7] = (uint8_t)((x)&255);           \
    } while (0)

#define LOAD64H(x, y)                                                         \
    do {                                                                      \
        x = (((uint64_t)((y)[0] & 255)) << 56) |                              \
            (((uint64_t)((y)[1] & 255)) << 48) |                              \
            (((uint64_t)((y)[2] & 255)) << 40) |                              \
            (((uint64_t)((y)[3] & 255)) << 32) |                              \
            (((uint64_t)((y)[4] & 255)) << 24) |                              \
            (((uint64_t)((y)[5] & 255)) << 16) |                              \
            (((uint64_t)((y)[6] & 255)) << 8) | (((uint64_t)((y)[7] & 255))); \
    } while (0)

#else
#error Unknown endianness not supported
#endif

Looks like it's doing a lot of preprocessor stuff in sha.h

pasis commented 2 years ago

strcpy(), strcat(), etc are not errors, but warnings. "safe" versions strncpy(), strncat() may be even more harmful in some cases, so it is not wise to simply force them. I haven't inspected the code around warnings, but can assume, that buffer overflows are handled before calling these "unsafe" functions.

So simply use _CRT_SECURE_NO_WARNING as suggested in the error message.

As for:

fatal error C1083: Cannot open include file: 'openssl/ssl.h': No such file or directory

You need to configure project to use openssl properly. Refer to external documentation how to build projects with openssl in visual studio. Unfortunately, I cannot help with it. Alternatively, you can replace tls_openssl.c with tls_dummy.c and try to build libstrophe without TLS support as the 1st step.

As for sha error, your compiler doesn't define endianness macros. You likely have little endian machine, so to build it you can simply define __LITTLE_ENDIAN__ above the code or in the project config. If you find the way how your compiler reports the endianness, we can add it to the checks.

As for:

error C4703: potentially uninitialized local pointer variable 'key2' used

This is a false positive. key2 will always be initialized when it is used. To shut this error you can initialize key2 with 0 for example.

ughstudios commented 2 years ago

Gotcha, what you're proposing is essentially what I ended up doing.

ughstudios commented 2 years ago

I might try to submit a separate fork on github with a visual studio solution. However, I want to make sure I actually understand it. For some reason, I'm unable to send a message: https://github.com/strophe/libstrophe/issues/193