diff --git a/src/hal/tools.c b/src/hal/tools.c index 89441ac..2fc90db 100644 --- a/src/hal/tools.c +++ b/src/hal/tools.c @@ -203,18 +203,4 @@ void unescape_uri(char *uri) { src++; } *dst = '\0'; -} - -void uuid_generate(char *uuid) { - const char *chars = "0123456789abcdef"; - - int i, j = 0; - for (i = 0; i < 36; i++) { - if (i == 8 || i == 13 || i == 18 || i == 23) { - uuid[i] = '-'; - } else { - uuid[i] = chars[rand() % 16]; - } - } - uuid[36] = '\0'; } \ No newline at end of file diff --git a/src/hal/tools.h b/src/hal/tools.h index b3c1ea5..4274ec7 100644 --- a/src/hal/tools.h +++ b/src/hal/tools.h @@ -43,6 +43,4 @@ void reverse(void *arr, size_t width); char *split(char **input, char *sep); -void unescape_uri(char *uri); - -void uuid_generate(char *uuid); \ No newline at end of file +void unescape_uri(char *uri); \ No newline at end of file diff --git a/src/network.c b/src/network.c index 6e34cc6..94c0300 100644 --- a/src/network.c +++ b/src/network.c @@ -1,7 +1,5 @@ #include "network.h" -pthread_t onvifPid = 0; - struct mdnsd *mdns = {0}; int start_mdns() { @@ -48,88 +46,4 @@ void stop_mdns() { if (mdns) mdnsd_stop(mdns); mdns = NULL; -} - -void *onvif_thread(void) { - struct ifaddrs *ifaddr, *ifa; - char ipaddr[INET_ADDRSTRLEN]; - char msgbuf[4096]; - int servfd, msglen; - struct sockaddr_in servaddr, clntaddr; - socklen_t clntsz; - - if (getifaddrs(&ifaddr) == -1) { - HAL_DANGER("onvif", "Failed to get network interfaces!\n"); - return (void*)EXIT_FAILURE; - } - - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET) continue; - if (ifa->ifa_flags & IFF_LOOPBACK) continue; - struct sockaddr_in *addr = (struct sockaddr_in *)ifa->ifa_addr; - inet_ntop(AF_INET, &addr->sin_addr.s_addr, ipaddr, sizeof(ipaddr)); - break; - } - - if ((servfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - HAL_DANGER("onvif", "Failed to create socket!\n"); - return (void*)EXIT_FAILURE; - } - - memset(&servaddr, 0, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = INADDR_ANY; - servaddr.sin_port = htons(3702); - - if (bind(servfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { - HAL_DANGER("onvif", "Failed to bind socket!\n"); - return (void*)EXIT_FAILURE; - } - - struct ip_mreq group; - group.imr_multiaddr.s_addr = inet_addr("239.255.255.250"); - group.imr_interface.s_addr = inet_addr(ipaddr); - if (setsockopt(servfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0){ - close(servfd); - return (void*)EXIT_FAILURE; - } - - while (keepRunning) { - clntsz = sizeof(clntaddr); - if ((msglen = recvfrom(servfd, msgbuf, sizeof(msgbuf), 0, (struct sockaddr *)&clntaddr, &clntsz)) < 0) - continue; - - msgbuf[msglen] = '\0'; -#ifdef DEBUG_ONVIF - HAL_INFO("onvif", "Received message: %s\n", msgbuf); -#endif - - if (!strstr(msgbuf, "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe")) - continue; - - char uuid[37], response[2048] = {0}; - uuid_generate(uuid); - sendto(servfd, response, strlen(response), 0, (struct sockaddr *)&clntaddr, clntsz); - } - - close(servfd); - return (void*)EXIT_SUCCESS; -} - -int start_onvif_server() { - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - size_t stacksize; - pthread_attr_getstacksize(&thread_attr, &stacksize); - size_t new_stacksize = 16 * 1024; - if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) - HAL_DANGER("onvif", "Can't set stack size %zu\n", new_stacksize); - pthread_create(&onvifPid, &thread_attr, (void *(*)(void *))onvif_thread, NULL); - if (pthread_attr_setstacksize(&thread_attr, stacksize)) - HAL_DANGER("onvif", "Can't set stack size %zu\n", stacksize); - pthread_attr_destroy(&thread_attr); -} - -void stop_onvif_server() { - pthread_join(onvifPid, NULL); } \ No newline at end of file diff --git a/src/network.h b/src/network.h index c2215ed..bd402df 100644 --- a/src/network.h +++ b/src/network.h @@ -1,10 +1,7 @@ #pragma once #include -#include #include -#include -#include #include #include @@ -16,9 +13,4 @@ extern int asprintf(char **restrict strp, const char *restrict fmt, ...); #include "lib/tinysvcmdns.h" int start_mdns(); -void stop_mdns(); - -void *onvif_thread(); - -int start_onvif_server(); -void stop_onvif_server(); \ No newline at end of file +void stop_mdns(); \ No newline at end of file