/[resiprocate]/main/sip/resiprocate/test/limpc.cxx
ViewVC logotype

Contents of /main/sip/resiprocate/test/limpc.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3604 - (show annotations) (download)
Tue Nov 23 07:15:40 2004 UTC (15 years, 2 months ago) by fluffy
File size: 26644 byte(s)
who knows
1 #if defined(HAVE_CONFIG_HXX)
2 #include "resiprocate/config.hxx"
3 #endif
4
5 #include <cstring>
6 #include <cassert>
7
8 //#define USE_CURSES
9
10 #ifdef USE_CURSES
11 #include <ncurses.h>
12 #else
13 #include <iostream>
14 #include <cstdio>
15
16 #ifdef WIN32
17 #include <io.h>
18 #else
19 #include <unistd.h>
20 #endif
21
22 typedef void WINDOW;
23
24 #ifndef __APPLE__
25 bool TRUE=true;
26 bool FALSE=false;
27 #endif
28
29 char ACS_HLINE=1;
30 char ACS_VLINE=2;
31 WINDOW* stdscr=0;
32 WINDOW* newwin(...) { return NULL; };
33 void waddstr(WINDOW*, const char* text) { std::clog << text; };
34 char getch()
35 {
36 #if 0
37 assert(0);
38 return 0;
39 #else
40 char buf[1];
41 int r = read(fileno(stdin),&buf,1);
42 if ( r ==1 )
43 {
44 return buf[0];
45 }
46 return 0;
47 #endif
48 };
49 void werase(WINDOW*) {};
50 void wrefresh(...) {};
51 void mvhline(...) {};
52 void refresh(...) {};
53 void getmaxyx(...) {};
54 void clearok(...) {};
55 void waddch(...) {};
56 void initscr(...) {};
57 void cbreak(...) {};
58 void noecho(...) {};
59 void nonl(...) {};
60 void intrflush(...) {};
61 void keypad(...) {};
62 void scrollok(...) {};
63 void wmove(...) {};
64 void mvvline(...) {};
65 #endif
66
67
68
69 #ifndef WIN32
70 #include <sys/time.h>
71 #include <sys/types.h>
72 #include <unistd.h>
73 #endif
74
75 #include "resiprocate/os/Socket.hxx"
76 #include "resiprocate/os/Logger.hxx"
77 #include "resiprocate/SipStack.hxx"
78 #include "resiprocate/Uri.hxx"
79 #include "resiprocate/TuIM.hxx"
80 #include "resiprocate/Security.hxx"
81
82 static int myMain(int argc, char* argv[]);
83
84 using namespace resip;
85
86 using namespace std;
87
88 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
89
90
91 static WINDOW* commandWin=0;
92 static WINDOW* textWin=0;
93 static WINDOW* statusWin=0;
94
95 static TuIM* tuIM;
96 static Uri dest;
97
98 void
99 displayPres()
100 {
101 werase(statusWin);
102
103 for( int i=0; i<tuIM->getNumBuddies();i++)
104 {
105 Uri uri = tuIM->getBuddyUri(i);
106 Data status;
107 bool online = tuIM->getBuddyStatus(i,&status);
108 const char* stat = (online)?"online":"offline";
109
110 waddstr(statusWin,uri.getAor().c_str());
111 waddstr(statusWin," ");
112 waddstr(statusWin,stat);
113 waddstr(statusWin," ");
114 waddstr(statusWin,status.c_str());
115 waddstr(statusWin,"\n");
116 }
117
118 wrefresh(statusWin);
119 }
120
121
122 class TestCallback: public TuIM::Callback
123 {
124 public:
125 virtual void presenceUpdate(const Uri& dest, bool open, const Data& status );
126 virtual void receivedPage( const Data& msg, const Uri& from ,
127 const Data& signedBy, SignatureStatus sigStatus,
128 bool wasEncryped );
129 virtual void sendPageFailed( const Uri& dest,int respNumber );
130 virtual void registrationFailed(const resip::Uri&, int respNumber);
131 virtual void registrationWorked(const Uri& dest );
132 virtual void receivePageFailed(const Uri& sender);
133 };
134
135
136 void
137 TestCallback::presenceUpdate(const Uri& from, bool open, const Data& status )
138 {
139 const char* stat = (open)?"online":"offline";
140 //cout << from << " set presence to " << stat << " " << status.c_str() << endl;
141
142 waddstr(textWin,"Status: ");
143 waddstr(textWin, from.getAor().c_str());
144 waddstr(textWin," is ");
145 waddstr(textWin,stat);
146 waddstr(textWin," ");
147 waddstr(textWin,status.c_str());
148 waddstr(textWin,"\n");
149
150 wrefresh(textWin);
151
152 displayPres();
153 }
154
155 void
156 TestCallback::receivedPage( const Data& msg, const Uri& from,
157 const Data& signedBy, SignatureStatus sigStatus,
158 bool wasEncryped )
159 {
160 //DebugLog(<< "In TestPageCallback");
161
162 if ( dest != from )
163 {
164 dest = from;
165 //cerr << "Set destination to <" << *mDest << ">" << endl;
166 waddstr(textWin,"Set destination to ");
167 waddstr(textWin, Data::from(dest).c_str());
168 waddstr(textWin,"\n");
169 }
170
171 //cout << from;
172
173 waddstr(textWin,"From: ");
174 waddstr(textWin,from.getAor().c_str());
175
176 if ( !wasEncryped )
177 {
178 //cout << " -NOT SECURE- ";
179 waddstr(textWin," -NOT SECURE-");
180 }
181 else
182 {
183 waddstr(textWin," -secure-");
184 }
185 switch ( sigStatus )
186 {
187 case SignatureIsBad:
188 //cout << " -bad signature- ";
189 waddstr(textWin,"bad signature");
190 break;
191 case SignatureNone:
192 //cout << " -no signature- ";
193 waddstr(textWin,"no signature");
194 break;
195 case SignatureTrusted:
196 //cout << " <signed " << signedBy << " > ";
197 waddstr(textWin,"signed ");
198 waddstr(textWin,signedBy.c_str());
199 break;
200 case SignatureCATrusted:
201 //cout << " <ca signed " << signedBy << " > ";
202 waddstr(textWin,"ca signed " );
203 waddstr(textWin,signedBy.c_str());
204 break;
205 case SignatureNotTrusted:
206 //cout << " <signed " << signedBy << " NOT TRUSTED > ";
207 waddstr(textWin,"untrusted signature ");
208 waddstr(textWin,signedBy.c_str());
209 break;
210 }
211
212 //cout << " says:" << endl;
213 //cout << msg.escaped() << endl;
214 waddstr(textWin, " says: ");
215 waddstr(textWin, msg.escaped().c_str() );
216 waddstr(textWin, "\n");
217
218 wrefresh(textWin);
219 }
220
221
222 void
223 TestCallback::sendPageFailed( const Uri& target, int respNum )
224 {
225 //InfoLog(<< "In TestErrCallback");
226 // cerr << "Message to " << dest << " failed" << endl;
227 Data num(respNum);
228
229 waddstr(textWin,"Message to ");
230 waddstr(textWin, Data::from(target).c_str());
231 waddstr(textWin," failed (");
232 waddstr(textWin,num.c_str());
233 waddstr(textWin," response)\n");
234 wrefresh(textWin);
235 }
236
237
238 void
239 TestCallback::receivePageFailed( const Uri& target )
240 {
241 //InfoLog(<< "In TestErrCallback");
242 // cerr << "Message to " << dest << " failed" << endl;
243
244 waddstr(textWin,"Can not understand messager from ");
245 waddstr(textWin, Data::from(target).c_str());
246 waddstr(textWin,"\n");
247 wrefresh(textWin);
248 }
249
250
251 void
252 TestCallback::registrationFailed(const resip::Uri& target, int respNum )
253 {
254 Data num(respNum);
255
256 waddstr(textWin,"Registration to ");
257 waddstr(textWin, Data::from(target).c_str());
258 waddstr(textWin," failed (");
259 waddstr(textWin,num.c_str());
260 waddstr(textWin," response)\n");
261 wrefresh(textWin);
262 }
263
264
265 void
266 TestCallback::registrationWorked(const resip::Uri& target)
267 {
268 waddstr(textWin,"Registration to ");
269 waddstr(textWin, Data::from(target).c_str());
270 waddstr(textWin," worked");
271 wrefresh(textWin);
272 }
273
274
275 bool
276 processStdin( Uri* dest, bool sign, bool encryp )
277 {
278 static unsigned int num=0;
279 static char buf[1024];
280
281 char c = getch();
282
283 if ( c == 0 )
284 {
285 return true;
286 }
287
288 if ( c == '\f' )
289 {
290 clearok(textWin,TRUE);
291 clearok(statusWin,TRUE);
292 clearok(commandWin,TRUE);
293
294 assert( num < sizeof(buf) );
295 buf[num] = 0;
296 werase(commandWin);
297 waddstr(commandWin,buf);
298
299 wrefresh(textWin);
300 wrefresh(statusWin);
301 wrefresh(commandWin);
302
303 return true;
304 }
305
306 #if 0
307 char junk[6];
308 junk[0]=' ';
309 junk[1]='0'+(c/100);
310 junk[2]='0'+((c/10)%10);
311 junk[3]='0'+(c%10);
312 junk[4]=' ';
313 junk[5]=0;
314 waddstr(commandWin,junk);
315 #endif
316
317 if ( (c == '\a') || (c == '\b') || (c == 4 ) || (c == 0x7F) )
318 {
319 if ( num > 0 )
320 {
321 num--;
322 }
323 buf[num]=0;
324
325 werase(commandWin);
326 waddstr(commandWin,buf);
327 wrefresh(commandWin);
328
329 return true;
330 }
331
332 if ( (c == '\r') || (c == '\n') || (num+2>=sizeof(buf)) )
333 {
334 buf[num] =0;
335
336 if ( (num>3) && (!strncmp("to:",buf,3)) )
337 {
338 buf[num] = 0;
339 *dest = Uri(Data(buf+3));
340
341 //cerr << "Set destination to <" << *dest << ">";
342 waddstr(textWin,"Set destination to ");
343 waddstr(textWin, Data::from(*dest).c_str());
344 waddstr(textWin,"\n");
345 wrefresh(textWin);
346 }
347 else if ( (num>4) && (!strncmp("add:",buf,4)) )
348 {
349 buf[num] = 0;
350 Uri uri(Data(buf+4));
351
352 //cerr << "Subscribing to buddy <" << uri << ">";
353 waddstr(textWin, "Subscribing to ");
354 waddstr(textWin, Data::from(uri).c_str());
355 waddstr(textWin, "\n");
356 wrefresh(textWin);
357
358 tuIM->addBuddy( uri, Data::Empty );
359 displayPres();
360 }
361 else if ( (num>=7) && (!strncmp("status:",buf,7)) )
362 {
363 buf[num] = 0;
364 Data stat(buf+7);
365
366 //cerr << "setting presence status to <" << stat << ">";
367 waddstr(textWin,"Set presece status to <");
368 waddstr(textWin,stat.c_str());
369 waddstr(textWin,">\n");
370 wrefresh(textWin);
371
372 tuIM->setMyPresence( !stat.empty(), stat );
373 }
374 else if ( (num==1) && (!strncmp(".",buf,1)) )
375 {
376 //DebugLog( << "Got a period - end program" );
377 return false;
378 }
379 else
380 {
381 if ( num >= 1 )
382 {
383 assert( num < sizeof(buf) );
384 buf[num] = 0;
385 Data text(buf);
386
387 Data destValue = dest->getAor();
388
389 DebugLog( << "Destination is " << destValue );
390
391 Data encFor = Data::Empty;
392 if (encryp)
393 {
394 encFor = dest->getAorNoPort();
395 }
396
397 DebugLog( << "Destination encrypt for is " << encFor );
398
399 if ( tuIM->haveCerts(sign,encFor) )
400 {
401 waddstr(textWin,"To: ");
402 waddstr(textWin,destValue.c_str());
403 waddstr(textWin," ");
404 waddstr(textWin,text.c_str());
405 waddstr(textWin,"\n");
406 wrefresh(textWin);
407
408 tuIM->sendPage( text , *dest, sign , encFor );
409 }
410 else
411 {
412 waddstr(textWin,"Don't have aproperate certificates to sign and encrypt a message to ");
413 waddstr(textWin,destValue.c_str());
414 waddstr(textWin,"\n");
415 wrefresh(textWin);
416 }
417 }
418 }
419
420 num = 0;
421
422 werase(commandWin);
423 wrefresh(commandWin);
424 }
425 else
426 {
427 buf[num++] = c;
428 assert( num < sizeof(buf) );
429
430 waddch(commandWin,c);
431 wrefresh(commandWin);
432 }
433
434 return true;
435 }
436
437
438 int
439 main(int argc, char* argv[])
440 {
441 int r;
442
443 try
444 {
445 r = myMain( argc, argv );
446 }
447 catch( ... )
448 {
449 ErrLog( << "Got a exception passed all the way to the top of limp" );
450 exit(-1);
451 }
452
453 return r;
454 }
455
456
457 static int
458 myMain(int argc, char* argv[])
459 {
460 Log::initialize(Log::Cerr, Log::Err, argv[0]);
461 Log::setLevel(Log::Warning);
462
463 InfoLog(<<"Test Driver for IM Starting");
464
465 int port = 5060;
466 int tlsPort = 5061;
467 Uri aor;
468 bool haveAor=false;
469 dest = Uri("sip:nobody@example.com");
470 Data aorPassword;
471 Uri contact("sip:user@");
472 bool haveContact=false;
473 Uri outbound;
474 bool noRegister = false;
475 bool tlsServer=false;
476
477 int numAdd=0;
478 Data addList[100];
479 int numPub=0;
480 Data pubList[100];
481 bool encryp=false;
482 bool sign=false;
483 Data key("password");
484 bool useTls = true;
485 bool noTls = false;
486 bool noTcp = false;
487 bool prefUdp = false;
488 bool prefTls = false;
489 bool prefTcp = false;
490 bool noUdp = false;
491 bool noV6 = false;
492 bool noV4 = false;
493
494 for ( int i=1; i<argc; i++)
495 {
496 if (!strcmp(argv[i],"-vv"))
497 {
498 Log::setLevel(Log::Stack);
499 }
500 else if (!strcmp(argv[i],"-v"))
501 {
502 Log::setLevel(Log::Info);
503 }
504 else if (!strcmp(argv[i],"-encrypt"))
505 {
506 encryp = true;
507 }
508 else if (!strcmp(argv[i],"-noRegister"))
509 {
510 noRegister = true;
511 }
512 else if (!strcmp(argv[i],"-sign"))
513 {
514 sign = true;
515 }
516 else if (!strcmp(argv[i],"-tlsServer"))
517 {
518 tlsServer = true;
519 }
520 else if (!strcmp(argv[i],"-ssl"))
521 {
522 useTls = false;
523 }
524 else if (!strcmp(argv[i],"-noTcp"))
525 {
526 noTcp = true;
527 }
528 else if (!strcmp(argv[i],"-noTls"))
529 {
530 noTls = true;
531 }
532 else if (!strcmp(argv[i],"-noUdp"))
533 {
534 noUdp = true;
535 }
536 else if (!strcmp(argv[i],"-prefTcp"))
537 {
538 prefTcp = true;
539 }
540 else if (!strcmp(argv[i],"-prefTls"))
541 {
542 prefTls = true;
543 }
544 else if (!strcmp(argv[i],"-prefUdp"))
545 {
546 prefUdp = true;
547 }
548 else if (!strcmp(argv[i],"-noV6"))
549 {
550 noV6 = true;
551 }
552 else if (!strcmp(argv[i],"-noV4"))
553 {
554 noV4 = true;
555 }
556 else if (!strcmp(argv[i],"-port"))
557 {
558 i++;
559 assert( i<argc );
560 port = atoi( argv[i] );
561 }
562 else if (!strcmp(argv[i],"-tlsPort"))
563 {
564 i++;
565 assert( i<argc );
566 tlsPort = atoi( argv[i] );
567 }
568 else if (!strcmp(argv[i],"-aor"))
569 {
570 i++;
571 assert( i<argc );
572 try
573 {
574 aor = Uri(Data(argv[i]));
575 }
576 catch (...)
577 {
578 ErrLog( <<"AOR URI is not valid - must start with sip: ");
579 exit(-1);
580 }
581 haveAor=true;
582 }
583 else if (!strcmp(argv[i],"-outbound"))
584 {
585 i++;
586 assert( i<argc );
587 try
588 {
589 outbound = Uri(Data(argv[i]));
590 }
591 catch (...)
592 {
593 ErrLog( <<"Outbound URI is not valid - must start with sip: ");
594 exit(-1);
595 }
596 }
597 else if (!strcmp(argv[i],"-contact"))
598 {
599 i++;
600 assert( i<argc );
601 try
602 {
603 contact = Uri(Data(argv[i]));
604 }
605 catch (...)
606 {
607 ErrLog( <<"Contact URI is not valid - must start with sip: ");
608 exit(-1);
609 }
610 haveContact=true;
611 }
612 else if (!strcmp(argv[i],"-add"))
613 {
614 i++;
615 assert( i<argc );
616 addList[numAdd++] = Data(argv[i]);
617 assert( numAdd < 100 );
618 try
619 {
620 // CJ TODO FIX
621 //Uri uri( Data(argv[i]) );
622 }
623 catch (...)
624 {
625 ErrLog( <<"URI in -add is not valid - must start with sip: ");
626 exit(-1);
627 }
628 }
629 else if (!strcmp(argv[i],"-pub"))
630 {
631 i++;
632 assert( i<argc );
633 pubList[numPub++] = Data(argv[i]);
634 assert( numPub < 100 );
635 try
636 {
637 // CJ TODO FIX
638 //Uri uri(Data(argv[i]));
639 }
640 catch (...)
641 {
642 ErrLog( <<"Pub URI is not valid - must start with sip: ");
643 exit(-1);
644 }
645 }
646 else if (!strcmp(argv[i],"-aorPassword"))
647 {
648 i++;
649 assert( i<argc );
650 aorPassword = Data(argv[i]);
651 }
652 else if (!strcmp(argv[i],"-to"))
653 {
654 i++;
655 assert( i<argc );
656 try
657 {
658 dest = Uri(Data(argv[i]));
659 }
660 catch (...)
661 {
662 ErrLog( <<"To URI is not valid - must start with sip: ");
663 exit(-1);
664 }
665 }
666 else if (!strcmp(argv[i],"-key"))
667 {
668 i++;
669 assert( i<argc );
670 key = Data(argv[i]);
671 }
672 else
673 {
674 clog <<"Bad command line opion: " << argv[i] << endl;
675 clog <<"options are: " << endl
676 << "\t [-v] [-vv] [-tls] [-port 5060] [-tlsport 5061]" << endl
677 << "\t [-aor sip:alice@example.com] [-aorPassword password]" << endl
678 << "\t [-to sip:friend@example.com] [-add sip:buddy@example.com]" << endl
679 << "\t [-sign] [-encrypt] [-key secret]" << endl
680 << "\t [-contact sip:me@example.com] " << endl
681 << "\t [-outbound \"sip:example.com;lr\"] " << endl
682 << "\t [-noRegister] " << endl
683 << "\t [-pub sip:foo.com] " << endl;
684 clog << endl
685 << " -v is verbose" << endl
686 << " -vv is very verbose" << endl
687 << " -noV6 don't use IPv6" << endl
688 << " -noV4 don't use IPv4" << endl
689 << " -noUdp don't use UDP" << endl
690 << " -noTcp don't use TCP" << endl
691 << " -noTls don't use TLS" << endl
692 << " -prefUdp prefer UDP" << endl
693 << " -prefTcp prefer TCP" << endl
694 << " -prefTls prefer TLS" << endl
695 << " -port sets the UDP and TCP port to listen on" << endl
696 << " -tlsPort sets the port to listen for TLS on" << endl
697 << " -tlsServer - sets to act as tls server instead of client" << endl
698 << " -ssl - use ssl instead of tls" << endl
699 << " -aor sets the proxy and user name to register with" << endl
700 << " -aorPassword sets the password to use for registration" << endl
701 << " -noRegister causes it not to register - by default the AOR is registered" << endl
702 << " -to sets initial location to send messages to" << endl
703 << " -outbound sets the outbound proxy" << endl
704 << " -add adds a budy who's presence will be monitored" << endl
705 << " -pub adds a State Agent to send publishes too" << endl
706 << " -sign signs message you send and -encryp encrypt them " << endl
707 << "\t(You need PKI certs for this to work)" << endl
708 << " -key allows you to enter a secret used to load your private key."<< endl
709 << " If you set the secret to - the system will querry you for it."<< endl
710 << " -contact overrides your SIP contact - can be used for NAT games" << endl
711 << "\t there can be many -add " << endl
712 << " " << endl
713 << "Examples" << endl
714 << "An example command line for a user with account name alice at example.com is:" << endl
715 << "\t" << argv[0] << " -aor \"alice@example.com\" -aorPassword \"secret\"" << endl
716 << "to watch the presence of bob and charlie add" << endl
717 << "\t-add \"sip:bob@bilboxi.com\" -add \"charlie@example.com\" " << endl
718 << "If Alice was behind a NAT that had a public address of 1.2.3.4 and had forwarded" << endl
719 << "port 5070 on this NAT to the machine Alice was using, then the following " << endl
720 << "options would be added" << endl
721 << "\t-contact \"sip:alice@1.2.3.4:5070\" -port 5070" << endl
722 << "" << endl
723 << endl;
724 exit(1);
725 }
726 }
727
728 //InfoLog( << "Using port " << port );
729
730 #ifdef USE_SSL
731 Security* security=NULL;
732 try
733 {
734 security = new Security("/Users/fluffy/.sipCerts/");
735 }
736 catch( ... )
737 {
738 security = NULL;
739 ErrLog( << "Got a exception setting up Security" );
740 }
741 SipStack sipStack( false /*multihtread*/, security );
742 #else
743 SipStack sipStack( false /*multihtread*/ );
744 #endif
745
746 if ( key == Data("-") )
747 {
748 clog << "Please enter password to use to load your private key: ";
749 char buf[1024];
750 cin.get(buf,1024);
751 key = Data(buf);
752 InfoLog( << "Certificate key set to <" << key << ">" );
753 }
754
755 #ifdef USE_SSL
756 try
757 {
758 Security* security = sipStack.getSecurity();
759 assert(security != 0);
760 security->preload();
761 }
762 catch( ... )
763 {
764 ErrLog( << "Got a exception loading certificates" );
765 }
766 #endif
767
768 DebugLog( << "About to add the transports " );
769 if (port!=0)
770 {
771 if ( noUdp != true )
772 {
773 if (!noV4) sipStack.addTransport(UDP, port, V4);
774 #ifdef USE_IPV6
775 if (!noV6) sipStack.addTransport(UDP, port, V6);
776 #endif
777 }
778 if ( noTcp != true )
779 {
780 if (!noV4) sipStack.addTransport(TCP, port, V4);
781 #ifdef USE_IPV6
782 if (!noV6) sipStack.addTransport(TCP, port, V6);
783 #endif
784 }
785 }
786 #if USE_SSL
787 if ( tlsPort != 0 )
788 {
789 if ( noTls != true )
790 {
791 if (!noV4)
792 {
793 sipStack.addTransport(TLS, tlsPort, V4, Data::Empty);
794 }
795 //if (!noV6) sipStack.addTlsTransport(tlsPort,Data::Empty,Data::Empty,Data::Empty,V6);
796 }
797 }
798 #endif
799 DebugLog( << "Done adding the transports " );
800
801 if (!haveContact)
802 {
803 // contact.port() = port;
804 // contact.host() = sipStack.getHostname();
805 }
806
807 if ( haveAor )
808 {
809 if (!haveContact)
810 {
811 contact.user() = aor.user();
812 #if USE_SSL
813 if ( aor.scheme() == "sips" )
814 {
815 contact.scheme() = aor.scheme();
816 //contact.port() = tlsPort;
817 }
818 #endif
819 }
820 }
821 else
822 {
823 aor.port() = port;
824 aor.host() = sipStack.getHostname();
825 aor.user() = Data("user");
826 }
827
828 InfoLog( << "aor is " << aor );
829 InfoLog( << "contact is " << contact );
830 TestCallback callback;
831 tuIM = new TuIM(&sipStack,aor,contact,&callback);
832
833 Data name("SIPimp.org/0.2.4 (curses)");
834 tuIM->setUAName( name );
835
836 if ( !outbound.host().empty() )
837 {
838 tuIM->setOutboundProxy( outbound );
839 }
840
841 // setup prefered outbound transport
842 if ( prefUdp )
843 {
844 tuIM->setDefaultProtocol( UDP );
845 }
846 if ( prefTcp )
847 {
848 tuIM->setDefaultProtocol( TCP );
849 }
850 if ( prefTls )
851 {
852 tuIM->setDefaultProtocol( TLS );
853 }
854
855 if ( haveAor )
856 {
857 if ( !noRegister )
858 {
859 tuIM->registerAor( aor, aorPassword );
860 }
861 }
862
863 initscr();
864 cbreak();
865 noecho();
866 nonl();
867 intrflush(stdscr, FALSE);
868 keypad(stdscr, TRUE);
869
870 int rows=0;
871 int cols=0;
872 getmaxyx(stdscr,rows,cols); /* get the number of rows and columns */
873
874 commandWin = newwin(2,cols,rows-2,0);
875 scrollok(commandWin, TRUE);
876 wmove(commandWin,0,0);
877
878 textWin = newwin(rows-3,cols*3/4,0,0);
879 scrollok(textWin, TRUE);
880 wmove(textWin,0,0);
881
882 statusWin = newwin(rows-3,cols-(cols*3/4)-1,0,1+cols*3/4);
883 scrollok(statusWin, FALSE);
884 wmove(statusWin,0,0);
885
886 mvhline(rows-3,0,ACS_HLINE,cols);
887 mvvline(0,(cols*3/4),ACS_VLINE,rows-3);
888 refresh();
889
890 for ( int i=0; i<numAdd; i++ )
891 {
892 Uri uri(addList[i]);
893 tuIM->addBuddy( uri, Data::Empty );
894 }
895
896 for ( int i=0; i<numPub; i++ )
897 {
898 Uri uri(pubList[i]);
899 tuIM->addStateAgent( uri );
900 }
901
902 displayPres();
903
904 waddstr(textWin,"Use -help on the command line to view options\n");
905 waddstr(textWin,"To set where your messages will get sent type\n");
906 waddstr(textWin," to: sip:alice@example.com \n");
907 waddstr(textWin,"To monitores someeone presence type\n");
908 waddstr(textWin," add: sip:buddy@example.com \n");
909 waddstr(textWin,"To change you online status type\n");
910 waddstr(textWin," status: in meeting\n");
911 waddstr(textWin,"To set yourself to offline type\n");
912 waddstr(textWin," status:\n");
913 waddstr(textWin,"To exit type a single period\n");
914 waddstr(textWin,"\n");
915 wrefresh(textWin);
916
917 while (1)
918 {
919 FdSet fdset;
920 sipStack.buildFdSet(fdset);
921 int time = sipStack.getTimeTillNextProcessMS();
922
923 fdset.setRead( fileno(stdin) );
924
925 //cerr << time << endl;
926
927 int err = fdset.selectMilliSeconds( time );
928 if ( err == -1 )
929 {
930 int e = errno;
931 switch (e)
932 {
933 case 0:
934 break;
935 default:
936 //InfoLog(<< "Error " << e << " " << strerror(e) << " in select");
937 break;
938 }
939 }
940 if ( err == 0 )
941 {
942 //cerr << "select timed out" << endl;
943 }
944 if ( err > 0 )
945 {
946 //cerr << "select has " << err << " fd ready" << endl;
947 }
948
949 ////InfoLog(<< "Select returned");
950
951 if ( fdset.readyToRead( fileno(stdin) ) )
952 {
953 bool keepGoing = processStdin(&dest,sign,encryp);
954 if (!keepGoing)
955 {
956 break;
957 }
958 }
959
960 // //DebugLog ( << "Try TO PROCESS " );
961 try
962 {
963 sipStack.process(fdset);
964 }
965 catch (...)
966 {
967 ErrLog( << "Got a exception from sipStack::process" );
968 }
969
970 try
971 {
972 tuIM->process();
973 }
974 catch (...)
975 {
976 ErrLog( << "Got a exception passed from TuIM::process" );
977 }
978 }
979
980 return 0;
981 }
982 /* ====================================================================
983 * The Vovida Software License, Version 1.0
984 *
985 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
986 *
987 * Redistribution and use in source and binary forms, with or without
988 * modification, are permitted provided that the following conditions
989 * are met:
990 *
991 * 1. Redistributions of source code must retain the above copyright
992 * notice, this list of conditions and the following disclaimer.
993 *
994 * 2. Redistributions in binary form must reproduce the above copyright
995 * notice, this list of conditions and the following disclaimer in
996 * the documentation and/or other materials provided with the
997 * distribution.
998 *
999 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
1000 * and "Vovida Open Communication Application Library (VOCAL)" must
1001 * not be used to endorse or promote products derived from this
1002 * software without prior written permission. For written
1003 * permission, please contact vocal@vovida.org.
1004 *
1005 * 4. Products derived from this software may not be called "VOCAL", nor
1006 * may "VOCAL" appear in their name, without prior written
1007 * permission of Vovida Networks, Inc.
1008 *
1009 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
1010 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1011 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
1012 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
1013 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
1014 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
1015 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1016 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1017 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
1018 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1019 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
1020 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1021 * DAMAGE.
1022 *
1023 * ====================================================================
1024 *
1025 * This software consists of voluntary contributions made by Vovida
1026 * Networks, Inc. and many individuals on behalf of Vovida Networks,
1027 * Inc. For more information on Vovida Networks, Inc., please see
1028 * <http://www.vovida.org/>.
1029 *
1030 */

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27