added String::truncate() and related functions.
started adding radius dictionary file reader. incomplete yet
This commit is contained in:
parent
25e49a4526
commit
211f5b014e
@ -423,6 +423,51 @@ public:
|
||||
return SelfType (this->_item->buffer + index, size);
|
||||
}
|
||||
|
||||
void truncate (qse_size_t new_size)
|
||||
{
|
||||
// use this function with care.
|
||||
// if the new size is greater than the current capacity,
|
||||
// it grows the capacity first according to the policy.
|
||||
// in such a case, it still changes the length.
|
||||
// if the new size is equal to or less than the current capaciy,
|
||||
// it only changes the length.
|
||||
// when chaning the length, it puts a null character at
|
||||
// the length position. it leaves the contents of the growing
|
||||
// part or the shrinking part untouched.
|
||||
//
|
||||
// if you want to shorten the length while growing the capacity,
|
||||
// you can call truncate twice. for instance,
|
||||
// str.truncate (1000).
|
||||
// str.truncate (100).
|
||||
|
||||
StringItem* old_item = QSE_NULL;
|
||||
|
||||
if (this->_item->isShared())
|
||||
{
|
||||
StringItem* t;
|
||||
|
||||
if (new_size > this->_item->capacity)
|
||||
t = this->_item->copy (this->getMmgr(), this->adjust_desired_capacity(new_size));
|
||||
else
|
||||
t = this->_item->copy (this->getMmgr());
|
||||
|
||||
old_item = this->_item;
|
||||
this->_item = t;
|
||||
this->ref_item ();
|
||||
}
|
||||
else if (new_size > this->_item->capacity)
|
||||
{
|
||||
StringItem* t = this->_item->copy (this->getMmgr(), this->adjust_desired_capacity(new_size));
|
||||
old_item = this->_item;
|
||||
this->_item = t;
|
||||
this->ref_item ();;
|
||||
}
|
||||
|
||||
this->_item->buffer[new_size] = NULL_CHAR;
|
||||
this->_item->size = new_size;
|
||||
if (old_item) this->deref_item (old_item);
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: comparison, hash, trim, case-converting, etc
|
||||
// utf-8 encoding/decoding
|
||||
|
@ -1,5 +1,6 @@
|
||||
pkgincludedir = $(includedir)/qse/rad
|
||||
|
||||
pkginclude_HEADERS = \
|
||||
raddic.h \
|
||||
radmsg.h
|
||||
|
||||
|
@ -357,6 +357,7 @@ top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
pkginclude_HEADERS = \
|
||||
raddic.h \
|
||||
radmsg.h
|
||||
|
||||
all: all-am
|
||||
|
79
qse/include/qse/rad/raddic.h
Normal file
79
qse/include/qse/rad/raddic.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_RAD_RADDIC_H_
|
||||
#define _QSE_RAD_RADDIC_H_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
#define QSE_RAD_ATTR_TYPE_STRING 0
|
||||
#define QSE_RAD_ATTR_TYPE_INTEGER 1
|
||||
#define QSE_RAD_ATTR_TYPE_IPADDR 2
|
||||
#define QSE_RAD_ATTR_TYPE_DATE 3
|
||||
#define QSE_RAD_ATTR_TYPE_ABINARY 4
|
||||
#define QSE_RAD_ATTR_TYPE_OCTETS 5
|
||||
#define QSE_RAD_ATTR_TYPE_IFID 6
|
||||
#define QSE_RAD_ATTR_TYPE_IPV6ADDR 7
|
||||
#define QSE_RAD_ATTR_TYPE_IPV6PREFIX 8
|
||||
#define QSE_RAD_ATTR_TYPE_BYTE 9
|
||||
#define QSE_RAD_ATTR_TYPE_SHORT 10
|
||||
#define QSE_RAD_ATTR_TYPE_ETHERNET 11
|
||||
#define QSE_RAD_ATTR_TYPE_SIGNED 12
|
||||
#define QSE_RAD_ATTR_TYPE_COMBO_IP 13
|
||||
#define QSE_RAD_ATTR_TYPE_TLV 14
|
||||
|
||||
struct qse_raddic_attr_t
|
||||
{
|
||||
int attr;
|
||||
int type;
|
||||
int vendor;
|
||||
/* ATTR_FLAGS flags;*/
|
||||
char name[1];
|
||||
};
|
||||
typedef struct qse_raddic_attr_t qse_raddic_attr_t;
|
||||
|
||||
typedef struct qse_raddic_t qse_raddic_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
QSE_EXPORT qse_raddic_t* qse_raddic_open (
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_size_t xtnsize
|
||||
);
|
||||
|
||||
QSE_EXPORT void qse_raddic_close (
|
||||
qse_raddic_t* dic
|
||||
);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -229,7 +229,7 @@ QSE_EXPORT int qse_rad_delete_attribute (
|
||||
QSE_EXPORT int qse_rad_delete_vendor_specific_attribute (
|
||||
qse_rad_hdr_t* hdr,
|
||||
qse_uint32_t vendor,
|
||||
qse_uint8_t id
|
||||
qse_uint8_t attrid
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_rad_insert_string_attribute (
|
||||
@ -284,7 +284,7 @@ QSE_EXPORT int qse_rad_insert_ipv6prefix_attribute (
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_rad_insert_giga_attribute (
|
||||
qse_rad_hdr_t* auth,
|
||||
qse_rad_hdr_t* auth,
|
||||
int max,
|
||||
qse_uint32_t vendor,
|
||||
int low_id,
|
||||
@ -293,7 +293,7 @@ QSE_EXPORT int qse_rad_insert_giga_attribute (
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_rad_set_user_password (
|
||||
qse_rad_hdr_t* auth,
|
||||
qse_rad_hdr_t* auth,
|
||||
int max,
|
||||
const qse_mchar_t* password,
|
||||
const qse_mchar_t* secret
|
||||
@ -309,7 +309,7 @@ QSE_EXPORT void qse_rad_copy_authenticator (
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_rad_set_authenticator (
|
||||
qse_rad_hdr_t* req,
|
||||
qse_rad_hdr_t* req,
|
||||
const qse_mchar_t* secret
|
||||
);
|
||||
|
||||
@ -319,14 +319,14 @@ QSE_EXPORT int qse_rad_set_authenticator (
|
||||
* so this function doesn't apply
|
||||
*/
|
||||
QSE_EXPORT int qse_rad_verify_request (
|
||||
qse_rad_hdr_t* req,
|
||||
qse_rad_hdr_t* req,
|
||||
const qse_mchar_t* secret
|
||||
);
|
||||
|
||||
QSE_EXPORT int qse_rad_verify_response (
|
||||
qse_rad_hdr_t* res,
|
||||
const qse_rad_hdr_t* req,
|
||||
const qse_mchar_t* secret
|
||||
const qse_mchar_t* secret
|
||||
);
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ AM_CPPFLAGS = \
|
||||
|
||||
lib_LTLIBRARIES = libqserad.la
|
||||
libqserad_la_SOURCES = \
|
||||
raddic.c \
|
||||
radmsg.c
|
||||
|
||||
libqserad_la_CFLAGS =
|
||||
|
@ -135,7 +135,8 @@ am__uninstall_files_from_dir = { \
|
||||
am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libqserad_la_DEPENDENCIES =
|
||||
am_libqserad_la_OBJECTS = libqserad_la-radmsg.lo
|
||||
am_libqserad_la_OBJECTS = libqserad_la-raddic.lo \
|
||||
libqserad_la-radmsg.lo
|
||||
libqserad_la_OBJECTS = $(am_libqserad_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
@ -396,6 +397,7 @@ AM_CPPFLAGS = \
|
||||
#noinst_HEADERS =
|
||||
lib_LTLIBRARIES = libqserad.la
|
||||
libqserad_la_SOURCES = \
|
||||
raddic.c \
|
||||
radmsg.c
|
||||
|
||||
libqserad_la_CFLAGS =
|
||||
@ -479,6 +481,7 @@ mostlyclean-compile:
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqserad_la-raddic.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libqserad_la-radmsg.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@ -502,6 +505,13 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
libqserad_la-raddic.lo: raddic.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqserad_la_CFLAGS) $(CFLAGS) -MT libqserad_la-raddic.lo -MD -MP -MF $(DEPDIR)/libqserad_la-raddic.Tpo -c -o libqserad_la-raddic.lo `test -f 'raddic.c' || echo '$(srcdir)/'`raddic.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libqserad_la-raddic.Tpo $(DEPDIR)/libqserad_la-raddic.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='raddic.c' object='libqserad_la-raddic.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqserad_la_CFLAGS) $(CFLAGS) -c -o libqserad_la-raddic.lo `test -f 'raddic.c' || echo '$(srcdir)/'`raddic.c
|
||||
|
||||
libqserad_la-radmsg.lo: radmsg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libqserad_la_CFLAGS) $(CFLAGS) -MT libqserad_la-radmsg.lo -MD -MP -MF $(DEPDIR)/libqserad_la-radmsg.Tpo -c -o libqserad_la-radmsg.lo `test -f 'radmsg.c' || echo '$(srcdir)/'`radmsg.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libqserad_la-radmsg.Tpo $(DEPDIR)/libqserad_la-radmsg.Plo
|
||||
|
2285
qse/lib/rad/raddic.c
Normal file
2285
qse/lib/rad/raddic.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user