Commit 699d861e0003b48969273696d5000072986699e8
1 parent
efb25644
Exists in
master
and in
3 other branches
Still refactoring network modules.
Showing
4 changed files
with
47 additions
and
38 deletions
Show diff stats
src/core/host.c
| @@ -62,6 +62,7 @@ | @@ -62,6 +62,7 @@ | ||
| 62 | #include <lib3270/trace.h> | 62 | #include <lib3270/trace.h> |
| 63 | #include <lib3270/toggle.h> | 63 | #include <lib3270/toggle.h> |
| 64 | #include <lib3270/keyboard.h> | 64 | #include <lib3270/keyboard.h> |
| 65 | +#include <networking.h> | ||
| 65 | 66 | ||
| 66 | /** | 67 | /** |
| 67 | * @brief Called from timer to attempt an automatic reconnection. | 68 | * @brief Called from timer to attempt an automatic reconnection. |
| @@ -368,6 +369,7 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) | @@ -368,6 +369,7 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) | ||
| 368 | if(!n) | 369 | if(!n) |
| 369 | return errno = ENOENT; | 370 | return errno = ENOENT; |
| 370 | 371 | ||
| 372 | +/* | ||
| 371 | static const struct _sch | 373 | static const struct _sch |
| 372 | { | 374 | { |
| 373 | char ssl; | 375 | char ssl; |
| @@ -386,37 +388,21 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) | @@ -386,37 +388,21 @@ LIB3270_EXPORT int lib3270_set_url(H3270 *h, const char *n) | ||
| 386 | { 0, "telnet://", "telnet" } | 388 | { 0, "telnet://", "telnet" } |
| 387 | 389 | ||
| 388 | }; | 390 | }; |
| 389 | - | 391 | +*/ |
| 390 | lib3270_autoptr(char) str = strdup(n); | 392 | lib3270_autoptr(char) str = strdup(n); |
| 391 | - char * hostname = str; | ||
| 392 | - const char * srvc = "telnet"; | 393 | + char * hostname = lib3270_set_network_module_from_url(h,str); |
| 394 | + const char * srvc; | ||
| 393 | char * ptr; | 395 | char * ptr; |
| 394 | char * query = ""; | 396 | char * query = ""; |
| 395 | int f; | 397 | int f; |
| 396 | 398 | ||
| 397 | trace("%s(%s)",__FUNCTION__,str); | 399 | trace("%s(%s)",__FUNCTION__,str); |
| 398 | 400 | ||
| 399 | -#ifdef HAVE_LIBSSLx | ||
| 400 | - h->ssl.enabled = 0; | ||
| 401 | -#endif // HAVE_LIBSSL | ||
| 402 | - | ||
| 403 | - for(f=0;f < sizeof(sch)/sizeof(sch[0]);f++) | ||
| 404 | - { | ||
| 405 | - size_t sz = strlen(sch[f].text); | ||
| 406 | - if(!strncasecmp(hostname,sch[f].text,sz)) | ||
| 407 | - { | ||
| 408 | -#ifdef HAVE_LIBSSLx | ||
| 409 | - h->ssl.enabled = sch[f].ssl; | ||
| 410 | -#endif // HAVE_LIBSSL | ||
| 411 | - srvc = sch[f].srvc; | ||
| 412 | - hostname += sz; | ||
| 413 | - break; | ||
| 414 | - } | ||
| 415 | - } | ||
| 416 | - | ||
| 417 | - if(!*hostname) | 401 | + if(!(hostname && *hostname)) |
| 418 | return 0; | 402 | return 0; |
| 419 | 403 | ||
| 404 | + srvc = h->network.module->service; | ||
| 405 | + | ||
| 420 | ptr = strchr(hostname,':'); | 406 | ptr = strchr(hostname,':'); |
| 421 | if(ptr) | 407 | if(ptr) |
| 422 | { | 408 | { |
src/include/networking.h
| @@ -190,6 +190,14 @@ | @@ -190,6 +190,14 @@ | ||
| 190 | LIB3270_INTERNAL int lib3270_network_send_failed(H3270 *hSession); | 190 | LIB3270_INTERNAL int lib3270_network_send_failed(H3270 *hSession); |
| 191 | 191 | ||
| 192 | /** | 192 | /** |
| 193 | + * @breif Select the network context from URL. | ||
| 194 | + * | ||
| 195 | + * @return Pointer to the hostname or NULL if failed (sets errno). | ||
| 196 | + * | ||
| 197 | + */ | ||
| 198 | + LIB3270_INTERNAL const char * lib3270_set_network_module_from_url(H3270 *hSession, const char *url); | ||
| 199 | + | ||
| 200 | + /** | ||
| 193 | * @brief Select the default (unsecure) network context. | 201 | * @brief Select the default (unsecure) network context. |
| 194 | * | 202 | * |
| 195 | * @param hSession TN3270 Session handle. | 203 | * @param hSession TN3270 Session handle. |
src/network_modules/default/main.c
| @@ -87,8 +87,6 @@ | @@ -87,8 +87,6 @@ | ||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | static int unsecure_network_getsockname(const H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) { | 89 | static int unsecure_network_getsockname(const H3270 *hSession, struct sockaddr *addr, socklen_t *addrlen) { |
| 90 | - if(hSession->network.context->sock < 0) | ||
| 91 | - return -(errno = ENOTCONN); | ||
| 92 | return getsockname(hSession->network.context->sock, addr, addrlen); | 90 | return getsockname(hSession->network.context->sock, addr, addrlen); |
| 93 | } | 91 | } |
| 94 | 92 | ||
| @@ -160,27 +158,14 @@ static int unsecure_network_is_connected(const H3270 *hSession) { | @@ -160,27 +158,14 @@ static int unsecure_network_is_connected(const H3270 *hSession) { | ||
| 160 | } | 158 | } |
| 161 | 159 | ||
| 162 | static int unsecure_network_setsockopt(H3270 *hSession, int level, int optname, const void *optval, size_t optlen) { | 160 | static int unsecure_network_setsockopt(H3270 *hSession, int level, int optname, const void *optval, size_t optlen) { |
| 163 | - | ||
| 164 | - if(hSession->network.context->sock < 0) { | ||
| 165 | - errno = ENOTCONN; | ||
| 166 | - return -1; | ||
| 167 | - } | ||
| 168 | - | ||
| 169 | return setsockopt(hSession->network.context->sock, level, optname, optval, optlen); | 161 | return setsockopt(hSession->network.context->sock, level, optname, optval, optlen); |
| 170 | - | ||
| 171 | } | 162 | } |
| 172 | 163 | ||
| 173 | static int unsecure_network_getsockopt(H3270 *hSession, int level, int optname, void *optval, socklen_t *optlen) { | 164 | static int unsecure_network_getsockopt(H3270 *hSession, int level, int optname, void *optval, socklen_t *optlen) { |
| 174 | - | ||
| 175 | - if(hSession->network.context->sock < 0) { | ||
| 176 | - errno = ENOTCONN; | ||
| 177 | - return -1; | ||
| 178 | - } | ||
| 179 | - | ||
| 180 | return getsockopt(hSession->network.context->sock, level, optname, optval, optlen); | 165 | return getsockopt(hSession->network.context->sock, level, optname, optval, optlen); |
| 181 | } | 166 | } |
| 182 | 167 | ||
| 183 | -static int unsecure_network_init(H3270 GNUC_UNUSED(*hSession), LIB3270_NETWORK_STATE GNUC_UNUSED(*state)) { | 168 | +static int unsecure_network_init(H3270 GNUC_UNUSED(*hSession)) { |
| 184 | return 0; | 169 | return 0; |
| 185 | } | 170 | } |
| 186 | 171 |
src/network_modules/select.c
| @@ -35,4 +35,34 @@ | @@ -35,4 +35,34 @@ | ||
| 35 | #include <config.h> | 35 | #include <config.h> |
| 36 | #include <lib3270.h> | 36 | #include <lib3270.h> |
| 37 | #include <lib3270/log.h> | 37 | #include <lib3270/log.h> |
| 38 | + #include <lib3270/trace.h> | ||
| 38 | #include <networking.h> | 39 | #include <networking.h> |
| 40 | + #include <string.h> | ||
| 41 | + | ||
| 42 | + /*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
| 43 | + | ||
| 44 | + const char * lib3270_set_network_module_from_url(H3270 *hSession, const char *url) { | ||
| 45 | + | ||
| 46 | + static const struct { | ||
| 47 | + const char *scheme; ///< @brief URL scheme for module. | ||
| 48 | + void (*activate)(H3270 *hSession); ///< @brief Selection method. | ||
| 49 | + } modules[] = { | ||
| 50 | + | ||
| 51 | + { "tn3270://", lib3270_set_default_network_module }, | ||
| 52 | + | ||
| 53 | + }; | ||
| 54 | + | ||
| 55 | + size_t ix; | ||
| 56 | + | ||
| 57 | + for(ix=0;ix < (sizeof(modules)/sizeof(modules[0])); ix++) { | ||
| 58 | + | ||
| 59 | + size_t len = strlen(modules[ix].scheme); | ||
| 60 | + if(!strncasecmp(url,modules[ix].scheme,len)) { | ||
| 61 | + modules[ix].activate(hSession); | ||
| 62 | + return url+len; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + return NULL; | ||
| 68 | + } |