diff options
| author | Tom Lane | 2000-08-03 23:07:51 +0000 |
|---|---|---|
| committer | Tom Lane | 2000-08-03 23:07:51 +0000 |
| commit | ed9ca687582caa88f31c4b273b9fd4eb5743cf41 (patch) | |
| tree | 5f291877d0a74c7c3f34da74c4e20aca6bd9a65f /src/include/utils | |
| parent | 61aca818c486dbe000ce94c77cb1dd1f379baf67 (diff) | |
Convert inet-related functions to new fmgr style. I have also taken it
on myself to do something about the non-self-consistency of the inet
comparison functions. The results are probably still semantically wrong
(inet and cidr should have different comparison semantics, I think)
but at least the boolean operators now agree with each other and with
the sort order of indexes on inet/cidr.
Diffstat (limited to 'src/include/utils')
| -rw-r--r-- | src/include/utils/builtins.h | 66 | ||||
| -rw-r--r-- | src/include/utils/inet.h | 35 |
2 files changed, 61 insertions, 40 deletions
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index bb483164130..4fa7481f042 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: builtins.h,v 1.129 2000/08/03 16:34:50 tgl Exp $ + * $Id: builtins.h,v 1.130 2000/08/03 23:07:51 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,7 +16,6 @@ #include "nodes/relation.h" /* for amcostestimate parameters */ #include "storage/itemptr.h" -#include "utils/inet.h" #include "utils/numeric.h" /* @@ -436,7 +435,6 @@ extern Datum textlike(PG_FUNCTION_ARGS); extern Datum textnlike(PG_FUNCTION_ARGS); /* oracle_compat.c */ - extern Datum lower(PG_FUNCTION_ARGS); extern Datum upper(PG_FUNCTION_ARGS); extern Datum initcap(PG_FUNCTION_ARGS); @@ -450,48 +448,48 @@ extern Datum ichar(PG_FUNCTION_ARGS); extern Datum repeat(PG_FUNCTION_ARGS); extern Datum ascii(PG_FUNCTION_ARGS); -/* acl.c */ - /* inet_net_ntop.c */ -extern char *inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size); -extern char *inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size); +extern char *inet_net_ntop(int af, const void *src, int bits, + char *dst, size_t size); +extern char *inet_cidr_ntop(int af, const void *src, int bits, + char *dst, size_t size); /* inet_net_pton.c */ -extern int inet_net_pton(int af, const char *src, void *dst, size_t size); +extern int inet_net_pton(int af, const char *src, + void *dst, size_t size); /* network.c */ -extern inet *inet_in(char *str); -extern char *inet_out(inet *addr); -extern inet *cidr_in(char *str); -extern char *cidr_out(inet *addr); -extern bool network_lt(inet *a1, inet *a2); -extern bool network_le(inet *a1, inet *a2); -extern bool network_eq(inet *a1, inet *a2); -extern bool network_ge(inet *a1, inet *a2); -extern bool network_gt(inet *a1, inet *a2); -extern bool network_ne(inet *a1, inet *a2); -extern bool network_sub(inet *a1, inet *a2); -extern bool network_subeq(inet *a1, inet *a2); -extern bool network_sup(inet *a1, inet *a2); -extern bool network_supeq(inet *a1, inet *a2); -extern int4 network_cmp(inet *a1, inet *a2); - +extern Datum inet_in(PG_FUNCTION_ARGS); +extern Datum inet_out(PG_FUNCTION_ARGS); +extern Datum cidr_in(PG_FUNCTION_ARGS); +extern Datum cidr_out(PG_FUNCTION_ARGS); +extern Datum network_cmp(PG_FUNCTION_ARGS); +extern Datum network_lt(PG_FUNCTION_ARGS); +extern Datum network_le(PG_FUNCTION_ARGS); +extern Datum network_eq(PG_FUNCTION_ARGS); +extern Datum network_ge(PG_FUNCTION_ARGS); +extern Datum network_gt(PG_FUNCTION_ARGS); +extern Datum network_ne(PG_FUNCTION_ARGS); +extern Datum network_sub(PG_FUNCTION_ARGS); +extern Datum network_subeq(PG_FUNCTION_ARGS); +extern Datum network_sup(PG_FUNCTION_ARGS); +extern Datum network_supeq(PG_FUNCTION_ARGS); extern Datum network_network(PG_FUNCTION_ARGS); extern Datum network_netmask(PG_FUNCTION_ARGS); -extern int4 network_masklen(inet *addr); +extern Datum network_masklen(PG_FUNCTION_ARGS); extern Datum network_broadcast(PG_FUNCTION_ARGS); extern Datum network_host(PG_FUNCTION_ARGS); /* mac.c */ -extern macaddr *macaddr_in(char *str); -extern char *macaddr_out(macaddr *addr); -extern bool macaddr_lt(macaddr *a1, macaddr *a2); -extern bool macaddr_le(macaddr *a1, macaddr *a2); -extern bool macaddr_eq(macaddr *a1, macaddr *a2); -extern bool macaddr_ge(macaddr *a1, macaddr *a2); -extern bool macaddr_gt(macaddr *a1, macaddr *a2); -extern bool macaddr_ne(macaddr *a1, macaddr *a2); -extern int4 macaddr_cmp(macaddr *a1, macaddr *a2); +extern Datum macaddr_in(PG_FUNCTION_ARGS); +extern Datum macaddr_out(PG_FUNCTION_ARGS); +extern Datum macaddr_cmp(PG_FUNCTION_ARGS); +extern Datum macaddr_lt(PG_FUNCTION_ARGS); +extern Datum macaddr_le(PG_FUNCTION_ARGS); +extern Datum macaddr_eq(PG_FUNCTION_ARGS); +extern Datum macaddr_ge(PG_FUNCTION_ARGS); +extern Datum macaddr_gt(PG_FUNCTION_ARGS); +extern Datum macaddr_ne(PG_FUNCTION_ARGS); extern Datum macaddr_manuf(PG_FUNCTION_ARGS); /* numeric.c */ diff --git a/src/include/utils/inet.h b/src/include/utils/inet.h index 075d66aa6b3..5b39801f9c1 100644 --- a/src/include/utils/inet.h +++ b/src/include/utils/inet.h @@ -7,17 +7,17 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: inet.h,v 1.7 2000/07/06 05:48:31 tgl Exp $ + * $Id: inet.h,v 1.8 2000/08/03 23:07:51 tgl Exp $ * *------------------------------------------------------------------------- */ -#ifndef MAC_H -#define MAC_H +#ifndef INET_H +#define INET_H /* - * This is the internal storage format for IP addresses: + * This is the internal storage format for IP addresses + * (both INET and CIDR datatypes): */ - typedef struct { unsigned char family; @@ -30,8 +30,17 @@ typedef struct } addr; } inet_struct; +/* + * Both INET and CIDR addresses are represented within Postgres as varlena + * objects, ie, there is a varlena header (basically a length word) in front + * of the struct type depicted above. + * + * Although these types are variable-length, the maximum length + * is pretty short, so we make no provision for TOASTing them. + */ typedef struct varlena inet; + /* * This is the internal storage format for MAC addresses: */ @@ -45,4 +54,18 @@ typedef struct macaddr unsigned char f; } macaddr; -#endif /* MAC_H */ +/* + * fmgr interface macros + */ +#define DatumGetInetP(X) ((inet *) DatumGetPointer(X)) +#define InetPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) +#define PG_RETURN_INET_P(x) return InetPGetDatum(x) +/* macaddr is a fixed-length pass-by-reference datatype */ +#define DatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X)) +#define MacaddrPGetDatum(X) PointerGetDatum(X) +#define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n)) +#define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x) + + +#endif /* INET_H */ |
