Add "extern C {...} to header files for C++ builds.
[freeradius.git] / src / include / libradius.h
index 90b5514..5423583 100644 (file)
@@ -53,21 +53,28 @@ RCSIDH(libradius_h, "$Id$")
 #include <freeradius-devel/sha1.h>
 #include <freeradius-devel/md4.h>
 
+#ifndef WITHOUT_TCP
+#define WITH_TCP (1)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define EAP_START               2
 
 #define AUTH_VECTOR_LEN                16
 #define CHAP_VALUE_LENGTH       16
 #define MAX_STRING_LEN         254     /* RFC2138: string 0-253 octets */
-
-#  define VENDOR(x)            ((x >> 16) & 0x7fff)
+#define FR_MAX_VENDOR          (1 << 24) /* RFC limitations */
 
 #ifdef _LIBRADIUS
 #  define AUTH_HDR_LEN         20
 #  define VENDORPEC_USR                429
 #define VENDORPEC_LUCENT       4846
 #define VENDORPEC_STARENT      8164
-#  define DEBUG                        if (librad_debug && fr_log_fp) fr_printf_log
-#  define debug_pair(vp)       do { if (librad_debug && fr_log_fp) { \
+#  define DEBUG                        if (fr_debug_flag && fr_log_fp) fr_printf_log
+#  define debug_pair(vp)       do { if (fr_debug_flag && fr_log_fp) { \
                                        fputc('\t', fr_log_fp); \
                                        vp_print(fr_log_fp, vp); \
                                        fputc('\n', fr_log_fp); \
@@ -101,9 +108,12 @@ typedef struct attr_flags {
        unsigned int            has_tlv : 1; /* has sub attributes */
        unsigned int            is_tlv : 1; /* is a sub attribute */
        unsigned int            encoded : 1; /* has been put into packet */
+       unsigned int            extended : 1; /* extended attribute */
+       unsigned int            extended_flags : 1; /* with flag */
 
        int8_t                  tag;          /* tag for tunneled attributes */
        uint8_t                 encrypt;      /* encryption method */
+       uint8_t                 length;
 } ATTR_FLAGS;
 
 /*
@@ -115,7 +125,7 @@ typedef struct attr_flags {
 #define FLAG_ENCRYPT_ASCEND_SECRET   (3)
 
 typedef struct dict_attr {
-       int                     attr;
+       unsigned int            attr;
        int                     type;
        int                     vendor;
         ATTR_FLAGS              flags;
@@ -123,16 +133,17 @@ typedef struct dict_attr {
 } DICT_ATTR;
 
 typedef struct dict_value {
-       int                     attr;
+       unsigned int            attr;
+       unsigned int            vendor;
        int                     value;
        char                    name[1];
 } DICT_VALUE;
 
 typedef struct dict_vendor {
        int                     vendorpec;
-       int                     type; /* length of type data */
-       int                     length; /* length of length data */
-       int                     flags;
+       size_t                  type; /* length of type data */
+       size_t                  length; /* length of length data */
+       size_t                  flags;
        char                    name[1];
 } DICT_VENDOR;
 
