Template object for FileInfo.
This commit is contained in:
parent
86a7ec499a
commit
2616d4c76a
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef FILEINFO_H
|
#ifndef FILEINFO_H
|
||||||
#define FILEINFO_H
|
#define FILEINFO_H
|
||||||
|
|
||||||
@ -9,75 +8,25 @@
|
|||||||
*
|
*
|
||||||
* \brief UpnpFileInfo object declararion.
|
* \brief UpnpFileInfo object declararion.
|
||||||
*
|
*
|
||||||
|
* Detailed description of this class should go here
|
||||||
|
*
|
||||||
* \author Marcelo Roberto Jimenez
|
* \author Marcelo Roberto Jimenez
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*! Detailed description of this class should go here */
|
|
||||||
typedef struct s_UpnpFileInfo UpnpFileInfo;
|
|
||||||
|
|
||||||
|
|
||||||
#include "ixml.h" /* for DOMString */
|
|
||||||
#include "UpnpGlobal.h" /* for EXPORT_SPEC */
|
|
||||||
|
|
||||||
|
|
||||||
#include <sys/types.h> /* for off_t */
|
#include <sys/types.h> /* for off_t */
|
||||||
#include <time.h> /* for time_t */
|
#include <time.h> /* for time_t */
|
||||||
|
|
||||||
|
#define CLASS UpnpFileInfo
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#define EXPAND_CLASS_MEMBERS(CLASS) \
|
||||||
extern "C" {
|
EXPAND_CLASS_MEMBER_INT(CLASS, FileLength, off_t) \
|
||||||
#endif /* __cplusplus */
|
EXPAND_CLASS_MEMBER_INT(CLASS, LastModified, time_t) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, IsDirectory, int) \
|
||||||
|
EXPAND_CLASS_MEMBER_INT(CLASS, IsReadable, int) \
|
||||||
|
EXPAND_CLASS_MEMBER_DOMSTRING(CLASS, ContentType) \
|
||||||
|
EXPAND_CLASS_MEMBER_DOMSTRING(CLASS, ExtraHeaders) \
|
||||||
|
|
||||||
|
#include "TemplateInclude.h"
|
||||||
/*! Constructor */
|
|
||||||
EXPORT_SPEC UpnpFileInfo *UpnpFileInfo_new();
|
|
||||||
|
|
||||||
/*! Destructor */
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_delete(UpnpFileInfo *p);
|
|
||||||
|
|
||||||
/*! Copy Constructor */
|
|
||||||
EXPORT_SPEC UpnpFileInfo *UpnpFileInfo_dup(const UpnpFileInfo *p);
|
|
||||||
|
|
||||||
/*! Assignment operator */
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_assign(UpnpFileInfo *p, const UpnpFileInfo *q);
|
|
||||||
|
|
||||||
/*! The length of the file. A length less than 0 indicates the size
|
|
||||||
* is unknown, and data will be sent until 0 bytes are returned from
|
|
||||||
* a read call. */
|
|
||||||
EXPORT_SPEC off_t UpnpFileInfo_get_FileLength(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_set_FileLength(UpnpFileInfo *p, off_t l);
|
|
||||||
|
|
||||||
/*! The time at which the contents of the file was modified;
|
|
||||||
* The time system is always local (not GMT). */
|
|
||||||
EXPORT_SPEC const time_t *UpnpFileInfo_get_LastModified(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_set_LastModified(UpnpFileInfo *p, const time_t *t);
|
|
||||||
|
|
||||||
/*! If the file is a directory, \b is_directory contains
|
|
||||||
* a non-zero value. For a regular file, it should be 0. */
|
|
||||||
EXPORT_SPEC int UpnpFileInfo_get_IsDirectory(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_set_IsDirectory(UpnpFileInfo *p, int b);
|
|
||||||
|
|
||||||
/*! If the file or directory is readable, this contains
|
|
||||||
* a non-zero value. If unreadable, it should be set to 0. */
|
|
||||||
EXPORT_SPEC int UpnpFileInfo_get_IsReadable(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_set_IsReadable(UpnpFileInfo *p, int b);
|
|
||||||
|
|
||||||
/*! The content type of the file. */
|
|
||||||
EXPORT_SPEC const DOMString UpnpFileInfo_get_ContentType(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC const char *UpnpFileInfo_get_ContentType_cstr(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_set_ContentType(UpnpFileInfo *p, const DOMString s);
|
|
||||||
|
|
||||||
/*! Additional HTTP headers to return. Each header line should be
|
|
||||||
* followed by "\r\n". */
|
|
||||||
EXPORT_SPEC const DOMString UpnpFileInfo_get_ExtraHeaders(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC const char *UpnpFileInfo_get_ExtraHeaders_cstr(const UpnpFileInfo *p);
|
|
||||||
EXPORT_SPEC void UpnpFileInfo_set_ExtraHeaders(UpnpFileInfo *p, const DOMString s);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FILEINFO_H */
|
#endif /* FILEINFO_H */
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \file
|
* \file
|
||||||
*
|
*
|
||||||
@ -8,172 +7,8 @@
|
|||||||
* \author Marcelo Roberto Jimenez
|
* \author Marcelo Roberto Jimenez
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#define TEMPLATE_GENERATE_SOURCE
|
||||||
#include "FileInfo.h"
|
#include "FileInfo.h"
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h> /* for calloc(), free() */
|
|
||||||
#include <string.h> /* for strlen(), strdup() */
|
|
||||||
|
|
||||||
|
|
||||||
struct SUpnpFileInfo
|
|
||||||
{
|
|
||||||
off_t m_fileLength;
|
|
||||||
time_t m_lastModified;
|
|
||||||
int m_isDirectory;
|
|
||||||
int m_isReadable;
|
|
||||||
DOMString m_contentType;
|
|
||||||
DOMString m_extraHeaders;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
UpnpFileInfo *UpnpFileInfo_new()
|
|
||||||
{
|
|
||||||
struct SUpnpFileInfo *p = calloc(1, sizeof (struct SUpnpFileInfo));
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
p->m_fileLength = 0;
|
|
||||||
p->m_lastModified = 0;
|
|
||||||
p->m_isDirectory = 0;
|
|
||||||
p->m_isReadable = 0;
|
|
||||||
p->m_contentType = NULL;
|
|
||||||
p->m_extraHeaders = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (UpnpFileInfo *)p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_delete(UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
struct SUpnpFileInfo *q = (struct SUpnpFileInfo *)p;
|
|
||||||
|
|
||||||
if (!q) return;
|
|
||||||
|
|
||||||
q->m_fileLength = 0;
|
|
||||||
|
|
||||||
q->m_lastModified = 0;
|
|
||||||
|
|
||||||
q->m_isDirectory = 0;
|
|
||||||
|
|
||||||
q->m_isReadable = 0;
|
|
||||||
|
|
||||||
ixmlFreeDOMString(q->m_contentType);
|
|
||||||
q->m_contentType = NULL;
|
|
||||||
|
|
||||||
ixmlFreeDOMString(q->m_extraHeaders);
|
|
||||||
q->m_extraHeaders = NULL;
|
|
||||||
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
UpnpFileInfo *UpnpFileInfo_dup(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
UpnpFileInfo *q = UpnpFileInfo_new();
|
|
||||||
|
|
||||||
UpnpFileInfo_assign(q, p);
|
|
||||||
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_assign(UpnpFileInfo *p, const UpnpFileInfo *q)
|
|
||||||
{
|
|
||||||
if (p != q) {
|
|
||||||
UpnpFileInfo_set_FileLength(p, UpnpFileInfo_get_FileLength(q));
|
|
||||||
UpnpFileInfo_set_LastModified(p, UpnpFileInfo_get_LastModified(q));
|
|
||||||
UpnpFileInfo_set_IsDirectory(p, UpnpFileInfo_get_IsDirectory(q));
|
|
||||||
UpnpFileInfo_set_IsReadable(p, UpnpFileInfo_get_IsReadable(q));
|
|
||||||
UpnpFileInfo_set_ContentType(p, UpnpFileInfo_get_ContentType(q));
|
|
||||||
UpnpFileInfo_set_ExtraHeaders(p, UpnpFileInfo_get_ExtraHeaders(q));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
off_t UpnpFileInfo_get_FileLength(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return ((struct SUpnpFileInfo *)p)->m_fileLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_set_FileLength(UpnpFileInfo *p, off_t l)
|
|
||||||
{
|
|
||||||
((struct SUpnpFileInfo *)p)->m_fileLength = l;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const time_t *UpnpFileInfo_get_LastModified(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return &((struct SUpnpFileInfo *)p)->m_lastModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_set_LastModified(UpnpFileInfo *p, const time_t *t)
|
|
||||||
{
|
|
||||||
((struct SUpnpFileInfo *)p)->m_lastModified = *t;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int UpnpFileInfo_get_IsDirectory(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return ((struct SUpnpFileInfo *)p)->m_isDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_set_IsDirectory(UpnpFileInfo *p, int b)
|
|
||||||
{
|
|
||||||
((struct SUpnpFileInfo *)p)->m_isDirectory = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int UpnpFileInfo_get_IsReadable(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return ((struct SUpnpFileInfo *)p)->m_isReadable;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_set_IsReadable(UpnpFileInfo *p, int b)
|
|
||||||
{
|
|
||||||
((struct SUpnpFileInfo *)p)->m_isReadable = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const DOMString UpnpFileInfo_get_ContentType(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return ((struct SUpnpFileInfo *)p)->m_contentType;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *UpnpFileInfo_get_ContentType_cstr(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return (const char *)UpnpFileInfo_get_ContentType(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_set_ContentType(UpnpFileInfo *p, const DOMString s)
|
|
||||||
{
|
|
||||||
ixmlFreeDOMString(((struct SUpnpFileInfo *)p)->m_contentType);
|
|
||||||
((struct SUpnpFileInfo *)p)->m_contentType = ixmlCloneDOMString(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const DOMString UpnpFileInfo_get_ExtraHeaders(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return ((struct SUpnpFileInfo *)p)->m_extraHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *UpnpFileInfo_get_ExtraHeaders_cstr(const UpnpFileInfo *p)
|
|
||||||
{
|
|
||||||
return (const char *)UpnpFileInfo_get_ExtraHeaders(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UpnpFileInfo_set_ExtraHeaders(UpnpFileInfo *p, const DOMString s)
|
|
||||||
{
|
|
||||||
ixmlFreeDOMString(((struct SUpnpFileInfo *)p)->m_extraHeaders);
|
|
||||||
((struct SUpnpFileInfo *)p)->m_extraHeaders = ixmlCloneDOMString(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -618,6 +618,7 @@ get_file_info(
|
|||||||
struct stat s;
|
struct stat s;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
time_t aux_LastModified;
|
||||||
|
|
||||||
UpnpFileInfo_set_ContentType(info, NULL);
|
UpnpFileInfo_set_ContentType(info, NULL);
|
||||||
|
|
||||||
@ -642,15 +643,16 @@ get_file_info(
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpnpFileInfo_set_FileLength(info, s.st_size);
|
UpnpFileInfo_set_FileLength(info, s.st_size);
|
||||||
UpnpFileInfo_set_LastModified(info, &s.st_mtime);
|
UpnpFileInfo_set_LastModified(info, s.st_mtime);
|
||||||
|
|
||||||
rc = get_content_type(filename, info);
|
rc = get_content_type(filename, info);
|
||||||
|
|
||||||
|
aux_LastModified = UpnpFileInfo_get_LastModified(info);
|
||||||
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
||||||
filename,
|
filename,
|
||||||
(long long)UpnpFileInfo_get_FileLength(info),
|
(long long)UpnpFileInfo_get_FileLength(info),
|
||||||
asctime(gmtime(UpnpFileInfo_get_LastModified(info))),
|
asctime(gmtime(&aux_LastModified)),
|
||||||
UpnpFileInfo_get_IsReadable(info));
|
UpnpFileInfo_get_IsReadable(info));
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -717,11 +719,10 @@ get_alias(
|
|||||||
{
|
{
|
||||||
int cmp = strcmp(alias->name.buf, request_file);
|
int cmp = strcmp(alias->name.buf, request_file);
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
// fill up info
|
|
||||||
UpnpFileInfo_set_FileLength(info, alias->doc.length);
|
UpnpFileInfo_set_FileLength(info, alias->doc.length);
|
||||||
UpnpFileInfo_set_IsDirectory(info, FALSE);
|
UpnpFileInfo_set_IsDirectory(info, FALSE);
|
||||||
UpnpFileInfo_set_IsReadable(info, TRUE);
|
UpnpFileInfo_set_IsReadable(info, TRUE);
|
||||||
UpnpFileInfo_set_LastModified(info, &alias->last_modified);
|
UpnpFileInfo_set_LastModified(info, alias->last_modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmp == 0;
|
return cmp == 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user