81
static int send_command(const char *command, const char * port, char *reply, int reply_len, int print_errors){
75
static int send_command(const char *command, char *reply, int reply_len, int print_errors){
86
struct addrinfo *ai=NULL;
87
struct addrinfo hints;
88
memset(&hints,0,sizeof(hints));
89
hints.ai_family=AF_INET;
90
hints.ai_socktype=SOCK_STREAM;
91
err=getaddrinfo("127.0.0.1",port,&hints,&ai);
93
if (print_errors) fprintf(stderr,"ERROR: getaddrinfo failed: error %i\n", err);
96
sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
97
if (connect(sock,ai->ai_addr,ai->ai_addrlen)!=0){
98
if (print_errors) fprintf(stderr,"ERROR: Failed to connect socket.\n");
105
struct sockaddr_un sa;
107
sock=socket(AF_UNIX,SOCK_STREAM,0);
108
sa.sun_family=AF_UNIX;
109
snprintf(path,sizeof(path)-1,"/tmp/linphonec-%i",getuid());
110
strncpy(sa.sun_path,path,sizeof(sa.sun_path)-1);
111
if (connect(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){
112
if (print_errors) fprintf(stderr,"ERROR: Failed to connect socket: %s\n",getSocketError());
81
snprintf(path,sizeof(path)-1,"linphonec-%i",getuid());
116
fprintf(stderr,"ERROR: windows pipes communication not yet implemented.\n");
85
DWORD size=sizeof(username)-1;
86
GetUserName(username,&size);
87
snprintf(path,sizeof(path)-1,"linphonec-%s",username);
90
if ((pp=ortp_client_pipe_connect(path))==ORTP_PIPE_INVALID){
91
if (print_errors) fprintf(stderr,"ERROR: Failed to connect pipe: %s\n",strerror(errno));
120
if (send(sock,command,strlen(command),0)<0){
94
if (ortp_pipe_write(pp,(uint8_t*)command,strlen(command))==-1){
121
95
if (print_errors) fprintf(stderr,"ERROR: Fail to send command to remote linphonec\n");
96
ortp_client_pipe_close(pp);
125
99
/*wait for replies */
127
while ((err=recv(sock,&reply[i],reply_len-i-1,0))>0){
101
while ((err=ortp_pipe_read(pp,(uint8_t*)&reply[i],reply_len-i-1))>0){
105
ortp_client_pipe_close(pp);
203
174
PROCESS_INFORMATION pinfo;
205
176
ZeroMemory( &si, sizeof(si) );
207
ZeroMemory( &pinfo, sizeof(pinfo) );
210
BOOL ret=CreateProcess(NULL,"linphonec.exe --tcp " DEFAULT_TCP_PORT " -c NUL",
178
ZeroMemory( &pinfo, sizeof(pinfo) );
181
BOOL ret=CreateProcess(NULL,"linphoned.exe --pipe -c NUL",
228
199
static int send_generic_command(const char *command, int print_result){
229
200
char reply[DEFAULT_REPLY_SIZE];
231
err=send_command(command,DEFAULT_TCP_PORT,reply,sizeof(reply),print_result);
202
err=send_command(command,reply,sizeof(reply),print_result);
232
203
if (err==0 && print_result) {
233
204
printf("%s",reply);
298
269
snprintf(cmd,sizeof(cmd),"status %s",argv[0]);
299
err=send_command(cmd,DEFAULT_TCP_PORT,reply,sizeof(reply),TRUE);
270
err=send_command(cmd,reply,sizeof(reply),TRUE);
301
272
printf("%s",reply);
302
273
err=make_status_value(reply);
325
296
snprintf(cmd,sizeof(cmd),"soundcard %s",argv[0]);
326
err=send_command(cmd,DEFAULT_TCP_PORT,reply,sizeof(reply),TRUE);
297
err=send_command(cmd,reply,sizeof(reply),TRUE);
328
299
printf("%s",reply);
329
300
return parse_card_index(reply);
331
302
}else if (argc==2){/*setting a soundcard */
332
303
snprintf(cmd,sizeof(cmd),"soundcard %s %s",argv[0],argv[1]);
333
err=send_command(cmd,DEFAULT_TCP_PORT,reply,sizeof(reply),TRUE);
304
err=send_command(cmd,reply,sizeof(reply),TRUE);
335
306
printf("%s",reply);
351
322
for(argi=1;argi<argc;++argi){
352
if (strcmp(argv[argi],"--tcp")==0){
354
}else if (strcmp(argv[argi],"init")==0){
323
if (strcmp(argv[argi],"init")==0){
355
324
/*check if there is running instance*/
356
325
if (send_generic_command("help",0)==0){
357
326
fprintf(stderr,"A running linphonec has been found, not spawning a second one.\n");
360
329
spawn_linphonec(argc-argi-1,&argv[argi+1]);
361
if (tcp) fprintf(stderr,"WARNING: using --tcp is unsafe: unprivilegied users can make calls.\n");
363
331
}else if (strcmp(argv[argi],"generic")==0){
364
332
if (argi+1<argc){