Drizzled Public API Documentation

ipv6_function.cc
1 /*
2  Original copyright header listed below. This comes via rsync.
3  Any additional changes are provided via the same license as the original.
4 
5  Copyright (C) 2011 Muhammad Umair
6 
7 */
8 /*
9  * Copyright (C) 1996-2001 Internet Software Consortium.
10  *
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.
14  *
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.
23  */
24 
25 #include <config.h>
26 
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>
32 
33 #include <drizzled/type/ipv6.h>
34 
35 namespace plugin {
36 namespace ipv6 {
37 
39 {
40 public:
42  void fix_length_and_dec()
43  {
44  max_length= (drizzled::type::IPv6::IPV6_BUFFER_LENGTH) * drizzled::system_charset_info->mbmaxlen;
45  }
46  const char *func_name() const{ return "ipv6"; }
48 };
49 
50 
52 {
53  drizzled::String _result;
54  drizzled::String *result= val_str(&_result);
55  drizzled::type::IPv6 ptr_address;
56 
57  if (not ptr_address.inet_pton(result->c_str()))
58  {
59  drizzled::my_error(drizzled::ER_INVALID_IPV6_VALUE, MYF(ME_FATALERROR));
60  str->length(0);
61 
62  return str;
63  }
64 
65  char *ipv6_string;
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();
70 
71  if (not ptr_address.inet_ntop(ipv6_string))
72  {
73  drizzled::my_error(drizzled::ER_INVALID_IPV6_VALUE, MYF(ME_FATALERROR));
74  str->length(0);
75 
76  return str;
77  }
78  str->length(max_length);
79 
80  return str;
81 }
82 
83 } // namespace ipv6
84 } // namespace plugin
85 
86 static int initialize(drizzled::module::Context &context)
87 {
89 
90  return 0;
91 }
92 
93 DRIZZLE_DECLARE_PLUGIN
94 {
95  DRIZZLE_VERSION_ID,
96  "ipv6",
97  "1.0",
98  "Muhammad Umair",
99  N_("IPV6 function"),
100  drizzled::PLUGIN_LICENSE_GPL,
101  initialize,
102  NULL,
103  NULL
104 }
105 DRIZZLE_DECLARE_PLUGIN_END;
Definition: engine.cc:41
drizzled::String * val_str(drizzled::String *)