"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "stream.c" between
motion-release-4.2.2.tar.gz and motion-Release-4.3.0.tar.gz

About: Motion monitors the video signal from one or more cameras and is able to detect motion.

stream.c  (motion-release-4.2.2):stream.c  (motion-Release-4.3.0)
/* /*
* NOTICE
* This entire module (stream.c) is dead code and will be removed in its entir
ety very shortly
*
* The only reason that it has not been removed yet is to allow for an emergen
cy option to use
* the old stream method if for some reason the webu MHD option does not work
on a particular
* platform. It is only avaialable for activation using the undocumented opti
on of
* cnt->conf.stream_preview_method == 99
*
* NO REVISIONS SHOULD BE MADE TO THIS MODULE. IT IS DEAD
*/
/*
* stream.c (based in webcam.c) * stream.c (based in webcam.c)
* Streaming using jpeg images over a multipart/x-mixed-replace stream * Streaming using jpeg images over a multipart/x-mixed-replace stream
* Copyright (C) 2002 Jeroen Vreeken (pe1rxq@amsat.org) * Copyright (C) 2002 Jeroen Vreeken (pe1rxq@amsat.org)
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
skipping to change at line 53 skipping to change at line 65
}; };
/** /**
* get_host * get_host
* Gets the host (IP) of a client from the socket file descriptor * Gets the host (IP) of a client from the socket file descriptor
* Returns nothing * Returns nothing
*/ */
static void get_host(char *buf, int fd) static void get_host(char *buf, int fd)
{ {
struct sockaddr_storage client; struct sockaddr_storage client;
int retcd;
socklen_t client_len = sizeof(client); socklen_t client_len = sizeof(client);
int res = getpeername(fd, (struct sockaddr *)&client, &client_len); int res = getpeername(fd, (struct sockaddr *)&client, &client_len);
if (res != 0) if (res != 0)
return; return;
char host[NI_MAXHOST]; char host[NI_MAXHOST];
res = getnameinfo((struct sockaddr *)&client, client_len, host, sizeof(host) , NULL, 0, NI_NUMERICHOST); res = getnameinfo((struct sockaddr *)&client, client_len, host, sizeof(host) , NULL, 0, NI_NUMERICHOST);
if (res != 0) if (res != 0)
return; return;
strncpy(buf, host, NI_MAXHOST - 1); retcd = snprintf(buf,NI_MAXHOST - 1,"%s",host);
if ((retcd < 0) || (retcd >= (int)NI_MAXHOST-1)){
MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO
,_("Error specifying host"));
}
} }
pthread_mutex_t stream_auth_mutex; pthread_mutex_t stream_auth_mutex;
/** /**
* set_sock_timeout * set_sock_timeout
* *
* Returns : 0 or 1 on timeout * Returns : 0 or 1 on timeout
*/ */
static int set_sock_timeout(int sock, int sec) static int set_sock_timeout(int sock, int sec)
skipping to change at line 102 skipping to change at line 121
* Returns : 1 on success or 0 if any error happens * Returns : 1 on success or 0 if any error happens
*/ */
static int read_http_request(int sock, char* buffer, int buflen, char* uri, int uri_len) static int read_http_request(int sock, char* buffer, int buflen, char* uri, int uri_len)
{ {
int nread = 0; int nread = 0;
int ret,readb = 1; int ret,readb = 1;
char method[10] = {'\0'}; char method[10] = {'\0'};
char url[512] = {'\0'}; char url[512] = {'\0'};
char protocol[10] = {'\0'}; char protocol[10] = {'\0'};
static const char *bad_request_response_raw = #define bad_request_response_raw \
"HTTP/1.0 400 Bad Request\r\n" "HTTP/1.0 400 Bad Request\r\n" \
"Content-type: text/plain\r\n\r\n" "Content-type: text/plain\r\n\r\n" \
"Bad Request\n"; "Bad Request\n"
static const char *bad_method_response_template_raw = #define bad_method_response_template_raw \
"HTTP/1.0 501 Method Not Implemented\r\n" "HTTP/1.0 501 Method Not Implemented\r\n" \
"Content-type: text/plain\r\n\r\n" "Content-type: text/plain\r\n\r\n" \
"Method Not Implemented\n"; "Method Not Implemented\n"
static const char *timeout_response_template_raw = #define timeout_response_template_raw \
"HTTP/1.0 408 Request Timeout\r\n" "HTTP/1.0 408 Request Timeout\r\n" \
"Content-type: text/plain\r\n\r\n" "Content-type: text/plain\r\n\r\n" \
"Request Timeout\n"; "Request Timeout\n"
buffer[0] = '\0'; buffer[0] = '\0';
while ((strstr(buffer, "\r\n\r\n") == NULL) && (readb != 0) && (nread < bufl en)) { while ((strstr(buffer, "\r\n\r\n") == NULL) && (readb != 0) && (nread < bufl en)) {
readb = read(sock, buffer+nread, buflen - nread); readb = read(sock, buffer+nread, buflen - nread);
if (readb == -1) { if (readb == -1) {
nread = -1; nread = -1;
break; break;
skipping to change at line 174 skipping to change at line 193
ret = write(sock, bad_request_response_raw, sizeof(bad_request_response_ raw)); ret = write(sock, bad_request_response_raw, sizeof(bad_request_response_ raw));
return 0; return 0;
} }
if (strcmp(method, "GET")) { if (strcmp(method, "GET")) {
/* /*
* This server only implements the GET method. If client * This server only implements the GET method. If client
* uses other method, report the failure. * uses other method, report the failure.
*/ */
char response[1024]; char response[1024];
snprintf(response, sizeof(response), bad_method_response_template_raw, m ethod); snprintf(response, sizeof(response), bad_method_response_template_raw);
ret = write(sock, response, strlen (response)); ret = write(sock, response, strlen (response));
return 0; return 0;
} }
if(uri) if(uri){
strncpy(uri, url, uri_len); ret = snprintf(uri, uri_len,"%s",url);
if ((ret < 0) || (ret >= uri_len)){
MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO
,_("Unable to set uri"));
}
}
return 1; return 1;
} }
static void stream_add_client(struct stream *list, int sc); static void stream_add_client(struct stream *list, int sc);
/** /**
* handle_basic_auth * handle_basic_auth
* *
* *
skipping to change at line 428 skipping to change at line 452
char buffer[1024] = {'\0'}; char buffer[1024] = {'\0'};
ssize_t length = 1023; ssize_t length = 1023;
char *auth, *h, *username, *realm, *uri, *nonce, *response; char *auth, *h, *username, *realm, *uri, *nonce, *response;
int username_len, realm_len, uri_len, nonce_len, response_len; int username_len, realm_len, uri_len, nonce_len, response_len;
#define SERVER_NONCE_LEN 17 #define SERVER_NONCE_LEN 17
char server_nonce[SERVER_NONCE_LEN]; char server_nonce[SERVER_NONCE_LEN];
#define SERVER_URI_LEN 512 #define SERVER_URI_LEN 512
char server_uri[SERVER_URI_LEN]; char server_uri[SERVER_URI_LEN];
char* server_user = NULL, *server_pass = NULL; char* server_user = NULL, *server_pass = NULL;
unsigned int rand1,rand2; unsigned int rand1,rand2;
int retcd, len_user,len_pass;
HASHHEX HA1; HASHHEX HA1;
HASHHEX HA2 = ""; HASHHEX HA2 = "";
HASHHEX server_response; HASHHEX server_response;
static const char *request_auth_response_template= static const char *request_auth_response_template=
"HTTP/1.0 401 Authorization Required\r\n" "HTTP/1.0 401 Authorization Required\r\n"
"Server: Motion/"VERSION"\r\n" "Server: Motion/"VERSION"\r\n"
"Max-Age: 0\r\n" "Max-Age: 0\r\n"
"Expires: 0\r\n" "Expires: 0\r\n"
"Cache-Control: no-cache, private\r\n" "Cache-Control: no-cache, private\r\n"
"Pragma: no-cache\r\n" "Pragma: no-cache\r\n"
skipping to change at line 486 skipping to change at line 512
goto InternalError; goto InternalError;
} }
h = strstr(p->conf->stream_authentication, ":"); h = strstr(p->conf->stream_authentication, ":");
if (!h) { if (!h) {
MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO
,_("Error no authentication data (no ':' found)")); ,_("Error no authentication data (no ':' found)"));
goto InternalError; goto InternalError;
} }
server_user = (char*)malloc((h - p->conf->stream_authentication) + 1); len_user = (h - p->conf->stream_authentication);
server_pass = (char*)malloc(strlen(h) + 1); len_pass = strlen(h);
server_user = (char*)malloc(len_user + 1);
server_pass = (char*)malloc(len_pass + 1);
if (!server_user || !server_pass) { if (!server_user || !server_pass) {
MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO
,_("Error malloc failed")); ,_("Error malloc failed"));
goto InternalError; goto InternalError;
} }
strncpy(server_user, p->conf->stream_authentication, h-p->conf->stream_authe retcd = snprintf(server_user, len_user+1, "%s", p->conf->stream_authenticati
ntication); on);
server_user[h - p->conf->stream_authentication] = '\0'; if ((retcd < 0) || (retcd >= len_user)) {
strncpy(server_pass, h + 1, strlen(h + 1)); MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO
server_pass[strlen(h + 1)] = '\0'; ,_("Error server user"));
goto InternalError;
}
retcd = snprintf(server_pass, len_pass+1, "%s", h);
if ((retcd < 0) || (retcd >= len_user)) {
MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO
,_("Error server pass"));
goto InternalError;
}
while(1) { while(1) {
if(!read_http_request(p->sock, buffer, length, server_uri, SERVER_URI_LE N - 1)) if(!read_http_request(p->sock, buffer, length, server_uri, SERVER_URI_LE N - 1))
goto Invalid_Request; goto Invalid_Request;
auth = strstr(buffer, "Authorization: Digest"); auth = strstr(buffer, "Authorization: Digest");
if(!auth) if(!auth)
goto Error; goto Error;
auth += sizeof("Authorization: Digest"); auth += sizeof("Authorization: Digest");
 End of changes. 9 change blocks. 
25 lines changed or deleted 66 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)