00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <config.h>
00026
00027 #include <drizzled/error.h>
00028 #include <drizzled/charset.h>
00029 #include <drizzled/function/str/strfunc.h>
00030 #include <drizzled/item/func.h>
00031 #include <drizzled/plugin/function.h>
00032
00033 #include <drizzled/type/ipv6.h>
00034
00035 namespace plugin {
00036 namespace ipv6 {
00037
00038 class Generate: public drizzled::Item_str_func
00039 {
00040 public:
00041 Generate(): drizzled::Item_str_func() {}
00042 void fix_length_and_dec()
00043 {
00044 max_length= (drizzled::type::IPv6::IPV6_BUFFER_LENGTH) * drizzled::system_charset_info->mbmaxlen;
00045 }
00046 const char *func_name() const{ return "ipv6"; }
00047 drizzled::String *val_str(drizzled::String *);
00048 };
00049
00050
00051 drizzled::String *Generate::val_str(drizzled::String *str)
00052 {
00053 drizzled::String _result;
00054 drizzled::String *result= val_str(&_result);
00055 drizzled::type::IPv6 ptr_address;
00056
00057 if (not ptr_address.inet_pton(result->c_str()))
00058 {
00059 drizzled::my_error(drizzled::ER_INVALID_IPV6_VALUE, MYF(ME_FATALERROR));
00060 str->length(0);
00061
00062 return str;
00063 }
00064
00065 char *ipv6_string;
00066 str->realloc(drizzled::type::IPv6::IPV6_BUFFER_LENGTH);
00067 str->length(drizzled::type::IPv6::IPV6_BUFFER_LENGTH);
00068 str->set_charset(drizzled::system_charset_info);
00069 ipv6_string= (char *) str->ptr();
00070
00071 if (not ptr_address.inet_ntop(ipv6_string))
00072 {
00073 drizzled::my_error(drizzled::ER_INVALID_IPV6_VALUE, MYF(ME_FATALERROR));
00074 str->length(0);
00075
00076 return str;
00077 }
00078 str->length(max_length);
00079
00080 return str;
00081 }
00082
00083 }
00084 }
00085
00086 static int initialize(drizzled::module::Context &context)
00087 {
00088 context.add(new drizzled::plugin::Create_function<plugin::ipv6::Generate>("ipv6"));
00089
00090 return 0;
00091 }
00092
00093 DRIZZLE_DECLARE_PLUGIN
00094 {
00095 DRIZZLE_VERSION_ID,
00096 "ipv6",
00097 "1.0",
00098 "Muhammad Umair",
00099 "IPV6() function",
00100 drizzled::PLUGIN_LICENSE_GPL,
00101 initialize,
00102 NULL,
00103 NULL
00104 }
00105 DRIZZLE_DECLARE_PLUGIN_END;