* Code cleanup.
This commit is contained in:
parent
1ca6bb2eb1
commit
ffd5df4a58
267
upnphttp.c
267
upnphttp.c
@ -117,9 +117,7 @@ Delete_upnphttp(struct upnphttp * h)
|
|||||||
{
|
{
|
||||||
if(h->socket >= 0)
|
if(h->socket >= 0)
|
||||||
CloseSocket_upnphttp(h);
|
CloseSocket_upnphttp(h);
|
||||||
if(h->req_buf)
|
|
||||||
free(h->req_buf);
|
free(h->req_buf);
|
||||||
if(h->res_buf)
|
|
||||||
free(h->res_buf);
|
free(h->res_buf);
|
||||||
free(h);
|
free(h);
|
||||||
}
|
}
|
||||||
@ -257,8 +255,8 @@ intervening space) by either an integer or the keyword "infinite". */
|
|||||||
p++;
|
p++;
|
||||||
if(strncasecmp(p, "bytes=", 6)==0) {
|
if(strncasecmp(p, "bytes=", 6)==0) {
|
||||||
h->reqflags |= FLAG_RANGE;
|
h->reqflags |= FLAG_RANGE;
|
||||||
h->req_RangeEnd = atoll(index(p+6, '-')+1);
|
h->req_RangeStart = strtoll(p+6, &colon, 10);
|
||||||
h->req_RangeStart = atoll(p+6);
|
h->req_RangeEnd = colon ? atoll(colon+1) : 0;
|
||||||
DPRINTF(E_DEBUG, L_HTTP, "Range Start-End: %lld - %lld\n",
|
DPRINTF(E_DEBUG, L_HTTP, "Range Start-End: %lld - %lld\n",
|
||||||
h->req_RangeStart, h->req_RangeEnd?h->req_RangeEnd:-1);
|
h->req_RangeStart, h->req_RangeEnd?h->req_RangeEnd:-1);
|
||||||
}
|
}
|
||||||
@ -1180,18 +1178,17 @@ send_file(struct upnphttp * h, int sendfd, off_t offset, off_t end_offset)
|
|||||||
}
|
}
|
||||||
offset+=ret;
|
offset+=ret;
|
||||||
}
|
}
|
||||||
if( buf )
|
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SendResp_icon(struct upnphttp * h, char * icon)
|
SendResp_icon(struct upnphttp * h, char * icon)
|
||||||
{
|
{
|
||||||
char * header;
|
char header[512];
|
||||||
char * data;
|
char mime[12] = "image/";
|
||||||
int size, ret;
|
|
||||||
char mime[12];
|
|
||||||
char date[30];
|
char date[30];
|
||||||
|
char *data;
|
||||||
|
int size, ret;
|
||||||
time_t curtime = time(NULL);
|
time_t curtime = time(NULL);
|
||||||
|
|
||||||
if( strcmp(icon, "sm.png") == 0 )
|
if( strcmp(icon, "sm.png") == 0 )
|
||||||
@ -1199,28 +1196,28 @@ SendResp_icon(struct upnphttp * h, char * icon)
|
|||||||
DPRINTF(E_DEBUG, L_HTTP, "Sending small PNG icon\n");
|
DPRINTF(E_DEBUG, L_HTTP, "Sending small PNG icon\n");
|
||||||
data = (char *)png_sm;
|
data = (char *)png_sm;
|
||||||
size = sizeof(png_sm)-1;
|
size = sizeof(png_sm)-1;
|
||||||
strcpy(mime, "image/png");
|
strcpy(mime+6, "png");
|
||||||
}
|
}
|
||||||
else if( strcmp(icon, "lrg.png") == 0 )
|
else if( strcmp(icon, "lrg.png") == 0 )
|
||||||
{
|
{
|
||||||
DPRINTF(E_DEBUG, L_HTTP, "Sending large PNG icon\n");
|
DPRINTF(E_DEBUG, L_HTTP, "Sending large PNG icon\n");
|
||||||
data = (char *)png_lrg;
|
data = (char *)png_lrg;
|
||||||
size = sizeof(png_lrg)-1;
|
size = sizeof(png_lrg)-1;
|
||||||
strcpy(mime, "image/png");
|
strcpy(mime+6, "png");
|
||||||
}
|
}
|
||||||
else if( strcmp(icon, "sm.jpg") == 0 )
|
else if( strcmp(icon, "sm.jpg") == 0 )
|
||||||
{
|
{
|
||||||
DPRINTF(E_DEBUG, L_HTTP, "Sending small JPEG icon\n");
|
DPRINTF(E_DEBUG, L_HTTP, "Sending small JPEG icon\n");
|
||||||
data = (char *)jpeg_sm;
|
data = (char *)jpeg_sm;
|
||||||
size = sizeof(jpeg_sm)-1;
|
size = sizeof(jpeg_sm)-1;
|
||||||
strcpy(mime, "image/jpeg");
|
strcpy(mime+6, "jpeg");
|
||||||
}
|
}
|
||||||
else if( strcmp(icon, "lrg.jpg") == 0 )
|
else if( strcmp(icon, "lrg.jpg") == 0 )
|
||||||
{
|
{
|
||||||
DPRINTF(E_DEBUG, L_HTTP, "Sending large JPEG icon\n");
|
DPRINTF(E_DEBUG, L_HTTP, "Sending large JPEG icon\n");
|
||||||
data = (char *)jpeg_lrg;
|
data = (char *)jpeg_lrg;
|
||||||
size = sizeof(jpeg_lrg)-1;
|
size = sizeof(jpeg_lrg)-1;
|
||||||
strcpy(mime, "image/jpeg");
|
strcpy(mime+6, "jpeg");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1229,9 +1226,8 @@ SendResp_icon(struct upnphttp * h, char * icon)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
||||||
ret = asprintf(&header, "HTTP/1.1 200 OK\r\n"
|
ret = snprintf(header, sizeof(header), "HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Type: %s\r\n"
|
"Content-Type: %s\r\n"
|
||||||
"Content-Length: %d\r\n"
|
"Content-Length: %d\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
@ -1239,28 +1235,24 @@ SendResp_icon(struct upnphttp * h, char * icon)
|
|||||||
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
|
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
|
||||||
mime, size, date);
|
mime, size, date);
|
||||||
|
|
||||||
if( (send_data(h, header, ret, MSG_MORE) == 0) && (h->req_command != EHead) )
|
if( send_data(h, header, ret, MSG_MORE) == 0 )
|
||||||
{
|
{
|
||||||
|
if( h->req_command != EHead )
|
||||||
send_data(h, data, size, 0);
|
send_data(h, data, size, 0);
|
||||||
}
|
}
|
||||||
free(header);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SendResp_albumArt(struct upnphttp * h, char * object)
|
SendResp_albumArt(struct upnphttp * h, char * object)
|
||||||
{
|
{
|
||||||
char header[1500];
|
char header[512];
|
||||||
char sql_buf[256];
|
|
||||||
char **result;
|
|
||||||
int rows = 0;
|
|
||||||
char *path;
|
char *path;
|
||||||
char *dash;
|
char *dash;
|
||||||
char date[30];
|
char date[30];
|
||||||
time_t curtime = time(NULL);
|
time_t curtime = time(NULL);
|
||||||
off_t offset = 0, size;
|
off_t size;
|
||||||
int sendfh;
|
int fd;
|
||||||
|
int ret;
|
||||||
memset(header, 0, 1500);
|
|
||||||
|
|
||||||
if( h->reqflags & FLAG_XFERSTREAMING || h->reqflags & FLAG_RANGE )
|
if( h->reqflags & FLAG_XFERSTREAMING || h->reqflags & FLAG_RANGE )
|
||||||
{
|
{
|
||||||
@ -1272,30 +1264,30 @@ SendResp_albumArt(struct upnphttp * h, char * object)
|
|||||||
dash = strchr(object, '-');
|
dash = strchr(object, '-');
|
||||||
if( dash )
|
if( dash )
|
||||||
*dash = '\0';
|
*dash = '\0';
|
||||||
sprintf(sql_buf, "SELECT PATH from ALBUM_ART where ID = %s", object);
|
|
||||||
sql_get_table(db, sql_buf, &result, &rows, NULL);
|
path = sql_get_text_field(db, "SELECT PATH from ALBUM_ART where ID = '%s'", object);
|
||||||
if( !rows )
|
if( !path )
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_HTTP, "ALBUM_ART ID %s not found, responding ERROR 404\n", object);
|
DPRINTF(E_WARN, L_HTTP, "ALBUM_ART ID %s not found, responding ERROR 404\n", object);
|
||||||
Send404(h);
|
Send404(h);
|
||||||
goto error;
|
return;
|
||||||
}
|
}
|
||||||
path = result[1];
|
|
||||||
DPRINTF(E_INFO, L_HTTP, "Serving album art ID: %s [%s]\n", object, path);
|
DPRINTF(E_INFO, L_HTTP, "Serving album art ID: %s [%s]\n", object, path);
|
||||||
|
|
||||||
if( access(path, F_OK) == 0 )
|
|
||||||
{
|
|
||||||
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
||||||
|
|
||||||
sendfh = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if( sendfh < 0 ) {
|
if( fd < 0 ) {
|
||||||
DPRINTF(E_ERROR, L_HTTP, "Error opening %s\n", path);
|
DPRINTF(E_ERROR, L_HTTP, "Error opening %s\n", path);
|
||||||
goto error;
|
sqlite3_free(path);
|
||||||
|
Send404(h);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
size = lseek(sendfh, 0, SEEK_END);
|
sqlite3_free(path);
|
||||||
lseek(sendfh, 0, SEEK_SET);
|
size = lseek(fd, 0, SEEK_END);
|
||||||
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
|
||||||
sprintf(header, "HTTP/1.1 200 OK\r\n"
|
ret = snprintf(header, sizeof(header), "HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Type: image/jpeg\r\n"
|
"Content-Type: image/jpeg\r\n"
|
||||||
"Content-Length: %jd\r\n"
|
"Content-Length: %jd\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
@ -1303,38 +1295,28 @@ SendResp_albumArt(struct upnphttp * h, char * object)
|
|||||||
"EXT:\r\n"
|
"EXT:\r\n"
|
||||||
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
|
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
|
||||||
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n"
|
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n"
|
||||||
"Server: " MINIDLNA_SERVER_STRING "\r\n",
|
"Server: " MINIDLNA_SERVER_STRING "\r\n"
|
||||||
size, date);
|
"transferMode.dlna.org: %s\r\n\r\n",
|
||||||
|
(intmax_t)size, date,
|
||||||
|
(h->reqflags & FLAG_XFERBACKGROUND) ? "Background" : "Interactive");
|
||||||
|
|
||||||
if( h->reqflags & FLAG_XFERBACKGROUND )
|
if( send_data(h, header, ret, MSG_MORE) == 0 )
|
||||||
{
|
{
|
||||||
strcat(header, "transferMode.dlna.org: Background\r\n\r\n");
|
if( h->req_command != EHead )
|
||||||
|
send_file(h, fd, 0, size-1);
|
||||||
}
|
}
|
||||||
else //if( h->reqflags & FLAG_XFERINTERACTIVE )
|
close(fd);
|
||||||
{
|
|
||||||
strcat(header, "transferMode.dlna.org: Interactive\r\n\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if( (send_data(h, header, strlen(header), MSG_MORE) == 0) && (h->req_command != EHead) && (sendfh > 0) )
|
|
||||||
{
|
|
||||||
send_file(h, sendfh, offset, size);
|
|
||||||
}
|
|
||||||
close(sendfh);
|
|
||||||
}
|
|
||||||
error:
|
|
||||||
sqlite3_free_table(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SendResp_caption(struct upnphttp * h, char * object)
|
SendResp_caption(struct upnphttp * h, char * object)
|
||||||
{
|
{
|
||||||
char header[1500];
|
char header[512];
|
||||||
char *path;
|
char *path;
|
||||||
char date[30];
|
char date[30];
|
||||||
time_t curtime = time(NULL);
|
time_t curtime = time(NULL);
|
||||||
off_t offset = 0, size;
|
off_t size;
|
||||||
int sendfh, ret;
|
int fd, ret;
|
||||||
|
|
||||||
strip_ext(object);
|
strip_ext(object);
|
||||||
path = sql_get_text_field(db, "SELECT PATH from CAPTIONS where ID = %s", object);
|
path = sql_get_text_field(db, "SELECT PATH from CAPTIONS where ID = %s", object);
|
||||||
@ -1346,17 +1328,17 @@ SendResp_caption(struct upnphttp * h, char * object)
|
|||||||
}
|
}
|
||||||
DPRINTF(E_INFO, L_HTTP, "Serving caption ID: %s [%s]\n", object, path);
|
DPRINTF(E_INFO, L_HTTP, "Serving caption ID: %s [%s]\n", object, path);
|
||||||
|
|
||||||
if( access(path, F_OK) != 0 )
|
fd = open(path, O_RDONLY);
|
||||||
goto error;
|
if( fd < 0 ) {
|
||||||
|
|
||||||
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
|
||||||
sendfh = open(path, O_RDONLY);
|
|
||||||
if( sendfh < 0 ) {
|
|
||||||
DPRINTF(E_ERROR, L_HTTP, "Error opening %s\n", path);
|
DPRINTF(E_ERROR, L_HTTP, "Error opening %s\n", path);
|
||||||
goto error;
|
sqlite3_free(path);
|
||||||
|
Send404(h);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
size = lseek(sendfh, 0, SEEK_END);
|
sqlite3_free(path);
|
||||||
lseek(sendfh, 0, SEEK_SET);
|
size = lseek(fd, 0, SEEK_END);
|
||||||
|
lseek(fd, 0, SEEK_SET);
|
||||||
|
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
||||||
|
|
||||||
ret = snprintf(header, sizeof(header), "HTTP/1.1 200 OK\r\n"
|
ret = snprintf(header, sizeof(header), "HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Type: smi/caption\r\n"
|
"Content-Type: smi/caption\r\n"
|
||||||
@ -1367,31 +1349,25 @@ SendResp_caption(struct upnphttp * h, char * object)
|
|||||||
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
|
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
|
||||||
size, date);
|
size, date);
|
||||||
|
|
||||||
if( (send_data(h, header, ret, MSG_MORE) == 0) && (h->req_command != EHead) && (sendfh > 0) )
|
if( send_data(h, header, ret, MSG_MORE) == 0 )
|
||||||
{
|
{
|
||||||
send_file(h, sendfh, offset, size);
|
if( h->req_command != EHead )
|
||||||
|
send_file(h, fd, 0, size);
|
||||||
}
|
}
|
||||||
close(sendfh);
|
close(fd);
|
||||||
|
|
||||||
error:
|
|
||||||
sqlite3_free(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SendResp_thumbnail(struct upnphttp * h, char * object)
|
SendResp_thumbnail(struct upnphttp * h, char * object)
|
||||||
{
|
{
|
||||||
char header[1500];
|
char header[512];
|
||||||
char sql_buf[256];
|
|
||||||
char **result;
|
|
||||||
int rows = 0;
|
|
||||||
char *path;
|
char *path;
|
||||||
char date[30];
|
char date[30];
|
||||||
time_t curtime = time(NULL);
|
time_t curtime = time(NULL);
|
||||||
|
int ret;
|
||||||
ExifData *ed;
|
ExifData *ed;
|
||||||
ExifLoader *l;
|
ExifLoader *l;
|
||||||
|
|
||||||
memset(header, 0, 1500);
|
|
||||||
|
|
||||||
if( h->reqflags & FLAG_XFERSTREAMING || h->reqflags & FLAG_RANGE )
|
if( h->reqflags & FLAG_XFERSTREAMING || h->reqflags & FLAG_RANGE )
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_HTTP, "Client tried to specify transferMode as Streaming with an image!\n");
|
DPRINTF(E_WARN, L_HTTP, "Client tried to specify transferMode as Streaming with an image!\n");
|
||||||
@ -1400,34 +1376,37 @@ SendResp_thumbnail(struct upnphttp * h, char * object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
strip_ext(object);
|
strip_ext(object);
|
||||||
sprintf(sql_buf, "SELECT PATH from DETAILS where ID = '%s'", object);
|
path = sql_get_text_field(db, "SELECT PATH from DETAILS where ID = '%s'", object);
|
||||||
sql_get_table(db, sql_buf, &result, &rows, NULL);
|
if( !path )
|
||||||
if( !rows )
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_HTTP, "%s not found, responding ERROR 404\n", object);
|
DPRINTF(E_WARN, L_HTTP, "DETAIL ID %s not found, responding ERROR 404\n", object);
|
||||||
Send404(h);
|
Send404(h);
|
||||||
goto error;
|
return;
|
||||||
}
|
}
|
||||||
path = result[1];
|
|
||||||
DPRINTF(E_INFO, L_HTTP, "Serving thumbnail for ObjectId: %s [%s]\n", object, path);
|
DPRINTF(E_INFO, L_HTTP, "Serving thumbnail for ObjectId: %s [%s]\n", object, path);
|
||||||
|
|
||||||
if( access(path, F_OK) == 0 )
|
if( access(path, F_OK) != 0 )
|
||||||
{
|
{
|
||||||
|
DPRINTF(E_ERROR, L_HTTP, "Error accessing %s\n", path);
|
||||||
|
sqlite3_free(path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
||||||
|
|
||||||
l = exif_loader_new();
|
l = exif_loader_new();
|
||||||
exif_loader_write_file(l, path);
|
exif_loader_write_file(l, path);
|
||||||
ed = exif_loader_get_data(l);
|
ed = exif_loader_get_data(l);
|
||||||
exif_loader_unref(l);
|
exif_loader_unref(l);
|
||||||
|
sqlite3_free(path);
|
||||||
|
|
||||||
if( !ed || !ed->size )
|
if( !ed || !ed->size )
|
||||||
{
|
{
|
||||||
Send404(h);
|
Send404(h);
|
||||||
if( ed )
|
if( ed )
|
||||||
exif_data_unref(ed);
|
exif_data_unref(ed);
|
||||||
goto error;
|
return;
|
||||||
}
|
}
|
||||||
sprintf(header, "HTTP/1.1 200 OK\r\n"
|
ret = snprintf(header, sizeof(header), "HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Type: image/jpeg\r\n"
|
"Content-Type: image/jpeg\r\n"
|
||||||
"Content-Length: %d\r\n"
|
"Content-Length: %d\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
@ -1435,34 +1414,26 @@ SendResp_thumbnail(struct upnphttp * h, char * object)
|
|||||||
"EXT:\r\n"
|
"EXT:\r\n"
|
||||||
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
|
"realTimeInfo.dlna.org: DLNA.ORG_TLAG=*\r\n"
|
||||||
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n"
|
"contentFeatures.dlna.org: DLNA.ORG_PN=JPEG_TN\r\n"
|
||||||
"Server: " MINIDLNA_SERVER_STRING "\r\n",
|
"Server: " MINIDLNA_SERVER_STRING "\r\n"
|
||||||
ed->size, date);
|
"transferMode.dlna.org: %s\r\n\r\n",
|
||||||
|
ed->size, date,
|
||||||
|
(h->reqflags & FLAG_XFERBACKGROUND) ? "Background" : "Interactive");
|
||||||
|
|
||||||
if( h->reqflags & FLAG_XFERBACKGROUND )
|
if( send_data(h, header, ret, MSG_MORE) == 0 )
|
||||||
{
|
|
||||||
strcat(header, "transferMode.dlna.org: Background\r\n\r\n");
|
|
||||||
}
|
|
||||||
else //if( h->reqflags & FLAG_XFERINTERACTIVE )
|
|
||||||
{
|
|
||||||
strcat(header, "transferMode.dlna.org: Interactive\r\n\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if( (send_data(h, header, strlen(header), MSG_MORE) == 0) && (h->req_command != EHead) )
|
|
||||||
{
|
{
|
||||||
|
if( h->req_command != EHead )
|
||||||
send_data(h, (char *)ed->data, ed->size, 0);
|
send_data(h, (char *)ed->data, ed->size, 0);
|
||||||
}
|
}
|
||||||
exif_data_unref(ed);
|
exif_data_unref(ed);
|
||||||
}
|
|
||||||
CloseSocket_upnphttp(h);
|
CloseSocket_upnphttp(h);
|
||||||
error:
|
|
||||||
sqlite3_free_table(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SendResp_resizedimg(struct upnphttp * h, char * object)
|
SendResp_resizedimg(struct upnphttp * h, char * object)
|
||||||
{
|
{
|
||||||
char header[1500];
|
char header[512];
|
||||||
char str_buf[256];
|
char str_buf[256];
|
||||||
|
struct string_s str;
|
||||||
char **result;
|
char **result;
|
||||||
char date[30];
|
char date[30];
|
||||||
char dlna_pn[4];
|
char dlna_pn[4];
|
||||||
@ -1478,7 +1449,7 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
char *pixelshape=NULL;
|
char *pixelshape=NULL;
|
||||||
int rotation; */
|
int rotation; */
|
||||||
sqlite_int64 id;
|
sqlite_int64 id;
|
||||||
int rows=0, chunked=0, ret;
|
int rows=0, chunked, ret;
|
||||||
#ifdef __sparc__
|
#ifdef __sparc__
|
||||||
char *tn;
|
char *tn;
|
||||||
ExifData *ed;
|
ExifData *ed;
|
||||||
@ -1521,9 +1492,9 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
}
|
}
|
||||||
while( item != NULL )
|
while( item != NULL )
|
||||||
{
|
{
|
||||||
#ifdef TIVO_SUPPORT
|
#ifdef TIVO_SUPPORT
|
||||||
decodeString(item, 1);
|
decodeString(item, 1);
|
||||||
#endif
|
#endif
|
||||||
val = item;
|
val = item;
|
||||||
key = strsep(&val, "=");
|
key = strsep(&val, "=");
|
||||||
DPRINTF(E_DEBUG, L_GENERAL, "%s: %s\n", key, val);
|
DPRINTF(E_DEBUG, L_GENERAL, "%s: %s\n", key, val);
|
||||||
@ -1581,7 +1552,12 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
scale = 2;
|
scale = 2;
|
||||||
|
|
||||||
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
strftime(date, 30,"%a, %d %b %Y %H:%M:%S GMT" , gmtime(&curtime));
|
||||||
snprintf(header, sizeof(header)-100, "HTTP/1.1 200 OK\r\n"
|
|
||||||
|
str.data = header;
|
||||||
|
str.size = sizeof(header);
|
||||||
|
str.off = 0;
|
||||||
|
|
||||||
|
strcatf(&str, "HTTP/1.1 200 OK\r\n"
|
||||||
"Content-Type: image/jpeg\r\n"
|
"Content-Type: image/jpeg\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
"Date: %s\r\n"
|
"Date: %s\r\n"
|
||||||
@ -1592,11 +1568,11 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
date, dlna_pn);
|
date, dlna_pn);
|
||||||
if( h->reqflags & FLAG_XFERINTERACTIVE )
|
if( h->reqflags & FLAG_XFERINTERACTIVE )
|
||||||
{
|
{
|
||||||
strcat(header, "transferMode.dlna.org: Interactive\r\n");
|
strcatf(&str, "transferMode.dlna.org: Interactive\r\n");
|
||||||
}
|
}
|
||||||
else if( h->reqflags & FLAG_XFERBACKGROUND )
|
else if( h->reqflags & FLAG_XFERBACKGROUND )
|
||||||
{
|
{
|
||||||
strcat(header, "transferMode.dlna.org: Background\r\n");
|
strcatf(&str, "transferMode.dlna.org: Background\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resizing from a thumbnail is much faster than from a large image */
|
/* Resizing from a thumbnail is much faster than from a large image */
|
||||||
@ -1624,12 +1600,13 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
#endif
|
#endif
|
||||||
if( strcmp(h->HttpVer, "HTTP/1.0") == 0 )
|
if( strcmp(h->HttpVer, "HTTP/1.0") == 0 )
|
||||||
{
|
{
|
||||||
|
chunked = 0;
|
||||||
imsrc = image_new_from_jpeg(file_path, 1, NULL, 0, scale);
|
imsrc = image_new_from_jpeg(file_path, 1, NULL, 0, scale);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chunked = 1;
|
chunked = 1;
|
||||||
strcat(header, "Transfer-Encoding: chunked\r\n\r\n");
|
strcatf(&str, "Transfer-Encoding: chunked\r\n\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !chunked )
|
if( !chunked )
|
||||||
@ -1644,11 +1621,10 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
imdst = image_resize(imsrc, dstw, dsth);
|
imdst = image_resize(imsrc, dstw, dsth);
|
||||||
data = image_save_to_jpeg_buf(imdst, &size);
|
data = image_save_to_jpeg_buf(imdst, &size);
|
||||||
|
|
||||||
sprintf(str_buf, "Content-Length: %d\r\n\r\n", size);
|
strcatf(&str, "Content-Length: %d\r\n\r\n", size);
|
||||||
strcat(header, str_buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (send_data(h, header, strlen(header), 0) == 0) && (h->req_command != EHead) )
|
if( (send_data(h, str.data, str.off, 0) == 0) && (h->req_command != EHead) )
|
||||||
{
|
{
|
||||||
if( chunked )
|
if( chunked )
|
||||||
{
|
{
|
||||||
@ -1688,8 +1664,8 @@ SendResp_resizedimg(struct upnphttp * h, char * object)
|
|||||||
void
|
void
|
||||||
SendResp_dlnafile(struct upnphttp * h, char * object)
|
SendResp_dlnafile(struct upnphttp * h, char * object)
|
||||||
{
|
{
|
||||||
char header[1500];
|
char header[1024];
|
||||||
char hdr_buf[512];
|
struct string_s str;
|
||||||
char sql_buf[256];
|
char sql_buf[256];
|
||||||
char **result;
|
char **result;
|
||||||
int rows, ret;
|
int rows, ret;
|
||||||
@ -1796,17 +1772,26 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
|
|||||||
sendfh = open(last_file.path, O_RDONLY);
|
sendfh = open(last_file.path, O_RDONLY);
|
||||||
if( sendfh < 0 ) {
|
if( sendfh < 0 ) {
|
||||||
DPRINTF(E_ERROR, L_HTTP, "Error opening %s\n", last_file.path);
|
DPRINTF(E_ERROR, L_HTTP, "Error opening %s\n", last_file.path);
|
||||||
|
Send404(h);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
size = lseek(sendfh, 0, SEEK_END);
|
size = lseek(sendfh, 0, SEEK_END);
|
||||||
lseek(sendfh, 0, SEEK_SET);
|
lseek(sendfh, 0, SEEK_SET);
|
||||||
|
|
||||||
sprintf(header, "HTTP/1.1 20%c OK\r\n"
|
str.data = header;
|
||||||
"Content-Type: %s\r\n", (h->reqflags & FLAG_RANGE ? '6' : '0'), last_file.mime);
|
str.size = sizeof(header);
|
||||||
|
str.off = 0;
|
||||||
|
|
||||||
|
strcatf(&str, "HTTP/1.1 20%c OK\r\n"
|
||||||
|
"Content-Type: %s\r\n",
|
||||||
|
(h->reqflags & FLAG_RANGE ? '6' : '0'),
|
||||||
|
last_file.mime);
|
||||||
if( h->reqflags & FLAG_RANGE )
|
if( h->reqflags & FLAG_RANGE )
|
||||||
{
|
{
|
||||||
if( !h->req_RangeEnd )
|
if( !h->req_RangeEnd || h->req_RangeEnd == size )
|
||||||
h->req_RangeEnd = size;
|
{
|
||||||
|
h->req_RangeEnd = size - 1;
|
||||||
|
}
|
||||||
if( (h->req_RangeStart > h->req_RangeEnd) || (h->req_RangeStart < 0) )
|
if( (h->req_RangeStart > h->req_RangeEnd) || (h->req_RangeStart < 0) )
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_HTTP, "Specified range was invalid!\n");
|
DPRINTF(E_WARN, L_HTTP, "Specified range was invalid!\n");
|
||||||
@ -1814,7 +1799,7 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
|
|||||||
close(sendfh);
|
close(sendfh);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if( h->req_RangeEnd > size )
|
if( h->req_RangeEnd >= size )
|
||||||
{
|
{
|
||||||
DPRINTF(E_WARN, L_HTTP, "Specified range was outside file boundaries!\n");
|
DPRINTF(E_WARN, L_HTTP, "Specified range was outside file boundaries!\n");
|
||||||
Send416(h);
|
Send416(h);
|
||||||
@ -1822,49 +1807,38 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( h->req_RangeEnd < size )
|
|
||||||
{
|
|
||||||
total = h->req_RangeEnd - h->req_RangeStart + 1;
|
total = h->req_RangeEnd - h->req_RangeStart + 1;
|
||||||
sprintf(hdr_buf, "Content-Length: %jd\r\n"
|
strcatf(&str, "Content-Length: %jd\r\n"
|
||||||
"Content-Range: bytes %jd-%jd/%jd\r\n",
|
"Content-Range: bytes %jd-%jd/%jd\r\n",
|
||||||
total, h->req_RangeStart, h->req_RangeEnd, size);
|
(intmax_t)total, (intmax_t)h->req_RangeStart,
|
||||||
|
(intmax_t)h->req_RangeEnd, (intmax_t)size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
h->req_RangeEnd = size;
|
h->req_RangeEnd = size - 1;
|
||||||
total = size - h->req_RangeStart;
|
|
||||||
sprintf(hdr_buf, "Content-Length: %jd\r\n"
|
|
||||||
"Content-Range: bytes %jd-%jd/%jd\r\n",
|
|
||||||
total, h->req_RangeStart, size-1, size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
h->req_RangeEnd = size;
|
|
||||||
total = size;
|
total = size;
|
||||||
sprintf(hdr_buf, "Content-Length: %jd\r\n", total);
|
strcatf(&str, "Content-Length: %jd\r\n", (intmax_t)total);
|
||||||
}
|
}
|
||||||
strcat(header, hdr_buf);
|
|
||||||
|
|
||||||
if( h->reqflags & FLAG_XFERSTREAMING )
|
if( h->reqflags & FLAG_XFERSTREAMING )
|
||||||
{
|
{
|
||||||
strcat(header, "transferMode.dlna.org: Streaming\r\n");
|
strcatf(&str, "transferMode.dlna.org: Streaming\r\n");
|
||||||
}
|
}
|
||||||
else if( h->reqflags & FLAG_XFERBACKGROUND )
|
else if( h->reqflags & FLAG_XFERBACKGROUND )
|
||||||
{
|
{
|
||||||
if( strncmp(last_file.mime, "image", 5) == 0 )
|
if( strncmp(last_file.mime, "image", 5) == 0 )
|
||||||
strcat(header, "transferMode.dlna.org: Background\r\n");
|
strcatf(&str, "transferMode.dlna.org: Background\r\n");
|
||||||
}
|
}
|
||||||
else //if( h->reqflags & FLAG_XFERINTERACTIVE )
|
else //if( h->reqflags & FLAG_XFERINTERACTIVE )
|
||||||
{
|
{
|
||||||
if( (strncmp(last_file.mime, "video", 5) == 0) ||
|
if( (strncmp(last_file.mime, "video", 5) == 0) ||
|
||||||
(strncmp(last_file.mime, "audio", 5) == 0) )
|
(strncmp(last_file.mime, "audio", 5) == 0) )
|
||||||
{
|
{
|
||||||
strcat(header, "transferMode.dlna.org: Streaming\r\n");
|
strcatf(&str, "transferMode.dlna.org: Streaming\r\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcat(header, "transferMode.dlna.org: Interactive\r\n");
|
strcatf(&str, "transferMode.dlna.org: Interactive\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1872,13 +1846,12 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
|
|||||||
{
|
{
|
||||||
if( sql_get_int_field(db, "SELECT ID from CAPTIONS where ID = '%lld'", id) > 0 )
|
if( sql_get_int_field(db, "SELECT ID from CAPTIONS where ID = '%lld'", id) > 0 )
|
||||||
{
|
{
|
||||||
sprintf(hdr_buf, "CaptionInfo.sec: http://%s:%d/Captions/%lld.srt\r\n",
|
strcatf(&str, "CaptionInfo.sec: http://%s:%d/Captions/%lld.srt\r\n",
|
||||||
lan_addr[0].str, runtime_vars.port, id);
|
lan_addr[0].str, runtime_vars.port, id);
|
||||||
strcat(header, hdr_buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(hdr_buf, "Accept-Ranges: bytes\r\n"
|
strcatf(&str, "Accept-Ranges: bytes\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
"Date: %s\r\n"
|
"Date: %s\r\n"
|
||||||
"EXT:\r\n"
|
"EXT:\r\n"
|
||||||
@ -1886,10 +1859,10 @@ SendResp_dlnafile(struct upnphttp * h, char * object)
|
|||||||
"contentFeatures.dlna.org: %s\r\n"
|
"contentFeatures.dlna.org: %s\r\n"
|
||||||
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
|
"Server: " MINIDLNA_SERVER_STRING "\r\n\r\n",
|
||||||
date, last_file.dlna);
|
date, last_file.dlna);
|
||||||
strcat(header, hdr_buf);
|
|
||||||
|
|
||||||
if( (send_data(h, header, strlen(header), MSG_MORE) == 0) && (h->req_command != EHead) && (sendfh > 0) )
|
if( send_data(h, str.data, str.off, MSG_MORE) == 0 )
|
||||||
{
|
{
|
||||||
|
if( h->req_command != EHead )
|
||||||
send_file(h, sendfh, offset, h->req_RangeEnd);
|
send_file(h, sendfh, offset, h->req_RangeEnd);
|
||||||
}
|
}
|
||||||
close(sendfh);
|
close(sendfh);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user