@@ -153,11 +164,20 @@ typedef union value_pair_data {
 
 typedef struct value_pair {
        const char              *name;
-       int                     attribute;
-       int                     vendor;
+       unsigned int            attribute;
+       unsigned int            vendor;
        int                     type;
        size_t                  length; /* of data */
+#ifdef __cplusplus
+       /*
+        *      C++ hackery.  The server and modules are all C, so
+        *      the defs here don't affect them.  But any C++ code
+        *      gets excited over "operator", so we change the name.
+        */
+       FR_TOKEN                op_token;
+#else
        FR_TOKEN                operator;
+#endif
         ATTR_FLAGS              flags;
        struct value_pair       *next;
        uint32_t                lvalue;
@@ -194,6 +214,7 @@ typedef struct fr_ipaddr_t {
                struct in_addr  ip4addr;
                struct in6_addr ip6addr; /* maybe defined in missing.h */
        } ipaddr;
+       uint32_t        scope;  /* for IPv6 */
 } fr_ipaddr_t;
 
 /*
@@ -217,19 +238,23 @@ typedef struct radius_packet {
        uint8_t                 vector[AUTH_VECTOR_LEN];
        time_t                  timestamp;
        uint8_t                 *data;
-       int                     data_len;
+       ssize_t                 data_len;
        VALUE_PAIR              *vps;
        ssize_t                 offset;
+#ifdef WITH_TCP
+       ssize_t                 partial;
+#endif
 } RADIUS_PACKET;
 
 /*
  *     Printing functions.
  */
-void           librad_safeprint(char *in, size_t inlen,
+int            fr_utf8_char(const uint8_t *str);
+void           fr_print_string(const char *in, size_t inlen,
                                 char *out, size_t outlen);
 int            vp_prints_value(char *out, size_t outlen,
                                VALUE_PAIR *vp, int delimitst);
-const char     *vp_print_name(char *buffer, size_t bufsize, int attr);
+const char     *vp_print_name(char *buffer, size_t bufsize, int attr, int vendor);
 int            vp_prints(char *out, size_t outlen, VALUE_PAIR *vp);
 void           vp_print(FILE *, VALUE_PAIR *);
 void           vp_printlist(FILE *, VALUE_PAIR *);
@@ -239,14 +264,14 @@ void              vp_printlist(FILE *, VALUE_PAIR *);
  *     Dictionary functions.
  */
 int            dict_addvendor(const char *name, int value);
-int            dict_addattr(const char *name, int vendor, int type, int value, ATTR_FLAGS flags);
+int            dict_addattr(const char *name, int attr, int vendor, int type, ATTR_FLAGS flags);
 int            dict_addvalue(const char *namestr, const char *attrstr, int value);
 int            dict_init(const char *dir, const char *fn);
 void           dict_free(void);
-DICT_ATTR      *dict_attrbyvalue(int attr);
+DICT_ATTR      *dict_attrbyvalue(unsigned int attr, unsigned int vendor);
 DICT_ATTR      *dict_attrbyname(const char *attr);
-DICT_VALUE     *dict_valbyattr(int attr, int val);
-DICT_VALUE     *dict_valbyname(int attr, const char *val);
+DICT_VALUE     *dict_valbyattr(unsigned int attr, unsigned int vendor, int val);
+DICT_VALUE     *dict_valbyname(unsigned int attr, unsigned int vendor, const char *val);
 int            dict_vendorbyname(const char *name);
 DICT_VENDOR    *dict_vendorbyvalue(int vendor);
 
@@ -300,6 +325,7 @@ int         rad_sign(RADIUS_PACKET *packet, const RADIUS_PACKET *original,
                         const char *secret);
 
 RADIUS_PACKET  *rad_alloc(int newvector);
+RADIUS_PACKET  *rad_alloc_reply(RADIUS_PACKET *);
 void           rad_free(RADIUS_PACKET **);
 int            rad_pwencode(char *encpw, size_t *len, const char *secret,
                             const uint8_t *vector);
@@ -312,27 +338,28 @@ int               rad_tunnel_pwdecode(uint8_t *encpw, size_t *len,
 int            rad_chap_encode(RADIUS_PACKET *packet, uint8_t *output,
                                int id, VALUE_PAIR *password);
 VALUE_PAIR     *rad_attr2vp(const RADIUS_PACKET *packet, const RADIUS_PACKET *original,
-                            const char *secret, int attribute, int length,
-                            const uint8_t *data);
+                            const char *secret, int attribute, int vendor,
+                            int length, const uint8_t *data);
 int            rad_vp2attr(const RADIUS_PACKET *packet,
                            const RADIUS_PACKET *original, const char *secret,
-                           const VALUE_PAIR *vp, uint8_t *ptr);
+                           const VALUE_PAIR *vp, uint8_t *ptr, size_t room);
 
 /* valuepair.c */
 VALUE_PAIR     *pairalloc(DICT_ATTR *da);
-VALUE_PAIR     *paircreate(int attr, int type);
+VALUE_PAIR     *paircreate_raw(int attr, int vendor, int type, VALUE_PAIR *);
+VALUE_PAIR     *paircreate(int attr, int vendor, int type);
 void           pairfree(VALUE_PAIR **);
 void            pairbasicfree(VALUE_PAIR *pair);
-VALUE_PAIR     *pairfind(VALUE_PAIR *, int);
-void           pairdelete(VALUE_PAIR **, int);
+VALUE_PAIR     *pairfind(VALUE_PAIR *, unsigned int attr, unsigned int vendor);
+void           pairdelete(VALUE_PAIR **, unsigned int attr, unsigned int vendor);
 void           pairadd(VALUE_PAIR **, VALUE_PAIR *);
 void            pairreplace(VALUE_PAIR **first, VALUE_PAIR *add);
 int            paircmp(VALUE_PAIR *check, VALUE_PAIR *data);
 VALUE_PAIR     *paircopyvp(const VALUE_PAIR *vp);
 VALUE_PAIR     *paircopy(VALUE_PAIR *vp);
-VALUE_PAIR     *paircopy2(VALUE_PAIR *vp, int attr);
+VALUE_PAIR     *paircopy2(VALUE_PAIR *vp, unsigned int attr, unsigned int vendor);
 void           pairmove(VALUE_PAIR **to, VALUE_PAIR **from);
-void           pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, int attr);
+void           pairmove2(VALUE_PAIR **to, VALUE_PAIR **from, unsigned int attr, unsigned int vendor);
 VALUE_PAIR     *pairparsevalue(VALUE_PAIR *vp, const char *value);
 VALUE_PAIR     *pairmake(const char *attribute, const char *value, int operator);
 VALUE_PAIR     *pairread(const char **ptr, FR_TOKEN *eol);
