Changeset 256:70ad9c490986 in mediastreamer2
- Timestamp:
- Feb 13, 2009 11:19:13 PM (4 years ago)
- Branch:
- default
- Location:
- linphone
- Files:
-
- 4 edited
-
NEWS (modified) (1 diff)
-
console/commands.c (modified) (2 diffs)
-
console/linphonec.c (modified) (10 diffs)
-
console/shell.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
linphone/NEWS
r236 r256 7 7 * linphonec can compile and work without libreadline 8 8 * enable translations on windows 9 * enable lookups of SRV records 9 10 * bugfixing as usual 10 11 -
linphone/console/commands.c
r248 r256 1244 1244 if (cfg){ 1245 1245 if (linphone_proxy_config_is_registered(cfg)){ 1246 linphonec_out(" identity=%s duration=%i\n",1246 linphonec_out("registered, identity=%s duration=%i\n", 1247 1247 linphone_proxy_config_get_identity(cfg), 1248 1248 linphone_proxy_config_get_expires(cfg)); … … 1269 1269 break; 1270 1270 case GSTATE_CALL_OUT_CONNECTED: 1271 linphonec_out(" hook=%s duration=%i\n", linphonec_get_callee(),1271 linphonec_out("Call out, hook=%s duration=%i\n", linphonec_get_callee(), 1272 1272 linphone_core_get_current_call_duration(lc)); 1273 1273 break; -
linphone/console/linphonec.c
r245 r256 48 48 #include <sys/socket.h> 49 49 #include <netdb.h> 50 #include <sys/un.h> 51 #include <sys/stat.h> 50 52 #endif 51 53 … … 131 133 static bool_t preview_enabled=FALSE; 132 134 static bool_t show_general_state=FALSE; 135 static bool_t unix_socket=FALSE; 133 136 static int tcp_port=0; /* see --tcp: tcp port to listen for commands */ 134 137 LPC_AUTH_STACK auth_stack; … … 139 142 static ortp_socket_t client_sock=-1; 140 143 char prompt[PROMPT_MAX_LEN]; 144 char sock_unix_path[128]={0}; 145 static ortp_thread_t net_reader_th; 146 static bool_t net_reader_run=FALSE; 147 static ortp_socket_t server_sock; 141 148 142 149 LinphoneCoreVTable linphonec_vtable = { … … 367 374 368 375 static ortp_socket_t create_server_socket(int port){ 369 ortp_socket_t server_sock; 370 char service[12]; 371 int tmp,err; 372 /*setup the server socket */ 373 struct addrinfo *ai=NULL; 374 struct addrinfo hints; 375 memset(&hints,0,sizeof(hints)); 376 hints.ai_family=AF_INET; 377 snprintf(service,sizeof(service),"%i",port); 378 379 getaddrinfo("127.0.0.1",service,&hints,&ai); 380 if (ai==NULL){ 381 fprintf(stderr,"getaddrinfo failed on port %s",service); 382 exit(-1); 383 } 384 server_sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); 385 tmp=1; 386 err=setsockopt(server_sock,SOL_SOCKET,SO_REUSEADDR,(void*)&tmp,sizeof(tmp)); 387 if (err<0) fprintf(stderr,"Error in setsockopt(): %s\n",getSocketError()); 388 if (bind(server_sock,ai->ai_addr,ai->ai_addrlen)!=0){ 389 fprintf(stderr,"Failed to bind command socket."); 390 exit(-1); 391 } 392 listen(server_sock,1); 393 return server_sock; 394 } 395 396 static void *tcp_thread(void*p){ 376 ortp_socket_t sock; 377 if (!unix_socket){ 378 char service[12]; 379 /*setup the server socket */ 380 struct addrinfo *ai=NULL; 381 struct addrinfo hints; 382 memset(&hints,0,sizeof(hints)); 383 hints.ai_family=AF_INET; 384 snprintf(service,sizeof(service),"%i",port); 385 386 getaddrinfo("127.0.0.1",service,&hints,&ai); 387 if (ai==NULL){ 388 fprintf(stderr,"getaddrinfo failed on port %s",service); 389 exit(-1); 390 } 391 sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); 392 if (bind(sock,ai->ai_addr,ai->ai_addrlen)!=0){ 393 fprintf(stderr,"Failed to bind command socket.\n"); 394 exit(-1); 395 } 396 listen(sock,1); 397 }else{ 398 #ifndef WIN32 399 struct sockaddr_un sa; 400 sock=socket(AF_UNIX,SOCK_STREAM,0); 401 sa.sun_family=AF_UNIX; 402 snprintf(sock_unix_path,sizeof(sock_unix_path)-1,"/tmp/linphonec-%i",getuid()); 403 strncpy(sa.sun_path,sock_unix_path,sizeof(sa.sun_path)-1); 404 unlink(sock_unix_path);/*in case we didn't finished properly previous time */ 405 fchmod(sock,S_IRUSR|S_IWUSR); 406 if (bind(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){ 407 fprintf(stderr,"Failed to bind command unix socket.\n"); 408 exit(-1); 409 } 410 listen(sock,1); 411 printf("Listening from unix socket %s\n",sock_unix_path); 412 #else 413 fprintf(stderr,"Window pipe implementation not written yet.\n"); 414 #endif 415 } 416 return sock; 417 } 418 419 static void *net_thread(void*p){ 397 420 char tmp[250]; 398 ortp_socket_t server_sock;399 421 struct sockaddr_storage ss; 422 #ifndef WIN32 423 struct sockaddr_un su; 424 #endif 400 425 socklen_t ssize; 401 bool_t run=TRUE;402 426 403 427 server_sock=create_server_socket(tcp_port); 404 428 if (server_sock==-1) return NULL; 405 while( run){429 while(net_reader_run){ 406 430 while(client_sock!=-1){ /*sleep until the last command is finished*/ 407 431 #ifndef WIN32 … … 411 435 #endif 412 436 } 413 ssize=sizeof(ss); 414 if ((client_sock=accept(server_sock,(struct sockaddr*)&ss,&ssize))!=-1){ 437 if (!unix_socket){ 438 ssize=sizeof(ss); 439 client_sock=accept(server_sock,(struct sockaddr*)&ss,&ssize); 440 }else{ 441 ssize=sizeof(su); 442 client_sock=accept(server_sock,(struct sockaddr*)&su,&ssize); 443 } 444 if (client_sock!=-1){ 415 445 int len; 416 446 /*now read from the client */ … … 419 449 tmp[len]='\0'; 420 450 strcpy(received_prompt,tmp); 421 if (strcmp(received_prompt,"quit")==0) run=FALSE;422 451 printf("Receiving command '%s'\n",received_prompt);fflush(stdout); 423 452 have_prompt=TRUE; … … 429 458 } 430 459 431 } 432 } 460 }else{ 461 if (net_reader_run) fprintf(stderr,"accept() failed: %s\n",getSocketError()); 462 } 463 } 464 433 465 return NULL; 434 466 } 435 467 436 static void start_tcp_reader(void){ 437 ortp_thread_t th; 468 static void start_net_reader(void){ 438 469 ms_mutex_init(&prompt_mutex,NULL); 439 ortp_thread_create(&th,NULL,tcp_thread,NULL); 470 net_reader_run=TRUE; 471 ortp_thread_create(&net_reader_th,NULL,net_thread,NULL); 472 } 473 474 static void stop_net_reader(void){ 475 net_reader_run=FALSE; 476 close(server_sock); 477 if (sock_unix_path[0]!=0){ 478 unlink(sock_unix_path); 479 } 480 /*ortp_thread_join(net_reader_th,NULL);*/ 440 481 } 441 482 … … 447 488 #else 448 489 static bool_t prompt_reader_started=FALSE; 449 static bool_t tcp_reader_started=FALSE;490 static bool_t net_reader_started=FALSE; 450 491 if (!prompt_reader_started){ 451 492 start_prompt_reader(); 452 493 prompt_reader_started=TRUE; 453 494 } 454 if ( tcp_port>0 && !tcp_reader_started){455 start_ tcp_reader();456 tcp_reader_started=TRUE;495 if ((tcp_port>0 || unix_socket) && !net_reader_started){ 496 start_net_reader(); 497 net_reader_started=TRUE; 457 498 } 458 499 fprintf(stdout,"%s",prompt); … … 633 674 linphonec_finish_readline(); 634 675 #endif 676 677 if (net_reader_run) 678 stop_net_reader(); 635 679 linphone_core_uninit (&linphonec); 636 680 … … 1007 1051 if (tcp_port==0) tcp_port=DEFAULT_TCP_PORT; 1008 1052 } 1053 else if (strncmp ("--pipe", argv[arg_num], 6) == 0) 1054 { 1055 unix_socket=1; 1056 } 1009 1057 else if (old_arg_num == arg_num) 1010 1058 { -
linphone/console/shell.c
r248 r256 30 30 #include <sys/socket.h> 31 31 #include <netdb.h> 32 #include <sys/un.h> 33 32 34 #endif 33 35 … … 37 39 #define DEFAULT_REPLY_SIZE 4096 38 40 41 #define STATUS_REGISTERED (1<<0) 42 #define STATUS_REGISTERING (1<<1) 43 #define STATUS_DIALING (1<<2) 44 #define STATUS_AUTOANSWER (1<<3) 45 #define STATUS_IN_CONNECTED (1<<4) /* incoming call accepted */ 46 #define STATUS_OUT_CONNECTED (1<<5) /*outgoing call accepted */ 47 48 static int tcp=0; 49 50 static int make_status_value(const char *status_string){ 51 int ret=0; 52 if (strstr(status_string,"registered, identity=")){ 53 ret|=STATUS_REGISTERED; 54 } 55 if (strstr(status_string,"registered=-1")){ 56 ret|=STATUS_REGISTERING; 57 } 58 if (strstr(status_string,"autoanswer=1")){ 59 ret|=STATUS_AUTOANSWER; 60 } 61 if (strstr(status_string,"dialing")){ 62 ret|=STATUS_DIALING; 63 } 64 if (strstr(status_string,"Call out")){ 65 ret|=STATUS_OUT_CONNECTED; 66 } 67 if (strstr(status_string,"hook=answered")){ 68 ret|=STATUS_IN_CONNECTED; 69 } 70 return ret; 71 } 72 39 73 static int send_command(const char *command, const char * port, char *reply, int reply_len, int print_errors){ 40 74 ortp_socket_t sock; 41 struct addrinfo *ai=NULL; 42 struct addrinfo hints; 75 int i; 43 76 int err; 44 int i; 45 memset(&hints,0,sizeof(hints)); 46 hints.ai_family=AF_INET; 47 hints.ai_socktype=SOCK_STREAM; 48 err=getaddrinfo("127.0.0.1",port,&hints,&ai); 49 if (err!=0){ 50 if (print_errors) fprintf(stderr,"ERROR: getaddrinfo failed: error %i\n", err); 77 if (tcp){ 78 struct addrinfo *ai=NULL; 79 struct addrinfo hints; 80 memset(&hints,0,sizeof(hints)); 81 hints.ai_family=AF_INET; 82 hints.ai_socktype=SOCK_STREAM; 83 err=getaddrinfo("127.0.0.1",port,&hints,&ai); 84 if (err!=0){ 85 if (print_errors) fprintf(stderr,"ERROR: getaddrinfo failed: error %i\n", err); 86 return -1; 87 } 88 sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); 89 if (connect(sock,ai->ai_addr,ai->ai_addrlen)!=0){ 90 if (print_errors) fprintf(stderr,"ERROR: Failed to connect socket.\n"); 91 freeaddrinfo(ai); 92 return -1; 93 } 94 freeaddrinfo(ai); 95 }else{ 96 #ifndef WIN32 97 struct sockaddr_un sa; 98 char path[128]; 99 sock=socket(AF_UNIX,SOCK_STREAM,0); 100 sa.sun_family=AF_UNIX; 101 snprintf(path,sizeof(path)-1,"/tmp/linphonec-%i",getuid()); 102 strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1); 103 if (connect(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){ 104 if (print_errors) fprintf(stderr,"ERROR: Failed to connect socket: %s\n",getSocketError()); 105 return -1; 106 } 107 #else 108 fprintf(stderr,"ERROR: windows pipes communication not yet implemented.\n"); 51 109 return -1; 52 } 53 sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); 54 if (connect(sock,ai->ai_addr,ai->ai_addrlen)!=0){ 55 if (print_errors) fprintf(stderr,"ERROR: Failed to connect socket.\n"); 56 freeaddrinfo(ai); 57 return -1; 58 } 59 freeaddrinfo(ai); 110 #endif 111 } 60 112 if (send(sock,command,strlen(command),0)<0){ 61 113 if (print_errors) fprintf(stderr,"ERROR: Fail to send command to remote linphonec\n"); … … 97 149 j=0; 98 150 args[j++]="linphonec"; 99 args[j++]="--tcp"; 100 args[j++]=DEFAULT_TCP_PORT; 151 if (tcp){ 152 args[j++]="--tcp"; 153 args[j++]=DEFAULT_TCP_PORT; 154 }else args[j++]="--pipe"; 101 155 args[j++]="-c"; 102 156 args[j++]="/dev/null"; … … 196 250 static int status_execute(int argc, char *argv[]){ 197 251 char cmd[512]; 252 char reply[DEFAULT_REPLY_SIZE]; 253 int err; 254 198 255 if (argc==1){ 199 256 snprintf(cmd,sizeof(cmd),"status %s",argv[0]); 200 return send_generic_command(cmd,TRUE); 257 err=send_command(cmd,DEFAULT_TCP_PORT,reply,sizeof(reply),TRUE); 258 if (err==0) { 259 printf("%s",reply); 260 err=make_status_value(reply); 261 } 262 return err; 201 263 }else{ 202 264 print_usage(); … … 213 275 ortp_init(); 214 276 for(argi=1;argi<argc;++argi){ 215 if (strcmp(argv[argi],"init")==0){ 277 if (strcmp(argv[argi],"--tcp")==0){ 278 tcp=1; 279 }else if (strcmp(argv[argi],"init")==0){ 216 280 /*check if there is running instance*/ 217 281 if (send_generic_command("help",0)==0){ … … 219 283 } 220 284 spawn_linphonec(argc-argi-1,&argv[argi+1]); 285 if (tcp) fprintf(stderr,"WARNING: using --tcp is unsafe: unprivilegied users can make calls.\n"); 221 286 return 0; 222 287 }else if (strcmp(argv[argi],"generic")==0){
Note: See TracChangeset
for help on using the changeset viewer.
