2
xynaplayer for rot13(NalK)
3
Copyright (C) 2009 Ying-Chun Liu (PaulLiu) <grandpaul@gmail.com>
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
30
#include <glib/gprintf.h>
34
char* smucNC = "00000001";
35
char* smucCNONCE = "0a4f113b";
37
in_addr_t smuc_addr(const char *cp) {
38
struct addrinfo hints;
39
struct addrinfo *res=NULL,*resi=NULL;
42
struct sockaddr_in *inaddr=NULL;
45
memset(&hints,0,sizeof(struct addrinfo));
46
hints.ai_family = AF_INET;
48
result = getaddrinfo(cp,NULL,&hints,&res);
54
for (resi = res; resi != NULL; resi = resi->ai_next) {
55
if (resi->ai_addrlen >= sizeof(struct sockaddr_in) && resi->ai_addr != NULL) {
56
inaddr = (struct sockaddr_in *)(resi->ai_addr);
57
ret = inaddr->sin_addr.s_addr;
68
ssize_t smuc_recvn(int fd, void *vptr, size_t n) {
76
nread = read(fd,ptr,nleft);
82
} else if (nread==0) {
92
ssize_t smuc_recvline(int fd,void *vptr, size_t maxlen) {
97
for (n=1; n<maxlen; n++) {
111
goto smuc_recvline_again;
119
int smuc_readInt32(int fd) {
125
for (i=0; i<4; i++) {
126
ret = ret + ((((int) (c[i])) & 0x00ff) << (i*8));
131
SmucServerNonce* smucGetNonce(char *ip,int port) {
133
struct sockaddr_in servaddr;
138
char *saveptr1,*saveptr2;
139
SmucServerNonce *ret=NULL;
141
sockfd = socket(AF_INET,SOCK_STREAM,0);
143
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
147
memset(&servaddr,0,sizeof(servaddr));
148
servaddr.sin_family = AF_INET;
149
servaddr.sin_port = htons(port);
150
servaddr.sin_addr.s_addr = smuc_addr(ip);
152
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
154
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
158
strcpy(writeBuf,"GET /Stream/Control HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
160
strcat(writeBuf,"\n\n");
161
result = send (sockfd,writeBuf,strlen(writeBuf),0);
163
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
168
while (smuc_recvline(sockfd,readBuf,sizeof(readBuf)-1) > 0) {
169
if (strcmp(readBuf,"\n")==0) {
172
if (g_str_has_prefix(readBuf,"WWW-Authenticate: Digest ")) {
173
ret = (SmucServerNonce*)malloc(sizeof(SmucServerNonce));
174
memset(ret,0,sizeof(SmucServerNonce));
175
for (ci = strtok_r(&(readBuf[25]),",",&saveptr1); ci != NULL ; ci = strtok_r(NULL," ,",&saveptr1)) {
179
cj = strtok_r(x,"=\"",&saveptr2);
180
if (strcmp(cj,"realm")==0) {
181
cj = strtok_r(NULL,"=\"",&saveptr2);
183
strcpy(ret->realm,cj);
185
} else if (strcmp(cj,"domain")==0) {
186
cj = strtok_r(NULL,"=\"",&saveptr2);
188
strcpy(ret->domain,cj);
190
} else if (strcmp(cj,"qop")==0) {
191
cj = strtok_r(NULL,"=\"",&saveptr2);
195
} else if (strcmp(cj,"nonce")==0) {
196
cj = strtok_r(NULL,"=\"",&saveptr2);
198
strcpy(ret->nonce,cj);
200
} else if (strcmp(cj,"opaque")==0) {
201
cj = strtok_r(NULL,"=\"",&saveptr2);
203
strcpy(ret->opaque,cj);
205
} else if (strcmp(cj,"algorithm")==0) {
206
cj = strtok_r(NULL,"=\"",&saveptr2);
208
strcpy(ret->algorithm,cj);
221
int smucGetControlFD(SmucServerNonce *nonce,char *ip,int port,char *user,char *password) {
223
struct sockaddr_in servaddr;
225
char *HA1=NULL,*HA2=NULL,*response=NULL;
229
char uri[]="/Stream/Control";
231
sockfd = socket(AF_INET,SOCK_STREAM,0);
233
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
237
memset(&servaddr,0,sizeof(servaddr));
238
servaddr.sin_family = AF_INET;
239
servaddr.sin_port = htons(port);
240
servaddr.sin_addr.s_addr = smuc_addr(ip);
242
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
244
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
248
strcpy(writeBuf,method);
249
strcat(writeBuf," ");
250
strcat(writeBuf,uri);
251
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
253
strcat(writeBuf,"\n");
254
result = send (sockfd,writeBuf,strlen(writeBuf),0);
256
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
261
/* calculate response */
262
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
263
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
264
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri);
265
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
266
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
267
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
273
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
276
result = send (sockfd,writeBuf,strlen(writeBuf),0);
278
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
283
result = send(sockfd,"\n",1,0);
285
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
292
int smucGetSession(int controlfd) {
295
while (smuc_recvline(controlfd,readBuf,sizeof(readBuf)-1) > 0) {
296
if (g_str_has_prefix(readBuf,"Session: ")) {
297
if (sscanf(&(readBuf[9]),"%d",&session)!=1) {
307
int smucGetVideoFD(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,int session) {
309
struct sockaddr_in servaddr;
312
char *HA1=NULL,*HA2=NULL,*response=NULL;
316
char uri_o[]="/Stream/Video";
317
char uri[100]="/Stream/Video?Session=0";
319
snprintf(uri,sizeof(uri),"%s?Session=%d",uri_o,session);
321
sockfd = socket(AF_INET,SOCK_STREAM,0);
323
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
327
memset(&servaddr,0,sizeof(servaddr));
328
servaddr.sin_family = AF_INET;
329
servaddr.sin_port = htons(port);
330
servaddr.sin_addr.s_addr = smuc_addr(ip);
332
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
334
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
338
strcpy(writeBuf,method);
339
strcat(writeBuf," ");
340
strcat(writeBuf,uri);
341
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
343
strcat(writeBuf,"\n");
344
result = send (sockfd,writeBuf,strlen(writeBuf),0);
346
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
351
/* calculate response */
352
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
353
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
354
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri_o);
355
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
356
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
357
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
363
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri_o,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
366
result = send (sockfd,writeBuf,strlen(writeBuf),0);
368
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
373
result = send(sockfd,"\n",1,0);
375
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
380
while (smuc_recvline(sockfd,readBuf,sizeof(readBuf)-1) > 0) {
381
if (strcmp(readBuf,"\n")==0) {
386
while (smuc_recvline(sockfd,readBuf,sizeof(readBuf)-1) > 0) {
387
if (strcmp(readBuf,"</html>\n")==0) {
395
int smucGetAudioFD(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,int session) {
397
struct sockaddr_in servaddr;
400
char *HA1=NULL,*HA2=NULL,*response=NULL;
404
char uri_o[]="/Stream/Audio";
405
char uri[100]="/Stream/Audio?Session=0";
407
snprintf(uri,sizeof(uri),"%s?Session=%d",uri_o,session);
409
sockfd = socket(AF_INET,SOCK_STREAM,0);
411
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
415
memset(&servaddr,0,sizeof(servaddr));
416
servaddr.sin_family = AF_INET;
417
servaddr.sin_port = htons(port);
418
servaddr.sin_addr.s_addr = smuc_addr(ip);
420
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
422
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
426
strcpy(writeBuf,method);
427
strcat(writeBuf," ");
428
strcat(writeBuf,uri);
429
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
431
strcat(writeBuf,"\n");
432
result = send (sockfd,writeBuf,strlen(writeBuf),0);
434
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
439
/* calculate response */
440
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
441
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
442
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri_o);
443
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
444
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
445
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
451
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri_o,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
454
result = send (sockfd,writeBuf,strlen(writeBuf),0);
456
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
461
result = send(sockfd,"\n",1,0);
463
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
468
while (smuc_recvline(sockfd,readBuf,sizeof(readBuf)-1) > 0) {
469
if (strcmp(readBuf,"\n")==0) {
474
while (smuc_recvline(sockfd,readBuf,sizeof(readBuf)-1) > 0) {
475
if (strcmp(readBuf,"</html>\n")==0) {
483
int smucDoControlPost(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,char *post) {
485
struct sockaddr_in servaddr;
487
char *HA1=NULL,*HA2=NULL,*response=NULL;
490
char method[]="POST";
491
char uri_o[]="/Stream/Control";
492
char uri[100]="/Stream/Control";
494
snprintf(uri,sizeof(uri),"%s",uri_o);
496
sockfd = socket(AF_INET,SOCK_STREAM,0);
498
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
502
memset(&servaddr,0,sizeof(servaddr));
503
servaddr.sin_family = AF_INET;
504
servaddr.sin_port = htons(port);
505
servaddr.sin_addr.s_addr = smuc_addr(ip);
507
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
509
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
513
strcpy(writeBuf,method);
514
strcat(writeBuf," ");
515
strcat(writeBuf,uri);
516
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
518
strcat(writeBuf,"\n");
519
result = send (sockfd,writeBuf,strlen(writeBuf),0);
521
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
526
/* calculate response */
527
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
528
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
529
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri_o);
530
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
531
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
532
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
538
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri_o,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
541
result = send (sockfd,writeBuf,strlen(writeBuf),0);
543
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
548
strcpy(writeBuf,"Content-Type: application/x-rtsp-tunnelled\n");
549
result = send (sockfd,writeBuf,strlen(writeBuf),0);
551
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send Content-Type");
556
snprintf(writeBuf,sizeof(writeBuf)-1,"Content-Length: %d\n",strlen(post));
557
result = send (sockfd,writeBuf,strlen(writeBuf),0);
559
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send Content-Length: %d",strlen(post));
564
result = send(sockfd,"\n",1,0);
566
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
571
result = send(sockfd,post,strlen(post),0);
573
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send post");
583
int smucPlay(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,int session) {
587
snprintf(post1,sizeof(post1)-1,"PLAY rtsp://%s/live RTSP/1.0\nCSeq: 1\nSession: %d\nRange: npt=0.000-\n\n",ip,session);
589
result = smucDoControlPost(nonce,ip,port,user,password,post1);
595
int smucTuneChannel(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,int cmd,int channel) {
597
struct sockaddr_in servaddr;
599
char *HA1=NULL,*HA2=NULL,*response=NULL;
603
char uri_o[]="/cgi/cgiTunerCtrl";
604
char uri[100]="/cgi/cgiTunerCtrl?cmd=0&channel=10";
607
snprintf(uri,sizeof(uri),"%s?cmd=%d&channel=%d",uri_o,cmd,channel);
609
snprintf(uri,sizeof(uri),"%s?cmd=%d",uri_o,cmd);
612
sockfd = socket(AF_INET,SOCK_STREAM,0);
614
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
618
memset(&servaddr,0,sizeof(servaddr));
619
servaddr.sin_family = AF_INET;
620
servaddr.sin_port = htons(port);
621
servaddr.sin_addr.s_addr = smuc_addr(ip);
623
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
625
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
629
strcpy(writeBuf,method);
630
strcat(writeBuf," ");
631
strcat(writeBuf,uri);
632
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
634
strcat(writeBuf,"\n");
635
result = send (sockfd,writeBuf,strlen(writeBuf),0);
637
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
642
/* calculate response */
643
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
644
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
645
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri_o);
646
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
647
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
648
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
654
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri_o,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
657
result = send (sockfd,writeBuf,strlen(writeBuf),0);
659
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
664
result = send(sockfd,"\n",1,0);
666
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
676
int smucTuneAV(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,int videochn,int audiochn) {
678
struct sockaddr_in servaddr;
680
char *HA1=NULL,*HA2=NULL,*response=NULL;
684
char uri_o[]="/cgi/cgiAVCtrl";
685
char uri[100]="/cgi/cgiAVCtrl?videochn=10&audiochn=10";
687
snprintf(uri,sizeof(uri),"%s?videochn=%d&audiochn=%d",uri_o,videochn,audiochn);
689
sockfd = socket(AF_INET,SOCK_STREAM,0);
691
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
695
memset(&servaddr,0,sizeof(servaddr));
696
servaddr.sin_family = AF_INET;
697
servaddr.sin_port = htons(port);
698
servaddr.sin_addr.s_addr = smuc_addr(ip);
700
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
702
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
706
strcpy(writeBuf,method);
707
strcat(writeBuf," ");
708
strcat(writeBuf,uri);
709
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
711
strcat(writeBuf,"\n");
712
result = send (sockfd,writeBuf,strlen(writeBuf),0);
714
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
719
/* calculate response */
720
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
721
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
722
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri_o);
723
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
724
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
725
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
731
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri_o,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
734
result = send (sockfd,writeBuf,strlen(writeBuf),0);
736
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
741
result = send(sockfd,"\n",1,0);
743
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
753
int smucEstimateBandwith(SmucServerNonce *nonce,char *ip,int port,char *user,char *password,int framesize,int quality) {
755
struct sockaddr_in servaddr;
757
char *HA1=NULL,*HA2=NULL,*response=NULL;
761
char uri_o[]="/cgi/cgiEstBandwith";
762
char uri[100]="/cgi/cgiEstBandwith?frameSize=1&quality=4";
765
snprintf(uri,sizeof(uri),"%s?frameSize=%d&quality=%d",uri_o,framesize,quality);
767
sockfd = socket(AF_INET,SOCK_STREAM,0);
769
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_ERROR,"Error: cannot new socket");
773
memset(&servaddr,0,sizeof(servaddr));
774
servaddr.sin_family = AF_INET;
775
servaddr.sin_port = htons(port);
776
servaddr.sin_addr.s_addr = smuc_addr(ip);
778
result = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
780
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: cannot connect to %s",ip);
784
strcpy(writeBuf,method);
785
strcat(writeBuf," ");
786
strcat(writeBuf,uri);
787
strcat(writeBuf," HTTP/1.0\nAccept: */*\nUser-Agent: Apexx Player\nHost: ");
789
strcat(writeBuf,"\n");
790
result = send (sockfd,writeBuf,strlen(writeBuf),0);
792
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send GET");
797
/* calculate response */
798
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s",user,nonce->realm,password);
799
HA1 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
800
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s",method,uri_o);
801
HA2 = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
802
snprintf(tmpbuf,sizeof(tmpbuf)-1,"%s:%s:%s:%s:%s:%s",HA1,nonce->nonce,smucNC,smucCNONCE,nonce->qop,HA2);
803
response = g_compute_checksum_for_string(G_CHECKSUM_MD5,tmpbuf,-1);
809
snprintf(writeBuf,sizeof(writeBuf)-1,"Authorization: Digest username=\"%s\", realm=\"%s\", algorithm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=%s, cnonce=\"%s\", opaque=\"%s\", response=\"%s\", qop=\"%s\"\n",user,nonce->realm,nonce->algorithm,nonce->nonce,uri_o,smucNC,smucCNONCE,nonce->opaque,response,nonce->qop);
812
result = send (sockfd,writeBuf,strlen(writeBuf),0);
814
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send USER/PASSWORD");
819
result = send(sockfd,"\n",1,0);
821
g_log(G_LOG_DOMAIN,G_LOG_LEVEL_CRITICAL,"Error: send \\n");
826
while (recv(sockfd,readBuf,sizeof(readBuf),0) > 0) {