[DEV] compile in C++

This commit is contained in:
Edouard DUPIN 2015-12-06 14:53:21 +01:00
parent e979a643de
commit 8ba04a5048
40 changed files with 66 additions and 131 deletions

View File

@ -63,7 +63,7 @@ buffer_append (struct buffer_t *buffer, const char *str)
if (len >= buffer->capacity)
{
buffer->capacity = MAX (len + 1, 2 * buffer->capacity);
buffer->buf = realloc (buffer->buf, buffer->capacity);
buffer->buf = (char*)realloc (buffer->buf, buffer->capacity);
}
strcat (buffer->buf, str);

View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
#include <string.h>
#include <stdio.h>
#include "ushare.h"
#include "services.h"
@ -271,7 +273,7 @@ didl_add_value (struct buffer_t *out, char *param, off_t value)
static void
didl_add_item (struct buffer_t *out, int item_id,
int parent_id, char *restricted, char *class, char *title,
int parent_id, char *restricted, char *classPointer, char *title,
char *protocol_info, off_t size, char *url, char *filter)
{
buffer_appendf (out, "<%s", DIDL_ITEM);
@ -280,7 +282,7 @@ didl_add_item (struct buffer_t *out, int item_id,
didl_add_param (out, DIDL_ITEM_RESTRICTED, restricted);
buffer_append (out, ">");
didl_add_tag (out, DIDL_ITEM_CLASS, class);
didl_add_tag (out, DIDL_ITEM_CLASS, classPointer);
didl_add_tag (out, DIDL_ITEM_TITLE, title);
if (filter_has_val (filter, DIDL_RES))
@ -305,7 +307,7 @@ didl_add_item (struct buffer_t *out, int item_id,
static void
didl_add_container (struct buffer_t *out, int id, int parent_id,
int child_count, char *restricted, char *searchable,
char *title, char *class)
char *title, char *classPointer)
{
buffer_appendf (out, "<%s", DIDL_CONTAINER);
@ -317,7 +319,7 @@ didl_add_container (struct buffer_t *out, int id, int parent_id,
didl_add_param (out, DIDL_CONTAINER_SEARCH, searchable);
buffer_append (out, ">");
didl_add_tag (out, DIDL_CONTAINER_CLASS, class);
didl_add_tag (out, DIDL_CONTAINER_CLASS, classPointer);
didl_add_tag (out, DIDL_CONTAINER_TITLE, title);
buffer_appendf (out, "</%s>", DIDL_CONTAINER);

View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
#include <string.h>
#include <stdio.h>
#include "ushare.h"
#include "services.h"
@ -84,7 +86,6 @@
static bool
cms_get_protocol_info (struct action_event_t *event)
{
extern struct mime_type_t MIME_Type_List[];
struct mime_type_t *list;
char *respText = NULL, *respPtr;
size_t respLen = 0, len;
@ -142,7 +143,6 @@ cms_get_current_connection_ids (struct action_event_t *event)
static bool
cms_get_current_connection_info (struct action_event_t *event)
{
extern struct mime_type_t MIME_Type_List[];
struct mime_type_t *list = MIME_Type_List;
if (!event)

View File

@ -291,7 +291,7 @@ ctrl_telnet_thread (void *a __attribute__ ((unused)))
socklen_t sl_addr;
/* Create client object */
client = malloc (sizeof (ctrl_telnet_client));
client = (ctrl_telnet_client *)malloc (sizeof (ctrl_telnet_client));
if (!client)
{
@ -628,7 +628,7 @@ ctrl_telnet_register (const char *funcname,
{
telnet_function_list *function;
function = malloc (sizeof (telnet_function_list));
function = (telnet_function_list *)malloc (sizeof (telnet_function_list));
function->name = strdup (funcname); /* Mayby use strndup...? */
function->description = description ? strdup (description) : NULL;
function->function = funcptr;
@ -689,7 +689,7 @@ ctrl_telnet_tokenize (char *raw, int *argc, char ***argv)
}
/* Create argv */
*argv = malloc (sizeof (char **) * ((*argc) + 1));
*argv = (char **)malloc (sizeof (char **) * ((*argc) + 1));
/* (2/3) Parse throu one more time, this time filling argv (Pass 2 / 3) */
i = 0;

View File

@ -27,6 +27,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
@ -187,10 +189,10 @@ get_file_memory (const char *fullpath, const char *description,
{
struct web_file_t *file;
file = malloc (sizeof (struct web_file_t));
file = (struct web_file_t *)malloc (sizeof (struct web_file_t));
file->fullpath = strdup (fullpath);
file->pos = 0;
file->type = FILE_MEMORY;
file->type = web_file_t::FILE_MEMORY;
file->detail.memory.contents = strdup (description);
file->detail.memory.len = length;
@ -241,10 +243,10 @@ http_open (const char *filename, enum UpnpOpenFileMode mode)
if (fd < 0)
return NULL;
file = malloc (sizeof (struct web_file_t));
file = (struct web_file_t *)malloc (sizeof (struct web_file_t));
file->fullpath = strdup (entry->fullpath);
file->pos = 0;
file->type = FILE_LOCAL;
file->type = web_file_t::FILE_LOCAL;
file->detail.local.entry = entry;
file->detail.local.fd = fd;
@ -264,11 +266,11 @@ http_read (UpnpWebFileHandle fh, char *buf, size_t buflen)
switch (file->type)
{
case FILE_LOCAL:
case web_file_t::FILE_LOCAL:
log_verbose ("Read local file.\n");
len = read (file->detail.local.fd, buf, buflen);
break;
case FILE_MEMORY:
case web_file_t::FILE_MEMORY:
log_verbose ("Read file from memory.\n");
len = (size_t) MIN (buflen, file->detail.memory.len - file->pos);
memcpy (buf, file->detail.memory.contents + file->pos, (size_t) len);
@ -323,7 +325,7 @@ http_seek (UpnpWebFileHandle fh, off_t offset, int origin)
log_verbose ("Attempting to seek by %lld from end (was at %lld) in %s\n",
offset, file->pos, file->fullpath);
if (file->type == FILE_LOCAL)
if (file->type == web_file_t::FILE_LOCAL)
{
struct stat sb;
if (stat (file->fullpath, &sb) < 0)
@ -333,15 +335,15 @@ http_seek (UpnpWebFileHandle fh, off_t offset, int origin)
return -1;
}
newpos = sb.st_size + offset;
}
else if (file->type == FILE_MEMORY)
} else if (file->type == web_file_t::FILE_MEMORY) {
newpos = file->detail.memory.len + offset;
}
break;
}
switch (file->type)
{
case FILE_LOCAL:
case web_file_t::FILE_LOCAL:
/* Just make sure we cannot seek before start of file. */
if (newpos < 0)
{
@ -357,7 +359,7 @@ http_seek (UpnpWebFileHandle fh, off_t offset, int origin)
return -1;
}
break;
case FILE_MEMORY:
case web_file_t::FILE_MEMORY:
if (newpos < 0 || newpos > file->detail.memory.len)
{
log_verbose ("%s: cannot seek: %s\n", file->fullpath, strerror (EINVAL));
@ -383,10 +385,10 @@ http_close (UpnpWebFileHandle fh)
switch (file->type)
{
case FILE_LOCAL:
case web_file_t::FILE_LOCAL:
close (file->detail.local.fd);
break;
case FILE_MEMORY:
case web_file_t::FILE_MEMORY:
/* no close operation */
if (file->detail.memory.contents)
free (file->detail.memory.contents);

View File

@ -25,6 +25,6 @@
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
struct UpnpVirtualDirCallbacks virtual_dir_callbacks;
extern struct UpnpVirtualDirCallbacks virtual_dir_callbacks;
#endif /* _HTTP_H_ */

0
appl/main.cpp Normal file
View File

View File

@ -26,6 +26,8 @@
#include <sys/stat.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
@ -89,7 +91,7 @@ is_valid_extension (const char *extension)
static int
get_list_length (void *list)
{
void **l = list;
void **l = (void **)list;
int n = 0;
while (*(l++))

View File

@ -21,6 +21,8 @@
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <stdio.h>
#include "mime.h"
#include "ushare.h"
@ -31,7 +33,7 @@
#define UPNP_PLAYLIST "object.item.playlistItem"
#define UPNP_TEXT "object.item.textItem"
const struct mime_type_t MIME_Type_List[] = {
struct mime_type_t MIME_Type_List[] = {
/* Video files */
{ "asf", UPNP_VIDEO, "http-get:*:video/x-ms-asf:"},
{ "avc", UPNP_VIDEO, "http-get:*:video/avi:"},

View File

@ -29,4 +29,6 @@ struct mime_type_t {
char *mime_get_protocol (struct mime_type_t *mime);
extern struct mime_type_t MIME_Type_List[];
#endif /* _MIME_H */

View File

@ -20,6 +20,8 @@
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
#include <string.h>
#include <stdio.h>
#include "ushare.h"
#include "services.h"

View File

@ -26,6 +26,8 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include "osdep.h"

View File

@ -27,6 +27,8 @@ static char rcsid[]="$Id: redblack.c,v 1.9 2003/10/24 01:31:21 damo Exp $";
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "redblack.h"
#define assert(expr)

View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <upnp/upnp.h>
#include <upnp/upnptools.h>
#include <string.h>
#include <stdio.h>
#include "ushare.h"
#include "services.h"

View File

@ -27,6 +27,8 @@
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <string.h>
#include <stdio.h>
#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__))
@ -783,7 +785,7 @@ main (int argc, char **argv)
{
char *name;
name = malloc (strlen (XBOX_MODEL_NAME) + strlen (ut->model_name) + 4);
name = (char*)malloc (strlen (XBOX_MODEL_NAME) + strlen (ut->model_name) + 4);
sprintf (name, "%s (%s)", XBOX_MODEL_NAME, ut->model_name);
free (ut->model_name);
ut->model_name = strdup (name);

View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "util_iconv.h"

View File

@ -32,23 +32,23 @@ def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type())
my_module.add_extra_compile_flags()
my_module.add_src_file([
'src/http.c',
'src/services.c',
'src/ushare.c',
'src/content.c',
'src/trace.c',
'src/cms.c',
'src/redblack.c',
'src/util_iconv.c',
'src/osdep.c',
'src/mime.c',
'src/cfgparser.c',
'src/metadata.c',
'src/msr.c',
'src/cds.c',
'src/presentation.c',
'src/buffer.c',
'src/ctrl_telnet.c'
'appl/http.cpp',
'appl/services.cpp',
'appl/ushare.cpp',
'appl/content.cpp',
'appl/trace.cpp',
'appl/cms.cpp',
'appl/redblack.cpp',
'appl/util_iconv.cpp',
'appl/osdep.cpp',
'appl/mime.cpp',
'appl/cfgparser.cpp',
'appl/metadata.cpp',
'appl/msr.cpp',
'appl/cds.cpp',
'appl/presentation.cpp',
'appl/buffer.cpp',
'appl/ctrl_telnet.cpp'
])
my_module.add_path(tools.get_current_path(__file__))
my_module.compile_flags('c', [

View File

@ -1,87 +0,0 @@
ifeq (,$(wildcard ../config.mak))
$(error "../config.mak is not present, run configure !")
endif
include ../config.mak
PROG = ushare
EXTRADIST = ushare.1 \
cds.h \
cms.h \
msr.h \
http.h \
presentation.h \
metadata.h \
mime.h \
services.h \
buffer.h \
util_iconv.h \
content.h \
cfgparser.h \
trace.h \
redblack.h \
osdep.h \
ctrl_telnet.h \
ushare.h \
gettext.h \
minmax.h \
SRCS = \
cds.c \
cms.c \
msr.c \
http.c \
presentation.c \
metadata.c \
mime.c \
services.c \
buffer.c \
util_iconv.c \
content.c \
cfgparser.c \
trace.c \
redblack.c \
osdep.c \
ctrl_telnet.c \
ushare.c
OBJS = $(SRCS:.c=.o)
.SUFFIXES: .c .o
all: depend $(PROG)
.c.o:
$(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $<
$(PROG): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) $(EXTRALIBS) -o $@
clean:
-$(RM) -f *.o $(PROG)
-$(RM) -f .depend
distclean:
install: $(PROG)
$(INSTALL) -d $(bindir)
$(INSTALL) $(PROG) $(bindir)
$(STRIP) $(INSTALLSTRIP) $(bindir)/$(PROG)
depend:
$(CC) -I.. -MM $(CFLAGS) $(SRCS) 1>.depend
.PHONY: clean distclean install depend
dist-all:
cp $(EXTRADIST) $(SRCS) Makefile $(DIST)
.PHONY: dist-all
#
# include dependency files if they exist
#
ifneq ($(wildcard .depend),)
include .depend
endif