Here are some samples about PJLIB!
PJLIB is the basic lib of PJSIP, so we need master the lib first!
String:
In our project, string is often used.But in a project based on PJSIP,we should learn to use pj_str_t instead of C string.Of course there have lots functions for you to convert the string type.
First you should know the struct of pj_str_t,and you need to use the function of pj_str to creat a pj_str_t type from a normal C string.
And lots of function are same like the C/C++ stytle,you can use them easily if you know the C/C++.
1 //test for pjlib heat nan 2 // string 3 #include<pjlib.h> 4 #include<pj/string.h> 5 #include<stdio.h> 6 void compare(const pj_str_t* s1,const pj_str_t* s2) 7 { 8 9 pj_status_t status; 10 status=pj_strcmp(s1,s2); 11 if(status<0) 12 { 13 printf("s1<s2\n"); 14 } 15 else if(status==0) 16 { 17 printf("s1=s2\n"); 18 } 19 else 20 { 21 printf("s1>s2\n"); 22 } 23 } 24 int main() 25 { 26 char *str="this is a string"; 27 pj_status_t status; 28 pj_str_t s1,s2,s3; 29 status=pj_init(); 30 if(status!=PJ_SUCCESS) 31 { 32 printf("pj_init failed\n"); 33 } 34 s1=pj_str("helloworld"); 35 s2=pj_str("heat nan"); 36 37 38 printf("s1=%s\n",s1.ptr); 39 printf("s2=%s\n",s2.ptr); 40 printf("len1=%d;len2=%d\n",s1.slen,s2.slen); 41 //Create string initializer from a normal C string 42 //pj_str_t pj_str ( char * str ) 43 printf("now we use the function pj_str creat a pj_str_t type string from normal C string"); 44 s3=pj_str(str); 45 puts(s3.ptr); 46 printf("****************************************\n"); 47 // 48 49 //function pj_strcmp 50 printf("now we have a compare about the the two string!\n"); 51 compare(&s1,&s2); 52 printf("****************************************\n"); 53 54 pj_shutdown(); 55 getchar(); 56 return 0; 57 58 }