First small part of lib cleanup. Mainly "constification" of arguments and

adding FIXME's.
This commit is contained in:
hasso 2004-10-04 19:10:31 +00:00
parent 97c52f4e39
commit b04c699ecf
9 changed files with 82 additions and 64 deletions

View File

@ -1,3 +1,12 @@
2004-10-04 Hasso Tepper <hasso at quagga.net>
* memory.c, memory.h: Make char * argument of strdup functions const.
* prefix.c, prefix.h: Make many arguments const. Reorder stuff in
header.
* log.h: Make log message const in struct message.
* log.c: Fix some indenting.
* network.c, network.h: Make second argument of writen() const.
2004-10-03 Hasso Tepper <hasso at quagga.net>
* command.h: Introduce SERVICE_NODE for "service <...>" commands.

View File

@ -113,7 +113,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list *args)
if (zl->flags & ZLOG_FILE)
{
time_print (zl->fp);
if (zl->record_priority) fprintf (zl->fp, "%s: ", zlog_priority[priority]);
if (zl->record_priority)
fprintf (zl->fp, "%s: ", zlog_priority[priority]);
fprintf (zl->fp, "%s: ", zlog_proto_names[zl->protocol]);
vfprintf (zl->fp, format, args[ZLOG_FILE_INDEX]);
fprintf (zl->fp, "\n");
@ -124,7 +125,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list *args)
if (zl->flags & ZLOG_STDOUT)
{
time_print (stdout);
if (zl->record_priority) fprintf (stdout, "%s: ", zlog_priority[priority]);
if (zl->record_priority)
fprintf (stdout, "%s: ", zlog_priority[priority]);
fprintf (stdout, "%s: ", zlog_proto_names[zl->protocol]);
vfprintf (stdout, format, args[ZLOG_STDOUT_INDEX]);
fprintf (stdout, "\n");
@ -135,7 +137,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list *args)
if (zl->flags & ZLOG_STDERR)
{
time_print (stderr);
if (zl->record_priority) fprintf (stderr, "%s: ", zlog_priority[priority]);
if (zl->record_priority)
fprintf (stderr, "%s: ", zlog_priority[priority]);
fprintf (stderr, "%s: ", zlog_proto_names[zl->protocol]);
vfprintf (stderr, format, args[ZLOG_STDERR_INDEX]);
fprintf (stderr, "\n");
@ -484,7 +487,7 @@ lookup (struct message *mes, int key)
}
/* Very old hacky version of message lookup function. Still partly
used in bgpd and ospfd. */
used in bgpd and ospfd. FIXME Seems that it's not used any more. */
char *
mes_lookup (struct message *meslist, int max, int index)
{

View File

@ -71,7 +71,7 @@ struct zlog
struct message
{
int key;
char *str;
const char *str;
};
/* Default logging strucutre. */

View File

@ -101,7 +101,7 @@ zfree (int type, void *ptr)
/* String duplication. */
char *
zstrdup (int type, char *str)
zstrdup (int type, const char *str)
{
void *dup;
@ -115,7 +115,7 @@ zstrdup (int type, char *str)
#ifdef MEMORY_LOG
struct
{
char *name;
const char *name;
unsigned long alloc;
unsigned long t_malloc;
unsigned long c_malloc;
@ -187,7 +187,7 @@ mtype_zfree (const char *file, int line, int type, void *ptr)
}
char *
mtype_zstrdup (const char *file, int line, int type, char *str)
mtype_zstrdup (const char *file, int line, int type, const char *str)
{
char *memory;
@ -230,7 +230,7 @@ alloc_dec (int type)
struct memory_list
{
int index;
char *format;
const char *format;
};
struct memory_list memory_list_lib[] =

View File

@ -236,7 +236,7 @@ void *zmalloc (int type, size_t size);
void *zcalloc (int type, size_t size);
void *zrealloc (int type, void *ptr, size_t size);
void zfree (int type, void *ptr);
char *zstrdup (int type, char *str);
char *zstrdup (int type, const char *str);
void *mtype_zmalloc (const char *file,
int line,
@ -263,7 +263,7 @@ void mtype_zfree (const char *file,
char *mtype_zstrdup (const char *file,
int line,
int type,
char *str);
const char *str);
void memory_init ();
#endif /* _ZEBRA_MEMORY_H */

View File

@ -50,7 +50,7 @@ readn (int fd, u_char *ptr, int nbytes)
/* Write nbytes from ptr to fd. */
int
writen(int fd, u_char *ptr, int nbytes)
writen(int fd, const u_char *ptr, int nbytes)
{
int nleft;
int nwritten;

View File

@ -24,6 +24,6 @@
#define _ZEBRA_NETWORK_H
int readn (int, u_char *, int);
int writen (int, u_char *, int);
int writen (int, const u_char *, int);
#endif /* _ZEBRA_NETWORK_H */

View File

@ -66,7 +66,7 @@ family2afi (int family)
/* If n includes p prefix then return 1 else return 0. */
int
prefix_match (struct prefix *n, struct prefix *p)
prefix_match (const struct prefix *n, const struct prefix *p)
{
int offset;
int shift;
@ -94,7 +94,7 @@ prefix_match (struct prefix *n, struct prefix *p)
/* Copy prefix from src to dest. */
void
prefix_copy (struct prefix *dest, struct prefix *src)
prefix_copy (struct prefix *dest, const struct prefix *src)
{
dest->family = src->family;
dest->prefixlen = src->prefixlen;
@ -127,7 +127,7 @@ prefix_copy (struct prefix *dest, struct prefix *src)
* as '==' (which is different from prefix_cmp).
*/
int
prefix_same (struct prefix *p1, struct prefix *p2)
prefix_same (const struct prefix *p1, const struct prefix *p2)
{
if (p1->family == p2->family && p1->prefixlen == p2->prefixlen)
{
@ -154,7 +154,7 @@ prefix_same (struct prefix *p1, struct prefix *p2)
* from prefix_same).
*/
int
prefix_cmp (struct prefix *p1, struct prefix *p2)
prefix_cmp (const struct prefix *p1, const struct prefix *p2)
{
int offset;
int shift;
@ -181,8 +181,8 @@ prefix_cmp (struct prefix *p1, struct prefix *p2)
}
/* Return prefix family type string. */
char *
prefix_family_str (struct prefix *p)
const char *
prefix_family_str (const struct prefix *p)
{
if (p->family == AF_INET)
return "inet";
@ -213,7 +213,7 @@ prefix_ipv4_free (struct prefix_ipv4 *p)
/* When string format is invalid return 0. */
int
str2prefix_ipv4 (char *str, struct prefix_ipv4 *p)
str2prefix_ipv4 (const char *str, struct prefix_ipv4 *p)
{
int ret;
int plen;
@ -335,7 +335,7 @@ apply_mask_ipv4 (struct prefix_ipv4 *p)
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */
int
prefix_ipv4_any (struct prefix_ipv4 *p)
prefix_ipv4_any (const struct prefix_ipv4 *p)
{
return (p->prefix.s_addr == 0 && p->prefixlen == 0);
}
@ -362,7 +362,7 @@ prefix_ipv6_free (struct prefix_ipv6 *p)
/* If given string is valid return pin6 else return NULL */
int
str2prefix_ipv6 (char *str, struct prefix_ipv6 *p)
str2prefix_ipv6 (const char *str, struct prefix_ipv6 *p)
{
char *pnt;
char *cp;
@ -399,7 +399,8 @@ str2prefix_ipv6 (char *str, struct prefix_ipv6 *p)
return ret;
}
/* Convert struct in6_addr netmask into integer. */
/* Convert struct in6_addr netmask into integer.
* FIXME return u_char as ip_maskleni() does. */
int
ip6_masklen (struct in6_addr netmask)
{
@ -470,7 +471,7 @@ apply_mask_ipv6 (struct prefix_ipv6 *p)
}
void
str2in6_addr (char *str, struct in6_addr *addr)
str2in6_addr (const char *str, struct in6_addr *addr)
{
int i;
unsigned int x;
@ -503,10 +504,11 @@ apply_mask (struct prefix *p)
return;
}
/* Utility function of convert between struct prefix <=> union sockunion */
/* Utility function of convert between struct prefix <=> union sockunion.
* FIXME This function isn't used anywhere. */
struct prefix *
sockunion2prefix (union sockunion *dest,
union sockunion *mask)
sockunion2prefix (const union sockunion *dest,
const union sockunion *mask)
{
if (dest->sa.sa_family == AF_INET)
{
@ -533,9 +535,9 @@ sockunion2prefix (union sockunion *dest,
return NULL;
}
/* Utility function of convert between struct prefix <=> union sockunion */
/* Utility function of convert between struct prefix <=> union sockunion. */
struct prefix *
sockunion2hostprefix (union sockunion *su)
sockunion2hostprefix (const union sockunion *su)
{
if (su->sa.sa_family == AF_INET)
{
@ -563,7 +565,7 @@ sockunion2hostprefix (union sockunion *su)
}
int
prefix_blen (struct prefix *p)
prefix_blen (const struct prefix *p)
{
switch (p->family)
{
@ -581,7 +583,7 @@ prefix_blen (struct prefix *p)
/* Generic function for conversion string to struct prefix. */
int
str2prefix (char *str, struct prefix *p)
str2prefix (const char *str, struct prefix *p)
{
int ret;
@ -601,7 +603,7 @@ str2prefix (char *str, struct prefix *p)
}
int
prefix2str (struct prefix *p, char *str, int size)
prefix2str (const struct prefix *p, char *str, int size)
{
char buf[BUFSIZ];
@ -627,9 +629,10 @@ prefix_free (struct prefix *p)
}
/* Utility function. Check the string only contains digit
character. */
* character.
* FIXME str.[c|h] would be better place for this function. */
int
all_digit (char *str)
all_digit (const char *str)
{
for (; *str != '\0'; str++)
if (!isdigit ((int) *str))
@ -668,7 +671,8 @@ void apply_classful_mask_ipv4 (struct prefix_ipv4 *p)
ex.) "1.1.0.0" "255.255.0.0" => "1.1.0.0/16"
ex.) "1.0.0.0" NULL => "1.0.0.0/8" */
int
netmask_str2prefix_str (char *net_str, char *mask_str, char *prefix_str)
netmask_str2prefix_str (const char *net_str, const char *mask_str,
char *prefix_str)
{
struct in_addr network;
struct in_addr mask;

View File

@ -128,43 +128,45 @@ struct prefix_rd
int afi2family (int);
int family2afi (int);
int prefix2str (struct prefix *, char *, int);
int str2prefix (char *, struct prefix *);
struct prefix *prefix_new ();
void prefix_free (struct prefix *p);
void prefix_free (struct prefix *);
const char *prefix_family_str (const struct prefix *);
int prefix_blen (const struct prefix *);
int str2prefix (const char *, struct prefix *);
int prefix2str (const struct prefix *, char *, int);
int prefix_match (const struct prefix *, const struct prefix *);
int prefix_same (const struct prefix *, const struct prefix *);
int prefix_cmp (const struct prefix *, const struct prefix *);
void prefix_copy (struct prefix *dest, const struct prefix *src);
void apply_mask (struct prefix *);
struct prefix_ipv4 *prefix_ipv4_new ();
void prefix_ipv4_free ();
int str2prefix_ipv4 (char *, struct prefix_ipv4 *);
void apply_mask_ipv4 (struct prefix_ipv4 *);
int prefix_blen (struct prefix *);
u_char ip_masklen (struct in_addr);
int prefix_ipv4_any (struct prefix_ipv4 *);
void masklen2ip (int, struct in_addr *);
void apply_classful_mask_ipv4 (struct prefix_ipv4 *);
char *prefix_family_str (struct prefix *p);
struct prefix *sockunion2prefix ();
struct prefix *sockunion2hostprefix ();
struct prefix_ipv4 *prefix_ipv4_new ();
void prefix_ipv4_free (struct prefix_ipv4 *);
int str2prefix_ipv4 (const char *, struct prefix_ipv4 *);
void apply_mask_ipv4 (struct prefix_ipv4 *);
int prefix_ipv4_any (const struct prefix_ipv4 *);
void apply_classful_mask_ipv4 (struct prefix_ipv4 *);
u_char ip_masklen (struct in_addr);
void masklen2ip (int, struct in_addr *);
int netmask_str2prefix_str (const char *, const char *, char *);
#ifdef HAVE_IPV6
struct prefix_ipv6 *prefix_ipv6_new ();
void prefix_ipv6_free ();
struct prefix *str2routev6 (char *);
int str2prefix_ipv6 (char *str, struct prefix_ipv6 *p);
void apply_mask_ipv6 (struct prefix_ipv6 *p);
void str2in6_addr (char *str, struct in6_addr *addr);
void masklen2ip6 (int masklen, struct in6_addr *netmask);
int ip6_masklen (struct in6_addr netmask);
void prefix_ipv6_free (struct prefix_ipv6 *);
int str2prefix_ipv6 (const char *, struct prefix_ipv6 *);
void apply_mask_ipv6 (struct prefix_ipv6 *);
int ip6_masklen (struct in6_addr);
void masklen2ip6 (int, struct in6_addr *);
void str2in6_addr (const char *, struct in6_addr *);
#endif /* HAVE_IPV6 */
void apply_mask (struct prefix *);
int prefix_match (struct prefix *n, struct prefix *p);
int prefix_same (struct prefix *, struct prefix *);
int prefix_cmp (struct prefix *, struct prefix *);
void prefix_copy (struct prefix *, struct prefix *);
int all_digit (char *);
int netmask_str2prefix_str (char *, char *, char *);
int all_digit (const char *);
#endif /* _ZEBRA_PREFIX_H */