added some netdebug and netconfig files

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14373 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2005-10-13 15:49:30 +00:00
parent 4e918a7c19
commit 060d9206d9
6 changed files with 186 additions and 13 deletions

View File

@ -0,0 +1,81 @@
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
/*
* netconfig.h
* Copyright (c) 1995 Be, Inc. All Rights Reserved
*
* Stuff for reading info out of the /boot/system/netconfig file
*/
#ifndef _NETCONFIG_H
#define _NETCONFIG_H
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdio.h>
#include <net_settings.h>
#define NC_MAXCLASSLEN 256
#define NC_MAXNAMELEN 256
#define NC_MAXVALLEN 256
static const char NETCONFIGFILE[] = "/network";
static const char NETCONFIGFILE_TMP[] = "/network.tmp";
typedef struct _netconfig {
FILE *ncfile;
char ncbuf[1020];
} NETCONFIG;
typedef char nc_data_t[NC_MAXVALLEN];
typedef struct nc_private {
nc_data_t key;
nc_data_t value;
} nc_private_t;
_IMPEXP_NET NETCONFIG *_netconfig_open(const char *heading);
_IMPEXP_NET char *_netconfig_find(const char *heading, const char *name, char *value,
int nbytes);
_IMPEXP_NET int _netconfig_set(const char *heading, const char *name, const char *value);
_IMPEXP_NET net_settings *_net_settings_open(const char *fname);
_IMPEXP_NET void _net_settings_makedefault(net_settings *ncw);
_IMPEXP_NET int _net_settings_save(net_settings *ncw);
_IMPEXP_NET int _net_settings_save_as(net_settings *ncw, const char *fname);
_IMPEXP_NET void _net_settings_close(net_settings *ncw);
_IMPEXP_NET int _netconfig_getnext(
NETCONFIG *netconfig,
char **name,
char **value
);
_IMPEXP_NET void _netconfig_close(NETCONFIG *netconfig);
#define net_settings_isdirty(ncw) (ncw)->_dirty
#define net_settings_makedirty(ncw, mkdirty) (ncw)->_dirty = mkdirty
#define net_settings_makedefault _net_settings_makedefault
#define netconfig_open _netconfig_open
#define net_settings_open _net_settings_open
#define netconfig_find _netconfig_find
#define netconfig_set _netconfig_set
#define net_settings_save _net_settings_save
#define net_settings_save_as _net_settings_save_as
#define net_settings_close _net_settings_close
#define netconfig_getnext _netconfig_getnext
#define netconfig_close _netconfig_close
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* _NETCONFIG_H */

View File

@ -0,0 +1,72 @@
/*
* netdebug.h
*
* Debugging message support. Nothing really network specific about
* it, but renamed from "debug.h" to distinguish it from other debug.h's
* that live around the system, and because the *&^%$#@! Metrowerks
* compiler can't deal with subdirs in include directives.
*/
/*
Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef _NETDEBUG_H
#define _NETDEBUG_H
#include <BeBuild.h>
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC extern
#endif
/*
* Debug messages can go to a file, to the console, to both or to nowhere.
* Use debug_setflags() to set.
*/
#define DEBUG_CONSOLE 1
#define DEBUG_FILE 2
#define DEBUG_NOFLUSH 4
EXTERNC _IMPEXP_NET void _debug_setflags(unsigned flags);
EXTERNC _IMPEXP_NET unsigned _debug_getflags(void);
#define debug_setflags _debug_setflags
#define debug_getflags _debug_getflags
/*
* function -DDEBUG=? comment
* _____________________________________________________
* wprintf anything for warnings
* dprintf DEBUG > 0 for debugging messages
* ddprintf DEBUG > 1 for extra debugging messages
*/
EXTERNC _IMPEXP_NET int _wprintf(const char *format, ...);
EXTERNC _IMPEXP_NET int _dprintf(const char *format, ...);
/*
* Define null function "noprintf"
*/
#define noprintf (void)
#if DEBUG
#define wprintf _dprintf
#define dprintf _dprintf
#if DEBUG > 1
#define ddprintf _dprintf
#else /* DEBUG > 1 */
#define ddprintf noprintf
#endif /* DEBUG > 1 */
#else /* DEBUG */
#define wprintf _wprintf
#define dprintf noprintf
#define ddprintf noprintf
#endif /* DEBUG */
#endif /* _NETDEBUG_H */

View File

@ -42,6 +42,8 @@ if ( $(TARGET_PLATFORM) = r5 ) {
SharedLibrary net :
$(PLATFORM_SOURCES)
netdebug.c
netconfig.c
socket.c
compat.c
arc4random.c

View File

@ -25,12 +25,10 @@ void initialize_before(void);
void terminate_after(void);
void _b_pre_accept(void);
void _b_post_accept(void);
void _debug_setflags(int flags);
const char * hstrerror(int error);
int _socket_interrupt(void);
int _netconfig_find(void);
char _socket_signals[5];
@ -42,10 +40,6 @@ _EXPORT void _b_post_accept(void)
{
}
_EXPORT void _debug_setflags(int flags)
{
}
_EXPORT void initialize_before(void)
{
h_errno_tls = tls_allocate();
@ -86,13 +80,6 @@ _EXPORT int _socket_interrupt(void)
return 0;
}
_EXPORT int _netconfig_find(void)
{
printf("_netconfig_find\n");
return 0;
}
/* XXX: HACK HACK HACK! FIXME! */
/* This is a terrible hack :(
* TODO: We should really get these settings values by parsing
@ -113,6 +100,10 @@ _EXPORT char * find_net_setting(net_settings * ncw, const char * heading,
strncpy(value, "baron\0", nbytes);
else if (strcmp(name, "PASSWORD") == 0)
strncpy(value, "password", nbytes);
else if (strcmp(name, "FTP_ENABLED") == 0)
strncpy(value, "1", nbytes);
else if (strcmp(name, "TELNETD_ENABLED") == 0)
strncpy(value, "1", nbytes);
else
return NULL;

View File

@ -0,0 +1,15 @@
/*
** Copyright 2005, Jérôme DUVAL. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <netconfig.h>
_EXPORT char *
_netconfig_find(const char *heading, const char *name, char *value,
int nbytes)
{
printf("_netconfig_find heading:%s, name:%s, value:%s, nbytes:%d\n", heading, name, value, nbytes);
return find_net_setting(NULL, heading, name, value, nbytes);
}

View File

@ -0,0 +1,12 @@
/*
** Copyright 2005, Jérôme DUVAL. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <netdebug.h>
_EXPORT void
_debug_setflags(unsigned flags)
{
}