1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

solve complilation errors on vs2008

replace snprintf with lws_snprintf
This commit is contained in:
hjfbswb 2019-08-01 23:03:14 +08:00 committed by Andy Green
parent 119fddbacb
commit 15ce3d03b9
7 changed files with 25 additions and 35 deletions

View file

@ -121,6 +121,3 @@
/* Defined if you have the <inttypes.h> header file. */
#cmakedefine LWS_HAVE_INTTYPES_H
#cmakedefine LWS_HAVE_SNPRINTF
#cmakedefine LWS_HAVE__SNPRINTF

View file

@ -294,8 +294,6 @@ lws_pthread_mutex_unlock(pthread_mutex_t *lock)
struct lws;
typedef int64_t lws_usec_t;
/* api change list for user code to test against */
#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
@ -467,7 +465,11 @@ struct sockaddr_in;
#else
#if defined(WIN32) || defined(_WIN32)
/* !!! >:-[ */
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t;
#else
@ -477,6 +479,7 @@ typedef unsigned char uint8_t;
#endif
#endif
typedef int64_t lws_usec_t;
typedef unsigned long long lws_filepos_t;
typedef long long lws_fileofs_t;
typedef uint32_t lws_fop_flags_t;

View file

@ -243,14 +243,14 @@ lwsl_hexdump_level(int hexdump_level, const void *vbuf, size_t len)
unsigned int start = n, m;
char line[80], *p = line;
p += snprintf(p, 10, "%04X: ", start);
p += lws_snprintf(p, 10, "%04X: ", start);
for (m = 0; m < 16 && n < len; m++)
p += snprintf(p, 5, "%02X ", buf[n++]);
p += lws_snprintf(p, 5, "%02X ", buf[n++]);
while (m++ < 16)
p += snprintf(p, 5, " ");
p += lws_snprintf(p, 5, " ");
p += snprintf(p, 6, " ");
p += lws_snprintf(p, 6, " ");
for (m = 0; m < 16 && (start + m) < len; m++) {
if (buf[start + m] >= ' ' && buf[start + m] < 127)

View file

@ -45,16 +45,6 @@
#include <inttypes.h>
#endif
#if defined(WIN32) || defined(_WIN32)
#ifndef LWS_HAVE_SNPRINTF // no snprintf
#ifdef LWS_HAVE__SNPRINTF // has _snprintf
#define snprintf _snprintf
#else
#error "no snprintf to use"
#endif
#endif
#endif
#include <assert.h>
#ifdef LWS_HAVE_SYS_TYPES_H

View file

@ -426,17 +426,17 @@ create_new_conn:
* Priority 1: connect to http proxy */
if (wsi->vhost->http.http_proxy_port) {
plen = snprintf((char *)pt->serv_buf, 256,
plen = lws_snprintf((char *)pt->serv_buf, 256,
"CONNECT %s:%u HTTP/1.0\x0d\x0a"
"User-agent: libwebsockets\x0d\x0a",
ads, wsi->c_port);
if (wsi->vhost->proxy_basic_auth_token[0])
plen += snprintf((char *)pt->serv_buf + plen, 256,
plen += lws_snprintf((char *)pt->serv_buf + plen, 256,
"Proxy-authorization: basic %s\x0d\x0a",
wsi->vhost->proxy_basic_auth_token);
plen += snprintf((char *)pt->serv_buf + plen, 5, "\x0d\x0a");
plen += lws_snprintf((char *)pt->serv_buf + plen, 5, "\x0d\x0a");
ads = wsi->vhost->http.http_proxy_address;
port = wsi->vhost->http.http_proxy_port;
#else

View file

@ -1102,23 +1102,23 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt)
* Sec-WebSocket-Version: 4
*/
p += snprintf(p, 2048, "%s %s HTTP/1.1\x0d\x0a", meth,
p += lws_snprintf(p, 2048, "%s %s HTTP/1.1\x0d\x0a", meth,
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI));
p += snprintf(p, 64, "Pragma: no-cache\x0d\x0a"
p += lws_snprintf(p, 64, "Pragma: no-cache\x0d\x0a"
"Cache-Control: no-cache\x0d\x0a");
p += snprintf(p, 128, "Host: %s\x0d\x0a",
p += lws_snprintf(p, 128, "Host: %s\x0d\x0a",
lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST));
if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN)) {
if (lws_check_opt(wsi->context->options,
LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN))
p += snprintf(p, 128, "Origin: %s\x0d\x0a",
p += lws_snprintf(p, 128, "Origin: %s\x0d\x0a",
lws_hdr_simple_ptr(wsi,
_WSI_TOKEN_CLIENT_ORIGIN));
else
p += snprintf(p, 128, "Origin: http://%s\x0d\x0a",
p += lws_snprintf(p, 128, "Origin: http://%s\x0d\x0a",
lws_hdr_simple_ptr(wsi,
_WSI_TOKEN_CLIENT_ORIGIN));
}
@ -1126,19 +1126,19 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt)
#if defined(LWS_WITH_HTTP_PROXY)
if (wsi->parent &&
lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)) {
p += snprintf(p, 128, "Content-Length: %s\x0d\x0a",
p += lws_snprintf(p, 128, "Content-Length: %s\x0d\x0a",
lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH));
if (atoi(lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)))
wsi->client_http_body_pending = 1;
}
if (wsi->parent &&
lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION)) {
p += snprintf(p, 128, "Authorization: %s\x0d\x0a",
p += lws_snprintf(p, 128, "Authorization: %s\x0d\x0a",
lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION));
}
if (wsi->parent &&
lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE)) {
p += snprintf(p, 128, "Content-Type: %s\x0d\x0a",
p += lws_snprintf(p, 128, "Content-Type: %s\x0d\x0a",
lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE));
}
#endif
@ -1153,7 +1153,7 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt)
#endif
{
if (!wsi->client_pipeline)
p += snprintf(p, 64, "connection: close\x0d\x0a");
p += lws_snprintf(p, 64, "connection: close\x0d\x0a");
}
/* give userland a chance to append, eg, cookies */
@ -1164,7 +1164,7 @@ lws_generate_client_handshake(struct lws *wsi, char *pkt)
(pkt + wsi->context->pt_serv_buf_size) - p - 12))
return NULL;
p += snprintf(p, 4, "\x0d\x0a");
p += lws_snprintf(p, 4, "\x0d\x0a");
// puts(pkt);

View file

@ -124,7 +124,7 @@ lws_add_http_header_content_length(struct lws *wsi,
char b[24];
int n;
n = snprintf(b, sizeof(b) - 1, "%llu", (unsigned long long)content_length);
n = lws_snprintf(b, sizeof(b) - 1, "%llu", (unsigned long long)content_length);
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH,
(unsigned char *)b, n, p, end))
return 1;
@ -309,7 +309,7 @@ lws_add_http_header_status(struct lws *wsi, unsigned int _code,
else
p1 = hver[0];
n = snprintf((char *)code_and_desc, sizeof(code_and_desc) - 1, "%s %u %s", p1, code,
n = lws_snprintf((char *)code_and_desc, sizeof(code_and_desc) - 1, "%s %u %s", p1, code,
description);
if (lws_add_http_header_by_name(wsi, NULL, code_and_desc, n, p,
@ -417,7 +417,7 @@ lws_return_http_status(struct lws *wsi, unsigned int code,
"</head><body><h1>%u</h1>%s</body></html>", code, html_body);
n = snprintf(slen, 12, "%d", len);
n = lws_snprintf(slen, 12, "%d", len);
if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH,
(unsigned char *)slen, n, &p, end))
return 1;