Check command line, clean warnings.

This commit is contained in:
Thomas Bernard 2019-02-12 15:46:48 +01:00
parent b4938b278d
commit 619a386006
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 29 additions and 9 deletions

View File

@ -1,6 +1,7 @@
# tested with GNU Make # tested with GNU Make
PKG_CONFIG ?= pkg-config PKG_CONFIG ?= pkg-config
CFLAGS += -g
CFLAGS += -Wall -Wextra CFLAGS += -Wall -Wextra
CFLAGS += $(shell $(PKG_CONFIG) libuv --cflags) CFLAGS += $(shell $(PKG_CONFIG) libuv --cflags)
LDFLAGS += $(shell $(PKG_CONFIG) libuv --libs-only-L) LDFLAGS += $(shell $(PKG_CONFIG) libuv --libs-only-L)

View File

@ -6,19 +6,21 @@
void requestFinish2(void* session, void* userdata, struct UPNPDev* upnpdev) void requestFinish2(void* session, void* userdata, struct UPNPDev* upnpdev)
{ {
struct UPNPDev* it = upnpdev; struct UPNPDev* it;
while(it != NULL) { (void)userdata;
for(it = upnpdev; it != NULL; it = it->pNext) {
printf("url = %s\n", it->descURL); printf("url = %s\n", it->descURL);
printf("st = %s\n", it->st); printf("st = %s\n", it->st);
printf("usn = %s\n", it->usn); printf("usn = %s\n", it->usn);
printf("\n"); printf("\n");
it = it->pNext;
} }
disconnectFromMiniSSDPD((uv_stream_t*)session); disconnectFromMiniSSDPD((uv_stream_t*)session);
} }
void requestFinish(void* session, int success, void* userdata) void requestFinish(void* session, int success, void* userdata)
{ {
(void)userdata;
if (success == 0) if (success == 0)
{ {
printf("Error while requesting results.\n"); printf("Error while requesting results.\n");
@ -48,8 +50,17 @@ void connect_cb(void* session, void* userdata)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char* pipeName = argv[1]; char* pipeName;
char* search = argv[2]; char* search;
if (argc < 3) {
printf("Usage: %s </path/to/minissdpd.socket> <device>\n", argv[0]);
printf(" ssdp:all for all devices\n");
return 1;
}
pipeName = argv[1];
search = argv[2];
connectToMiniSSDPD(pipeName, &connect_cb, search); connectToMiniSSDPD(pipeName, &connect_cb, search);
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
return 0;
} }

View File

@ -88,15 +88,22 @@ static void write_cb(uv_write_t* req, int status)
MINIUPNP_LIBSPEC int MINIUPNP_LIBSPEC int
requestDevicesFromMiniSSDPD(void *session, const char * devtype, void(*requestFinish)(void *connect, int success, void* userdata), void* userdata) requestDevicesFromMiniSSDPD(void *session, const char * devtype, void(*requestFinish)(void *connect, int success, void* userdata), void* userdata)
{ {
char *buffer = malloc(256); char *buffer;
char *p;
unsigned int stsize;
if (devtype == NULL)
{
return MINISSDPC_UNKNOWN_ERROR;
}
stsize = strlen(devtype);
buffer = malloc(256);
if(buffer == NULL) if(buffer == NULL)
{ {
return MINISSDPC_MEMORY_ERROR; return MINISSDPC_MEMORY_ERROR;
} }
p = buffer;
char *p = buffer;
unsigned int stsize = strlen(devtype);
if(stsize == 8 && 0 == memcmp(devtype, "ssdp:all", 8)) if(stsize == 8 && 0 == memcmp(devtype, "ssdp:all", 8))
{ {
@ -155,6 +162,7 @@ requestDevicesFromMiniSSDPD(void *session, const char * devtype, void(*requestFi
static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf)
{ {
(void)handle;
buf->base = malloc(size); buf->base = malloc(size);
buf->len = size; buf->len = size;
} }