static int32_t init_oscam_ser_device(struct s_client *cl) { char *device = cl->serialdata->oscam_ser_device; speed_t baud = cl->serialdata->oscam_ser_baud; int32_t port = cl->serialdata->oscam_ser_port; int32_t fd; // network connection to a TCP-exposed serial port if (port > 0) { cs_strncpy(cl->reader->device, device, sizeof(cl->reader->device)); cl->reader->r_port = cl->port = port; fd = network_tcp_connection_open(cl->reader); if (fd < 0) return 0; else return fd; } else // standard serial port connection { fd=open(device, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK); if (fd>0) { fcntl(fd, F_SETFL, 0); if (oscam_ser_set_serial_device(fd, baud)<0) cs_log("ERROR ioctl"); if (tcflush(fd, TCIOFLUSH)<0) cs_log("ERROR flush"); } else { fd=0; cs_log("ERROR opening %s (errno=%d %s)", device, errno, strerror(errno)); } return(fd); } }
int32_t ghttp_client_init(struct s_client *cl) { int32_t handle; cs_log("%s: init cache client %s:%d (fd=%d)", cl->reader->label, cl->reader->device, cl->reader->r_port, cl->udp_fd); handle = network_tcp_connection_open(cl->reader); if(handle < 0) return -1; cl->reader->tcp_connected = 2; cl->reader->card_status = CARD_INSERTED; cl->reader->last_g = cl->reader->last_s = time((time_t *)0); cl->pfd = cl->udp_fd; if(!cl->ghttp) { if(!cs_malloc(&(cl->ghttp), sizeof (s_ghttp))) return -1; } memset(cl->ghttp, 0, sizeof (s_ghttp)); cs_debug_mask(D_CLIENT, "%s: last_s=%ld, last_g=%ld", cl->reader->label, cl->reader->last_s, cl->reader->last_g); return 0; }
int32_t radegast_cli_init(struct s_client *cl) { int32_t handle; cs_log("radegast: proxy %s:%d (fd=%d)", cl->reader->device, cl->reader->r_port, cl->udp_fd); handle = network_tcp_connection_open(cl->reader); if(handle < 0) return -1; cl->reader->tcp_connected = 2; cl->reader->card_status = CARD_INSERTED; cl->reader->last_g = cl->reader->last_s = time((time_t *)0); cs_debug_mask(D_CLIENT, "radegast: last_s=%ld, last_g=%ld", cl->reader->last_s, cl->reader->last_g); cl->pfd=cl->udp_fd; return(0); }
int32_t ghttp_client_init(struct s_client *cl) { int32_t handle; char *str = NULL; if(cl->reader->r_port == 0) { cl->reader->r_port = cl->reader->ghttp_use_ssl ? 443 : 80; } str = strstr(cl->reader->device, "."); if(!str) { char host[128]; cs_strncpy(host, cl->reader->device, sizeof(cl->reader->device)); snprintf(cl->reader->device, sizeof(cl->reader->device), "%s.appspot.com", host); } cs_log("%s: init google cache client %s:%d (fd=%d)", cl->reader->label, cl->reader->device, cl->reader->r_port, cl->udp_fd); if(cl->udp_fd) { network_tcp_connection_close(cl->reader, "re-init"); } handle = network_tcp_connection_open(cl->reader); if(handle < 0) { return -1; } cl->reader->tcp_connected = 2; cl->reader->card_status = CARD_INSERTED; cl->reader->last_g = cl->reader->last_s = time((time_t *)0); cl->pfd = cl->udp_fd; if(!cl->ghttp) { if(!cs_malloc(&(cl->ghttp), sizeof(s_ghttp))) { return -1; } memset(cl->ghttp, 0, sizeof(s_ghttp)); ((s_ghttp *)cl->ghttp)->post_contexts = ll_create("post contexts"); ((s_ghttp *)cl->ghttp)->ecm_q = ll_create("ecm queue"); } else { ll_clear(((s_ghttp *)cl->ghttp)->ecm_q); } if(cl->reader->ghttp_use_ssl) { #ifndef WITH_SSL cs_log("%s: use_ssl set but no ssl support available, aborting...", cl->reader->label); return -1; #endif #ifdef WITH_SSL if(ghttp_ssl_context == NULL) { return -1; } if(_ssl_connect(cl, handle)) { cl->crypted = 1; } else { network_tcp_connection_close(cl->reader, "ssl failed"); return -1; } #endif } return 0; }
int32_t radegast_cli_init(struct s_client *cl) { *cl = *cl; //prevent compiler warning struct sockaddr_in loc_sa; int32_t handle; cur_client()->pfd=0; if (cur_client()->reader->r_port<=0) { cs_log("radegast: invalid port %d for server %s", cur_client()->reader->r_port, cur_client()->reader->device); return(1); } cur_client()->ip=0; memset((char *)&loc_sa,0,sizeof(loc_sa)); loc_sa.sin_family = AF_INET; #ifdef LALL if (cfg.serverip[0]) loc_sa.sin_addr.s_addr = inet_addr(cfg.serverip); else #endif loc_sa.sin_addr.s_addr = INADDR_ANY; loc_sa.sin_port = htons(cur_client()->reader->l_port); if ((cur_client()->udp_fd=socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))<0) { cs_log("radegast: Socket creation failed (errno=%d %s)", errno, strerror(errno)); cs_exit(1); } #ifdef SO_PRIORITY if (cfg.netprio) setsockopt(cur_client()->udp_fd, SOL_SOCKET, SO_PRIORITY, (void *)&cfg.netprio, sizeof(uintptr_t)); #endif if (!cur_client()->reader->tcp_ito) { uint32_t keep_alive = cur_client()->reader->tcp_ito?1:0; setsockopt(cur_client()->udp_fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keep_alive, sizeof(uintptr_t)); } memset((char *)&cur_client()->udp_sa,0,sizeof(cur_client()->udp_sa)); cur_client()->udp_sa.sin_family = AF_INET; cur_client()->udp_sa.sin_port = htons((uint16_t)cur_client()->reader->r_port); cs_log("radegast: proxy %s:%d (fd=%d)", cur_client()->reader->device, cur_client()->reader->r_port, cur_client()->udp_fd); handle = network_tcp_connection_open(); if(handle < 0) return -1; cur_client()->reader->tcp_connected = 2; cur_client()->reader->card_status = CARD_INSERTED; cur_client()->reader->last_g = cur_client()->reader->last_s = time((time_t *)0); cs_debug_mask(D_CLIENT, "radegast: last_s=%d, last_g=%d", cur_client()->reader->last_s, cur_client()->reader->last_g); cur_client()->pfd=cur_client()->udp_fd; return(0); }