1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = GNetworkAddress.html 27 * outPack = gio 28 * outFile = NetworkAddress 29 * strct = GNetworkAddress 30 * realStrct= 31 * ctorStrct=GSocketConnectable 32 * clss = NetworkAddress 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * - SocketConnectableIF 40 * prefixes: 41 * - g_network_address_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * - g_network_address_parse 46 * omit signals: 47 * imports: 48 * - glib.Str 49 * - glib.ErrorG 50 * - glib.GException 51 * - gio.SocketConnectable 52 * - gio.SocketConnectableIF 53 * - gio.SocketConnectableT 54 * structWrap: 55 * - GSocketConnectable* -> SocketConnectableIF 56 * module aliases: 57 * local aliases: 58 * overrides: 59 */ 60 61 module gio.NetworkAddress; 62 63 public import gtkc.giotypes; 64 65 private import gtkc.gio; 66 private import glib.ConstructionException; 67 private import gobject.ObjectG; 68 69 70 private import glib.Str; 71 private import glib.ErrorG; 72 private import glib.GException; 73 private import gio.SocketConnectable; 74 private import gio.SocketConnectableIF; 75 private import gio.SocketConnectableT; 76 77 78 79 private import gobject.ObjectG; 80 81 /** 82 * GNetworkAddress provides an easy way to resolve a hostname and 83 * then attempt to connect to that host, handling the possibility of 84 * multiple IP addresses and multiple address families. 85 * 86 * See GSocketConnectable for and example of using the connectable 87 * interface. 88 */ 89 public class NetworkAddress : ObjectG, SocketConnectableIF 90 { 91 92 /** the main Gtk struct */ 93 protected GNetworkAddress* gNetworkAddress; 94 95 96 public GNetworkAddress* getNetworkAddressStruct() 97 { 98 return gNetworkAddress; 99 } 100 101 102 /** the main Gtk struct as a void* */ 103 protected override void* getStruct() 104 { 105 return cast(void*)gNetworkAddress; 106 } 107 108 /** 109 * Sets our main struct and passes it to the parent class 110 */ 111 public this (GNetworkAddress* gNetworkAddress) 112 { 113 super(cast(GObject*)gNetworkAddress); 114 this.gNetworkAddress = gNetworkAddress; 115 } 116 117 protected override void setStruct(GObject* obj) 118 { 119 super.setStruct(obj); 120 gNetworkAddress = cast(GNetworkAddress*)obj; 121 } 122 123 // add the SocketConnectable capabilities 124 mixin SocketConnectableT!(GNetworkAddress); 125 126 /** 127 * Creates a new GSocketConnectable for connecting to the given 128 * hostname and port. May fail and return NULL in case 129 * parsing host_and_port fails. 130 * host_and_port may be in any of a number of recognised formats: an IPv6 131 * address, an IPv4 address, or a domain name (in which case a DNS 132 * lookup is performed). Quoting with [] is supported for all address 133 * types. A port override may be specified in the usual way with a 134 * colon. Ports may be given as decimal numbers or symbolic names (in 135 * which case an /etc/services lookup is performed). 136 * If no port is specified in host_and_port then default_port will be 137 * used as the port number to connect to. 138 * In general, host_and_port is expected to be provided by the user 139 * (allowing them to give the hostname, and a port overide if necessary) 140 * and default_port is expected to be provided by the application. 141 * Since 2.22 142 * Params: 143 * hostAndPort = the hostname and optionally a port 144 * defaultPort = the default port if not in host_and_port 145 * Returns: the new GNetworkAddress, or NULL on error 146 * Throws: GException on failure. 147 */ 148 public static SocketConnectableIF parse(string hostAndPort, ushort defaultPort) 149 { 150 // GSocketConnectable * g_network_address_parse (const gchar *host_and_port, guint16 default_port, GError **error); 151 GError* err = null; 152 153 auto p = g_network_address_parse(Str.toStringz(hostAndPort), defaultPort, &err); 154 155 if (err !is null) 156 { 157 throw new GException( new ErrorG(err) ); 158 } 159 160 if(p is null) 161 { 162 return null; 163 } 164 return new NetworkAddress(cast(GNetworkAddress*) p); 165 } 166 167 /** 168 */ 169 170 /** 171 * Creates a new GSocketConnectable for connecting to the given 172 * hostname and port. 173 * Since 2.22 174 * Params: 175 * hostname = the hostname 176 * port = the port 177 * Throws: ConstructionException GTK+ fails to create the object. 178 */ 179 public this (string hostname, ushort port) 180 { 181 // GSocketConnectable * g_network_address_new (const gchar *hostname, guint16 port); 182 auto p = g_network_address_new(Str.toStringz(hostname), port); 183 if(p is null) 184 { 185 throw new ConstructionException("null returned by g_network_address_new(Str.toStringz(hostname), port)"); 186 } 187 this(cast(GNetworkAddress*) p); 188 } 189 190 /** 191 * Gets addr's hostname. This might be either UTF-8 or ASCII-encoded, 192 * depending on what addr was created with. 193 * Since 2.22 194 * Returns: addr's hostname 195 */ 196 public string getHostname() 197 { 198 // const gchar * g_network_address_get_hostname (GNetworkAddress *addr); 199 return Str.toString(g_network_address_get_hostname(gNetworkAddress)); 200 } 201 202 /** 203 * Gets addr's port number 204 * Since 2.22 205 * Returns: addr's port (which may be 0) 206 */ 207 public ushort getPort() 208 { 209 // guint16 g_network_address_get_port (GNetworkAddress *addr); 210 return g_network_address_get_port(gNetworkAddress); 211 } 212 213 /** 214 * Gets addr's scheme 215 * Since 2.26 216 * Returns: addr's scheme (NULL if not built from URI) 217 */ 218 public string getScheme() 219 { 220 // const gchar * g_network_address_get_scheme (GNetworkAddress *addr); 221 return Str.toString(g_network_address_get_scheme(gNetworkAddress)); 222 } 223 224 /** 225 * Creates a new GSocketConnectable for connecting to the given 226 * uri. May fail and return NULL in case parsing uri fails. 227 * Using this rather than g_network_address_new() or 228 * g_network_address_parse() allows GSocketClient to determine 229 * when to use application-specific proxy protocols. 230 * Since 2.26 231 * Params: 232 * uri = the hostname and optionally a port 233 * defaultPort = The default port if none is found in the URI 234 * Returns: the new GNetworkAddress, or NULL on error. [transfer full] 235 * Throws: GException on failure. 236 */ 237 public static SocketConnectableIF parseUri(string uri, ushort defaultPort) 238 { 239 // GSocketConnectable * g_network_address_parse_uri (const gchar *uri, guint16 default_port, GError **error); 240 GError* err = null; 241 242 auto p = g_network_address_parse_uri(Str.toStringz(uri), defaultPort, &err); 243 244 if (err !is null) 245 { 246 throw new GException( new ErrorG(err) ); 247 } 248 249 250 if(p is null) 251 { 252 return null; 253 } 254 255 return ObjectG.getDObject!(SocketConnectable, SocketConnectableIF)(cast(GSocketConnectable*) p); 256 } 257 }