2
Original copyright header listed below. This comes via rsync.
3
Any additional changes are provided via the same license as the original.
5
Copyright (C) 2011 Muhammad Umair
9
* Copyright (C) 1996-2001 Internet Software Consortium.
11
* Permission to use, copy, modify, and distribute this software for any
12
* purpose with or without fee is hereby granted, provided that the above
13
* copyright notice and this permission notice appear in all copies.
15
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
16
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
18
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
19
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
20
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
22
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27
#include <drizzled/error.h>
28
#include <drizzled/charset.h>
29
#include <drizzled/function/str/strfunc.h>
30
#include <drizzled/item/func.h>
31
#include <drizzled/plugin/function.h>
33
#include <drizzled/type/ipv6.h>
38
class Generate: public drizzled::Item_str_func
41
Generate(): drizzled::Item_str_func() {}
42
void fix_length_and_dec()
44
max_length= (drizzled::type::IPv6::IPV6_BUFFER_LENGTH) * drizzled::system_charset_info->mbmaxlen;
46
const char *func_name() const{ return "ipv6"; }
47
drizzled::String *val_str(drizzled::String *);
51
drizzled::String *Generate::val_str(drizzled::String *str)
53
drizzled::String _result;
54
drizzled::String *result= val_str(&_result);
55
drizzled::type::IPv6 ptr_address;
57
if (not ptr_address.inet_pton(result->c_str()))
59
drizzled::my_error(drizzled::ER_INVALID_IPV6_VALUE, MYF(ME_FATALERROR));
66
str->realloc(drizzled::type::IPv6::IPV6_BUFFER_LENGTH);
67
str->length(drizzled::type::IPv6::IPV6_BUFFER_LENGTH);
68
str->set_charset(drizzled::system_charset_info);
69
ipv6_string= (char *) str->ptr();
71
if (not ptr_address.inet_ntop(ipv6_string))
73
drizzled::my_error(drizzled::ER_INVALID_IPV6_VALUE, MYF(ME_FATALERROR));
78
str->length(max_length);
86
static int initialize(drizzled::module::Context &context)
88
context.add(new drizzled::plugin::Create_function<plugin::ipv6::Generate>("ipv6"));
93
DRIZZLE_DECLARE_PLUGIN
100
drizzled::PLUGIN_LICENSE_GPL,
101
initialize, /* Plugin Init */
103
NULL /* config options */
105
DRIZZLE_DECLARE_PLUGIN_END;