@@ -343,21 +370,23 @@ VALUE_PAIR     *readvp2(FILE *fp, int *pfiledone, const char *errprefix);
  *     Error functions.
  */
 #ifdef _LIBRADIUS
-void           librad_log(const char *, ...)
+void           fr_strerror_printf(const char *, ...)
 #ifdef __GNUC__
                __attribute__ ((format (printf, 1, 2)))
 #endif
 ;
 #endif
-void           librad_perror(const char *, ...)
+void           fr_perror(const char *, ...)
 #ifdef __GNUC__
                __attribute__ ((format (printf, 1, 2)))
 #endif
 ;
-extern char    librad_errstr[];
-extern int     librad_dodns;   /* 0 = no dns lookups */
-extern int     librad_debug;   /* 0 = no debugging information */
-extern int     librad_max_attributes; /* per incoming packet */
+extern const char *fr_strerror(void);
+extern int     fr_dns_lookups; /* 0 = no dns lookups */
+extern int     fr_debug_flag;  /* 0 = no debugging information */
+extern int     fr_max_attributes; /* per incoming packet */
+#define        FR_MAX_PACKET_CODE (52)
+extern const char *fr_packet_codes[FR_MAX_PACKET_CODE];
 extern FILE    *fr_log_fp;
 void           fr_printf_log(const char *, ...)
 #ifdef __GNUC__
@@ -467,6 +496,14 @@ void *fr_fifo_pop(fr_fifo_t *fi);
 void *fr_fifo_peek(fr_fifo_t *fi);
 int fr_fifo_num_elements(fr_fifo_t *fi);
 
+#ifdef __cplusplus
+}
+#endif
+
 #include <freeradius-devel/packet.h>
 
+#ifdef WITH_TCP
+#include <freeradius-devel/tcp.h>
+#endif
+
 #endif /*LIBRADIUS_H*/