/* fopn [-m mode] [-t num] fname */ HRESULT CALLBACK fopn(PDEBUG_CLIENT4 Client, PCSTR args) { HRESULT ret=E_FAIL; set_client(Client); flag_desc_t flags_dsc[] = {{'m', TRUE}, {'t', TRUE}, {0}}; size_t rd_sz = read_flags(args, flags_dsc); args += rd_sz; char mode[16] = "r+"; if (flags_dsc[0].is_pres) { memcpy(mode, flags_dsc[0].pc_arg, min(flags_dsc[0].arg_len, sizeof(mode))); mode[sizeof(mode)-1]=0; } char pr_name[MAX_PR_NAME]; if (flags_dsc[1].is_pres) { if (!get_pr_name(&flags_dsc[1], pr_name)) goto finish; } else { /* set default pseudo-reg */ strcpy(pr_name, "$t0"); } if (file_open(args, mode, pr_name)) ret=S_OK; finish: return ret; }
bool init_users(t_server *server) { int i; int j; i = -1; while (++i < 4) { if ((server->user[i] = malloc(sizeof(t_client))) == NULL) { j = -1; while (++j < i) { free(server->user[j]); trantorien_destroy(&server->user[j]->trant); } free(server->user); return (false); } server->client_log += 1; memset(server->user[i], 0, sizeof(t_client)); set_client(server, i); } return (true); }
bool add_client(int fd_socket, t_server *server) { int client_fd; if ((my_accept(&client_fd, fd_socket)) == false) return (false); if (server->client_log == server->client_max && (server->client_max += 1)) if ((server->fd_type = realloc(server->fd_type, sizeof(fd_type) * (server->client_max))) == NULL || (server->exec = realloc(server->exec, sizeof(fptr) * (server->client_max))) == NULL || (server->user = realloc(server->user, sizeof(t_client) * (server->client_max))) == NULL || (server->id_users = realloc(server->id_users, sizeof(int) * (server->client_max))) == NULL) return (false); if ((server->user[client_fd] = malloc(sizeof(t_client))) == NULL) return (false); set_client(server, client_fd); server->fd_type[client_fd] = FD_CLIENT; server->id_users[client_fd] = -1; server->exec[client_fd] = &read_on_client; server->user[client_fd]->id = find_player(server); printf("%s\nPlayer %d connected%s\n", text[GREEN], server->user[client_fd]->id, text[NOCOLOR]); server->client_log += 1; return (reponse_to_client(client_fd, "BIENVENUE\n", server, 10)); }
bool pipe_server_t::do_connect() { for (pipe_client_iter_t i( container->get_clients() ); i; i.next()) { pipe_client_t *pipe_client = i; if (pipe_client->server) continue; set_client( pipe_client ); return true; } return false; }
/* fcls hndl */ HRESULT CALLBACK fcls(PDEBUG_CLIENT4 Client, PCSTR args) { HRESULT ret=E_FAIL; set_client(Client); ULONG64 fh_val; if (!get_expression(args, &fh_val, NULL)) goto finish; if (!fh_val || fclose((FILE*)fh_val)) { err_dbgprintf("File closure error\n"); } else ret=S_OK; finish: return ret; }
/* frdl hndl */ HRESULT CALLBACK frdl(PDEBUG_CLIENT4 Client, PCSTR args) { HRESULT ret=E_FAIL; set_client(Client); ULONG64 fh_val; if (!get_expression(args, &fh_val, &args)) goto finish; if (fh_val) file_rdln((FILE*)fh_val); ret=S_OK; finish: return ret; }
/* fwrt hndl input */ HRESULT CALLBACK fwrt(PDEBUG_CLIENT4 Client, PCSTR args) { HRESULT ret=E_FAIL; set_client(Client); ULONG64 fh_val; if (!get_expression(args, &fh_val, &args)) goto finish; for (; *args && isspace(*args); args++); if (fh_val && file_wrtstr((FILE*)fh_val, args)) ret=S_OK; finish: return ret; }
void command_play_qam(JsmnContext * jc) { localptr(String, player_cmd) = String_value_none(); localptr(String, mux_cmd) = String_value_none(); localptr(String, azap_cmd) = String_value_none(); localptr(String, channel) = String_value_none(); localptr(String, clientid) = String_value_none(); clientid = jsmn_lookup_string(jc, "clientid"); if (String_is_none(clientid)) { fprintf(stderr, "%s: missing clientid\n", __func__); return; } channel = jsmn_lookup_string(jc, "channel"); if (String_is_none(channel)) { fprintf(stderr, "%s: missing channel\n", __func__); return; } /* Verify valid channel. */ if (!Regex_match(s(channel), "^[0-9]+[.][0-9]+$")) { fprintf(stderr, "%s: invalid channel\n", __func__); return; } set_client(clientid); stop_playback_programs(STOP_ALL); /* Start azap. */ azap_cmd = String_sprintf("/platform/rpi/bin/azap.jsg -j azap.json -c azap.conf -q -r %s", s(channel)); bgstart(s(azap_cmd), &playbackState.azap_pid); /* Start muxer. */ mux_cmd = String_sprintf("/platform/rpi/bin/streammux"); bgstart(s(mux_cmd), &playbackState.mux_pid); /* Start player. */ unlink("/tmp/pb.in"); unlink("/tmp/pb.out"); player_cmd = String_sprintf("empty -p empty_omxplayer.pid " "-i /tmp/pb.in -o /tmp/pb.out " "-f /usr/bin/omxplayer tcp://localhost:5102 --layer 1 --lavfdopts probesize:250000"); bgstart(s(player_cmd), &playbackState.player_pid); String_clear(&playbackState.title); playbackState.title = String_dup(channel); playbackState.playing = 1; playbackState.paused = 0; playbackState.recording = 0; }
TFrameWindow::TFrameWindow(pchar caption, TWin *cli, int style, TWin *parent) : TEventWindow(caption,parent,style) { // int SBParts[2]; set_client(cli); #ifdef COMMCTRL /* m_status = CreateStatusWindow(WS_CHILD | WS_BORDER | WS_VISIBLE, "", m_hwnd, 1); if(!m_status) set_text("no status"); SBParts[0] = width()/2; SBParts[1] = -1; SendMessage(m_status,SB_SETPARTS,2,(LPARAM)SBParts); */ m_status = NULL; // for now!! #else m_status = NULL; #endif }
int main(int ac, char **av) { t_client client; set_client(&client); if (ac == 3) { ft_strcpy(client.buff, "/connect "); ft_strcat(client.buff, av[1]); ft_strcat(client.buff, " "); ft_strcat(client.buff, av[2]); command_connect(&client); if (client.sock != -1) main_loop(&client); } while (!client.exit) unlogged_loop(&client); return (0); }
void command_play_url(JsmnContext * jc) { localptr(String, player_cmd) = String_value_none(); localptr(String, clientid) = String_value_none(); localptr(String, url) = String_value_none(); clientid = jsmn_lookup_string(jc, "clientid"); if (String_is_none(clientid)) { fprintf(stderr, "%s: missing clientid\n", __func__); return; } url = jsmn_lookup_string(jc, "url"); if (String_is_none(url)) { fprintf(stderr, "%s: missing url\n", __func__); return; } /* Verify valid url */ //if (!Regex_match((channel), "^...$")) { //fprintf(stderr, "%s: invalid channel\n", __func__); //goto out; //} set_client(clientid); stop_playback_programs(STOP_ALL); /* Start player. */ unlink("/tmp/pb.in"); unlink("/tmp/pb.out"); player_cmd = String_sprintf("empty -p empty_omxplayer.pid" " -i /tmp/pb.in -o /tmp/pb.out" " -f livestreamer -np '/usr/bin/omxplayer --layer 1 --lavfdopts probesize:250000'" " '%s'" " best" , s(url)); // -i /tmp/pb.in -o /tmp/pb.out bgstart(s(player_cmd), &playbackState.player_pid); String_clear(&playbackState.title); playbackState.title = String_dup(url); /* FIXME: Potential XSS vector here when it gets passed back in config? */ playbackState.playing = 1; playbackState.paused = 0; playbackState.recording = 0; }
/* sxtr input/pattern/replacement */ HRESULT CALLBACK sxtr(PDEBUG_CLIENT4 Client, PCSTR args) { HRESULT ret=E_FAIL; set_client(Client); flag_desc_t flags_dsc[] = {{'t', TRUE}, {0}}; size_t rd_sz = read_flags(args, flags_dsc); args += rd_sz; char pr_name[MAX_PR_NAME]; if (flags_dsc[0].is_pres) { if (!get_pr_name(&flags_dsc[0], pr_name)) goto finish; str_extr(args, pr_name); } else { str_extr(args, NULL); } ret=S_OK; finish: return ret; }
/* help info */ HRESULT CALLBACK help(PDEBUG_CLIENT4 Client, PCSTR args) { set_client(Client); dbgprintf( "scriptext: Various scripting utilities\n\n" "sxtr [-t num] input/pattern/replacement\n" " Look for a substring of the input string matching the extended POSIX RE pattern.\n" " If the pattern matches, the substring is extracted and modified according to\n" " the replacement string. The input string may contain alphanumeric characters\n" " plus '_' only, or must be enclosed in '' or \"\". If it's enclosed in [], then\n" " the input string specifies an alias name containing a string to process.\n" " Delimiter character is recognized as the first one after the input string. All\n" " the strings may contain escaped characters.\n" " -t: If specified, provides a pseudo-reg $t number where the matching result\n" " will be set: 0 - not matched, 1 - matched.\n\n" "fopn [-m mode] [-t num] fname\n" " Open a file with a name fname.\n" " -m: Open mode (C standard). \"r+\" by default.\n" " -t: Pseudo-reg $t number where a handle of the opened file will be written. In\n" " case of opening error zero will be written there. If not specified $t0 is\n" " taken.\n" "fwrt hndl input\n" " Write the input string to the file with the handle hndl. If the input string\n" " is enclosed in [] then it specifies an alias name containing a string to write.\n" " The input string may contain escaped characters.\n" "frdl hndl\n" " Read line from a file with the handle hndl. The file shall be opened for read\n" " in the text mode.\n" "fcls hndl\n" " Close a file with a handle hndl.\n\n" "help\n" " Display this help.\n"); return S_OK; }
DWORD APIENTRY WinSock ( LPVOID threadNum ) { // call Socket library (initialize) WSADATA sd; SYSTEMTIME nowtime; WORD ver=0x0101; SOCKET svrSck,sck; DWORD arg; SOCKADDR_IN addr; fd_set rfd,efd; SOCKADDR_IN ad; struct timeval timeout; int len; char szMessage[1000]; client clt; HINSTANCE hInstance = *(HINSTANCE *) threadNum ; HANDLE hThread = NULL ; DWORD ThreadID = 0L ; init_clients(); // Initialize users' list if(WSAStartup(ver,&sd)) { LoadString ( hInstance , IDS_INIT_FAILURE , szMessage , sizeof (szMessage ) ) ; MessageBox ( hCurDlg , szMessage , szCaption , MB_ICONERROR ) ; ExitProcess ( EXIT_FAILURE ) ; } // Create Socket svrSck=socket(AF_INET,SOCK_STREAM,0); if(svrSck==INVALID_SOCKET) { WSACleanup ( ); LoadString ( hInstance , IDS_CREATION_FAILED , szMessage , sizeof ( szMessage ) ) ; MessageBox ( hCurDlg , szMessage , szCaption , MB_ICONERROR ) ; ExitProcess ( EXIT_FAILURE ) ; } // Set Socket running mode arg=1; ioctlsocket(svrSck,FIONBIO,&arg); // Set non-blocking mode // bind addr.sin_family=AF_INET; addr.sin_port=htons(2007); addr.sin_addr.s_addr = htonl(ADDR_ANY); if(bind(svrSck,(SOCKADDR*)&addr,sizeof(SOCKADDR)) == SOCKET_ERROR) { shutdown(svrSck,SD_BOTH); closesocket(svrSck); WSACleanup(); LoadString ( hInstance , IDS_BIND_FAILED , szMessage , sizeof ( szMessage ) ) ; MessageBox ( hCurDlg , szMessage , szCaption , MB_ICONERROR ) ; ExitProcess ( EXIT_FAILURE ) ; } // start listening if( listen(svrSck,10) == SOCKET_ERROR ) { closesocket ( svrSck ) ; LoadString ( hInstance , IDS_LISTEN_FALED , szMessage , sizeof ( szMessage ) ) ; MessageBox ( hCurDlg , szMessage , szCaption , MB_ICONERROR ) ; ExitProcess ( EXIT_FAILURE ) ; } state = TRUE ; hThread = CreateThread (NULL, 0, GetMessageFromClient, 0, 0, &ThreadID) ; while ( state ) // Wait for client connection { FD_ZERO(&rfd); // used for judging whether there is connection FD_ZERO(&efd); // used for judging whether there's any error FD_SET(svrSck,&rfd) ; FD_SET(svrSck,&efd) ; timeout.tv_sec=0 ; timeout.tv_usec=10000 ; // set timeout as 10 second if( select(0,&rfd,NULL,&efd,&timeout) ) { if(FD_ISSET(svrSck,&rfd)) // if there's a connction { len = sizeof(SOCKADDR_IN); sck = accept(svrSck,(SOCKADDR*)&ad,&len); if( sck != INVALID_SOCKET ) { GetLocalTime(&nowtime); set_client (&clt,sck,ad,"","","",TRUE,nowtime,NULL); ins_clients(clt); refresh( ) ; } } else if( FD_ISSET( svrSck,&efd ) ) // Something goes wrong { shutdown(svrSck,SD_BOTH); closesocket(svrSck); WSACleanup(); LoadString ( hInstance , IDS_SOCKET_ERROR , szMessage , sizeof ( szMessage ) ) ; MessageBox ( hCurDlg , szMessage , szCaption , MB_ICONERROR ) ; ExitProcess ( EXIT_FAILURE ) ; } } Sleep(10); } TerminateThread ( hThread , 0 ) ; CloseHandle ( hThread ) ; hThread = NULL ; dst_clients( ); shutdown(svrSck,SD_BOTH); closesocket(svrSck); WSACleanup(); return 0L; }