예제 #1
0
		return -1;
	}

	if(pvs->setf==NULL) {
		LM_ERR("read only output var [%.*s]\n", spv->len, spv->s);
		return -1;
	}

	return janssonmod_get_helper(msg, spath, sdoc, pvs);
}

/**
 *
 */
static sr_kemi_t sr_kemi_jansson_exports[] = {
	{ str_init("jansson"), str_init("get"),
		SR_KEMIP_INT, ki_jansson_get,
		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
	},

	{{0, 0}, {0, 0}, 0, NULL, {0, 0, 0, 0, 0, 0}}
};

/**
 *
 */
int mod_register(char *path, int *dlflags, void *p1, void *p2)
{
	sr_kemi_modules_add(sr_kemi_jansson_exports);
	return 0;
예제 #2
0
					}
				}

	/* got here, it means all unknown params in first URI have been resolved
		=> first URI matched second URI, and the other way around
	*/

headers_check:
	 /* XXX Do we really care ? */
	compare_uri_val(headers,strncasecmp);
	return 0;
}

static const str uri_type_names[6] = {
	{NULL, 0}, /*This is the error type*/
	str_init("sip"),
	str_init("sips"),
	str_init("tel"),
	str_init("tels"),
	str_init("urn:service")
};

char* uri_type2str(const uri_type type, char *result)
{
	if (type == ERROR_URI_T)
		return NULL;

	memcpy(result, uri_type_names[type].s, uri_type_names[type].len);
	return result + uri_type_names[type].len;
}
예제 #3
0
int b2bl_key_avp_name;
unsigned short b2bl_key_avp_type;
static str b2bl_key_avp_param = {NULL, 0};

static str b2bl_from_spec_param = {NULL, 0};
static pv_spec_t b2bl_from_spec;
static pv_value_t b2bl_from_tok;
static struct to_body b2bl_from;

#define B2BL_FROM_BUF_LEN    255
static char b2bl_from_buf[B2BL_FROM_BUF_LEN + 1];

str db_url= {0, 0};
db_con_t *b2bl_db = NULL;
db_func_t b2bl_dbf;
str b2bl_dbtable= str_init("b2b_logic");
str init_callid_hdr={0, 0};

str server_address = {0, 0};
int b2bl_db_mode = WRITE_BACK;
int unsigned b2bl_th_init_timeout = 60;

static cmd_export_t cmds[]=
{
	{"b2b_init_request", (cmd_function)b2b_init_request, {
		{CMD_PARAM_STR, fixup_b2b_logic, fixup_free_b2b_logic},
		{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
		{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
		{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
		{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
		REQUEST_ROUTE},
예제 #4
0
파일: gesave.c 프로젝트: Refandler/gentee
uint STDCALL ge_save( pvmEngine pThis, char* fileName, char* isSave)
{
    gehead   head;
    pgehead  phead;
    uint     i, ii, count;
    pvmobj   pvmo;
    buf       out;
    str  filename;
    if ( setjmp( pThis->stack_state) == -1 ) 
        return 0;

    str_init( pThis, &filename );
    str_copyzero( pThis, &filename, fileName );
    buf_init( pThis, &out );

    pThis->gesave = &out;
    buf_reserve( pThis, &out, 0x1ffff );

   *( puint )&head.idname = GE_STRING;//0x00004547;   // строка GE
   head.flags = 0;
   head.crc = 0;
   head.headsize = sizeof( gehead );
   head.size = 0;
   head.vermajor = GEVER_MAJOR; 
   head.verminor = GEVER_MINOR; 
   
   buf_append( pThis, &out, ( pubyte )&head, sizeof( gehead ));
   // Save resources at the first !
   gesave_resource(pThis);

   count = arr_count( pThis, &pThis->_vm.objtbl );
   for ( i = KERNEL_COUNT; i < count ; i++ )
   {
      if(isSave && isSave[i] == 0)
      {
         /* gesave_addubyte( pThis, OVM_NONE );
          gesave_adduint( pThis, GHCOM_PACK);
          gesave_bwd( pThis, 6 );*/
          pThis->popravka ++;
          continue;
      }

      pvmo = ( pvmobj )PCMD( i );
      pvmo->id -= pThis->popravka;
      //@init @delete @array @oftype @index -не удалять имена
      if(pThis->isDelName&&(pvmo->flag&GHCOM_NAME)&&pvmo->name&&lstrcmpA("@init",pvmo->name)&&
          lstrcmpA("@delete",pvmo->name)&&lstrcmpA("@array",pvmo->name)&&
          lstrcmpA("@oftype",pvmo->name)&&lstrcmpA("@index",pvmo->name))
      {
          pvmo->flag &= ~GHCOM_NAME;
      }else
          if(pvmo->name)
             pvmo->flag |= ~GHCOM_NAME;

      gesave_head( pThis, pvmo->type, pvmo->flag & GHCOM_NAME ? 
          pvmo->name : NULL, pvmo->flag );
      
      switch ( pvmo->type )
      {
         case OVM_NONE:
            break;
         case OVM_BYTECODE:
            gesave_bytecode( pThis, ( povmbcode )pvmo );
            break;
         case OVM_EXFUNC:
            ((povmfunc)pvmo)->import = ((pvmobj)PCMD(((povmfunc)pvmo)->import))->id;
            gesave_exfunc( pThis, ( povmfunc )pvmo );
            break;
         case OVM_TYPE:
             {
                for(ii = 0; ii<((povmtype)pvmo)->count; ii++)
                {
                    if(pThis->isDelName)
                        ((povmtype)pvmo)->children[ii].flag &=~GHCOM_NAME;
                    else if(((povmtype)pvmo)->children[ii].name)
                        ((povmtype)pvmo)->children[ii].flag |=GHCOM_NAME;
                }
                gesave_type( pThis, ( povmtype )pvmo );
             }break;
         case OVM_GLOBAL:
            gesave_var( pThis, (( povmglobal )pvmo)->type );
            break;
         case OVM_DEFINE:
            gesave_define( pThis, ( povmdefine )pvmo );
            break;
         case OVM_IMPORT:
            gesave_import( pThis, ( povmimport )pvmo );
            break;
         case OVM_ALIAS:
            gesave_bwd( pThis, (( povmalias )pvmo)->idlink );
            break;
      }
      gesave_finish(pThis);
   }
   // Specify the full size and crc
   phead = ( pgehead )buf_ptr( pThis, &out );
   phead->size = buf_len( pThis, &out );
   phead->crc = crc( pThis, ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF );
   buf2file( pThis, &filename, &out );
   buf_delete( pThis, &out );
   str_delete( pThis, &filename );
   return 1;
}
예제 #5
0
static int rules_num;  /* Number of parsed allow/deny files */


/* Module parameter variables */
static char* default_allow_file = DEFAULT_ALLOW_FILE;
static char* default_deny_file = DEFAULT_DENY_FILE;
char* allow_suffix = ".allow";
static char* deny_suffix = ".deny";


/* for allow_trusted and allow_address function */
str db_url = {NULL, 0};                    /* Don't connect to the database by default */

/* for allow_trusted function */
int db_mode = DISABLE_CACHE;               /* Database usage mode: 0=no cache, 1=cache */
str trusted_table = str_init("trusted");   /* Name of trusted table */
str source_col = str_init("src_ip");       /* Name of source address column */
str proto_col = str_init("proto");         /* Name of protocol column */
str from_col = str_init("from_pattern");   /* Name of from pattern column */
str ruri_col = str_init("ruri_pattern");   /* Name of RURI pattern column */
str tag_col = str_init("tag");             /* Name of tag column */
str priority_col = str_init("priority");   /* Name of priority column */
str tag_avp_param = {NULL, 0};             /* Peer tag AVP spec */
int peer_tag_mode = 0;                     /* Add tags form all mathcing peers to avp */

/* for allow_address function */
str address_table = str_init("address");   /* Name of address table */
str grp_col = str_init("grp");             /* Name of address group column */
str ip_addr_col = str_init("ip_addr");     /* Name of ip address column */
str mask_col = str_init("mask");           /* Name of mask column */
str port_col = str_init("port");           /* Name of port column */
예제 #6
0
파일: rx.c 프로젝트: castro732/X-Weather
/************************************************************************
*  Main Program  *****  Programa Principal                              *
************************************************************************/
void main()
{

   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
   setup_timer_2(T2_DIV_BY_16,0xFF,16);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   setup_adc( ADC_OFF );

   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT1);
   enable_interrupts(global);
   

   str_init(print_date);
   str_init(print_time);
   
   
   
   
   
   set_timer1(0);
   
   init_ext_eeprom();
   ds1307_init();
   glcd_init(ON);    

   

   readconfig();

      
  

   draw_sect();

   while (1)
   { 
      
      
      
      if (firstrun==255)
      {
         glcd_fillscreen(OFF);
         glcd_loadscreen();
         glcd_showlogo();
         delay_ms(1500);
         menu_mainmenu();
         firstrun = 0;
         write_eeprom(0x00, firstrun);
      }
      
      if (config==1)
      {   
         menu_mainmenu();
         if(UniTemp[0]==0x43)
         {
            write_eeprom(0x01, 1);
         }
         else if(UniTemp[0]==0x46)
         {
            write_eeprom(0x01, 2);
         }
         if(UniPres[0]==0x6D)
         {
            write_eeprom(0x02, 1);
         }
         else if(UniPres[0]==0x50)
         {
            write_eeprom(0x02, 2);
         }
         if(UniVel[0]==0x4E)
         {
            write_eeprom(0x03, 1);
         }
         else if(UniVel[0]==0x6B)
         {
            write_eeprom(0x03, 2);
         }
         else if(UniVel[0]==0x6D)
         {
            write_eeprom(0x03, 3);
         }
         
         update_readings();
         
         button = !PRESSED;
         config=0;
      }
      
      if (uh>40)
      {
       
         twop[0]=":";
         guion[0]="-";
         spa[0]=" ";  

         str_init(print_time);
         str_init(print_date);
         
         ds1307_get_time(aux_hr,aux_min,aux_sec);
         ds1307_get_date(aux_day, aux_month, aux_year, aux_dow);

         itoa(aux_day,10,print_day);
         itoa(aux_month,10,print_month);
         itoa(aux_year,10,print_year);
         switch(aux_dow)
         {
            case 0:
            {
               print_dow[0] = "D";
               break;
            }
            case 1:
            {
               print_dow[0] = "L";
               break;
            }
            case 2:
            {
               print_dow[0] = "M";
               break;
            }
            case 3:
            {
               print_dow[0] = "I";
               break;
            }
            case 4:
            {
               print_dow[0] = "J";
               break;
            }
            case 5:
            {
               print_dow[0] = "V";
               break;
            }
            case 6:
            {
               print_dow[0] = "S";
               break;
            }
         }
         sprintf(print_date,"%s:%s-%s-%s",print_dow,print_day,print_month,print_year);
         //strcat(print_date,print_dow);
         //strcat(print_date,twop);
         //strcat(print_date,print_day);
         //strcat(print_date,guion);
        // strcat(print_date,print_month);
         //strcat(print_date,guion);
         //strcat(print_date,print_year);

         if(aop[0]==0x50)
         {
            aux_hr=aux_hr-20;
         }
         itoa(aux_hr,10,print_hr);
         itoa(aux_min,10,print_min);
         strcat(print_time,print_hr);
         strcat(print_time,twop);
         strcat(print_time,print_min);
         
         if ((aop[0]==0x41)||(aop[0]==0x50))
         {
            strcat(print_time,twop);
            strcat(print_time,aop);
         }
         


         
         rcv_td=1;
         uh=0;
      }

      poll_ok();
      lightbuttons();

      while(bkbhit) 
      {
         
         auxi = bgetc();
         switch (auxi)
         {
            case 0x54:     //T
            {
               type=1;
               str_init(string);
               break;
            }
            case 0x50:     //P
            {
               type=2;
               str_init(string);
               break;
            }
            case 0x48:     //H
            {
               type=3;
               str_init(string);
               break;
            }
            case 0x41:     //A
            {
               type=4;
               str_init(string);
               break;
            }
            case 0x57:     //W
            {
               type=5;
               str_init(string);
               break;
            }
            case 0x52:     //R 
            {
               type=6;
               str_init(string);
               break;
            }
            case 0x44:     //D
            {
               type=7;
               str_init(string);
               break;
            }
            case 0x4C:     //L
            {
               type=8;
               str_init(string);
               break;
            }
            case 0x56:     //V
            {
               type=9;
               str_init(string);
               break;
            }
            case 0x42:     //B
            {
               type=10;
               str_init(string);
               break;
            }         
            
         }
         
         switch (type)
         {
            case 1:                 //Temperatura
            {
               if ((auxi!=0x0D)&&(auxi!=0x54))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  str_init(tprint);
                  tt = atol(string);  

                  if(UniTemp[0]==0x46)
                  {
                     tt = ((tt*9)/5)+320;
                  }

                  strcat(temp_buffer_eeprom,string);
                  eep+=3;

                  sprintf(ttt,"%3.1w",tt);
                  strcat(tprint,ttt);
                  strcat(tprint,UniTemp);

                  strcpy(t2_print,tprint);

                  rcv_t=1;
               }
               break;
            }
            case 2:                 //Presion
            {
               if ((auxi!=0x0D)&&(auxi!=0x50))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  str_init(pprint);
                  pp = atoi32(string);

                  if(UniPres[0]==0x50)
                  {
                     pp = pp*10;
                     sprintf(ppp,"%6.0w",pp);
                     strcat(pprint,ppp);
                     strcat(pprint,UniPres);  
                  }
                  else
                  {
                     sprintf(ppp,"%4.1w",pp);
                     strcat(pprint,ppp);
                     strcat(pprint,UniPres);  
                  }

                  rcv_p=1;
                  
               }
               break;
            }
            case 3:                 //Humedad
            {
               if ((auxi!=0x0D)&&(auxi!=0x48))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  char uni[]="%";
                  str_init(hprint);
                  hh = atol(string);
                  sprintf(hhh,"%2.1w",hh);
                  strcat(hprint,hhh);
                  strcat(hprint,uni);

                  rcv_h=1;
               }
               break;
            }
            case 4:                 //Altitud
            {
               if ((auxi!=0x0D)&&(auxi!=0x41))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  char uni[]="m";
                  str_init(aprint);
                  aa = atol(string);
                  sprintf(aaa,"%5.1w",aa);
                  strcat(aprint,aaa);
                  strcat(aprint,uni);

                  rcv_a=1;
                    
               }
               break;
            }
            case 5:                 //Clima
            {
               if ((auxi!=0x0D)&&(auxi!=0x57))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;                  
                  
                  ww = atoi(string);
                                    
                  rcv_w=1;
               }
               break;
            }
            case 6:                 //Probabilidad de lluvia
            {
               if ((auxi!=0x0D)&&(auxi!=0x52))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;

                  char uni[]="%";
                  str_init(pdlprint);
                  ppdl = atol(string);
                  sprintf(pppdl,"%2.0w",ppdl);
                  strcat(pdlprint,pppdl);
                  strcat(pdlprint,uni);
                  
                  rcv_pdl=1;
               }
               break;
            }
            case 7:                 //Direccion del viento
            {
               if ((auxi!=0x0D)&&(auxi!=0x44))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  
                  str_init(dprint);
                  dd = atol(string);
                  switch(dd)
                  {
                     case 0:
                     {
                        dprint[0]="N";
                        dprint[1]="\0";
                        break;
                     }
                     case 1:
                     {
                        dprint[0]="N";
                        dprint[1]="E";
                        dprint[2]="\0";
                        break;
                     }
                     case 2:
                     {
                        dprint[0]="E";
                        dprint[1]="\0";
                        break;
                     }
                     case 3:
                     {
                        dprint[0]="S";
                        dprint[1]="E";
                        dprint[2]="\0";
                        break;
                     }
                     case 4:
                     {
                        dprint[0]="S";
                        dprint[1]="\0";
                        break;
                     }
                     case 5:
                     {
                        dprint[0]="S";
                        dprint[1]="O";
                        dprint[2]="\0";
                        break;
                     }
                     case 6:
                     {
                        dprint[0]="O";
                        dprint[1]="\0";
                        break;
                     }
                     case 7:
                     {
                        dprint[0]="N";
                        dprint[1]="O";
                        dprint[2]="\0";
                        break;
                     }
                  }
                  
                  rcv_d=1;           
               }
               break;
            }
            case 8:                 //Intensidad de luz
            {
               if ((auxi!=0x0D)&&(auxi!=0x4C))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;                  
                  
                  ll = atoi(string);
                  ll = ll*6.3+67;
                  
                  rcv_l=1;
               }
               break;
            }
            case 9:                 //Velocidad del viento
            {
               if ((auxi!=0x0D)&&(auxi!=0x56))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  
                  str_init(vprint);
                  vv = atoi32(string);

                  if(UniVel[0]==0x6D)
                  {
                     vv = vv * 0.5144;
                  }
                  else if(UniVel[0]==0x6B)
                  {
                     vv = vv * 1.852;
                  }
                  else
                  {

                  }

                  sprintf(vvv,"%4.1w",vv);
                  strcat(vprint,vvv);
                  strcat(vprint,UniVel);  

                  
                  rcv_v=1;
               }
               break;
            }
            case 10:                //Bat Status
            {
               if ((auxi!=0x0D)&&(auxi!=0x42))
               {
                  string[i] = auxi;
                  i++;
               }
               if (auxi==0x0D)
               {
                  i=0;
                  
                  
                  bat1_st = atoi(string);
                  
                  rcv_bat1_st=1;
               }
               break;
            }
            
         }

         if(eep>=9)
         {
            update_eeprom();
            eep=0;
         }
         update_readings();
         glcd_update();
         //END KBHIT 
      }
      

      
      glcd_update();
      //ENDWHILE
   }
//ENDMAIN
}
예제 #7
0
int b2b_entities_bind(b2b_api_t* api);
static mi_response_t *mi_b2be_list(const mi_params_t *params,
								struct mi_handler *async_hdl);

/** Global variables */
unsigned int server_hsize = 9;
unsigned int client_hsize = 9;
static char* script_req_route = NULL;
static char* script_reply_route = NULL;
int req_routeid  = -1;
int reply_routeid = -1;
int replication_mode= 0;
static str db_url= {0, 0};
db_con_t *b2be_db = NULL;
db_func_t b2be_dbf;
str b2be_dbtable= str_init("b2b_entities");
static int b2b_update_period = 100;
int uac_auth_loaded;
str b2b_key_prefix = str_init("B2B");
int b2be_db_mode = WRITE_BACK;

#define DB_COLS_NO  26

/* TM bind */
struct tm_binds tmb;

/* UAC_AUTH bind */
uac_auth_api_t uac_auth_api;

/** Exported functions */
static cmd_export_t cmds[] = {
예제 #8
0
/*
 * timer interval length in seconds, tunable via modparam
 */
#define RL_TIMER_INTERVAL 10

/** SL API structure */
sl_api_t slb;

enum {
	LOAD_SOURCE_CPU,
	LOAD_SOURCE_EXTERNAL
};

str_map_t source_names[] = {
	{str_init("cpu"),	LOAD_SOURCE_CPU},
	{str_init("external"),	LOAD_SOURCE_EXTERNAL},
	{{0, 0},		0},
};

static int pl_drop_code = 503;
static str pl_drop_reason = str_init("Server Unavailable");
static int pl_hash_size = 6;

typedef struct pl_queue {
	int     *       pipe;
	int             pipe_mp;
	str     *       method;
	str             method_mp;
} pl_queue_t;
예제 #9
0
#include "cpl_sig.h"
#include "cpl_env.h"
#include "cpl_run.h"


#define EO_SCRIPT            ((char*)0xffffffff)
#define DEFAULT_ACTION       ((char*)0xfffffffe)
#define CPL_SCRIPT_ERROR     ((char*)0xfffffffd)
#define CPL_RUNTIME_ERROR    ((char*)0xfffffffc)
#define CPL_TO_CONTINUE      ((char*)0xfffffffb)

#define HDR_NOT_FOUND        ((char*)0xffffffff)
#define UNDEF_CHAR           (0xff)


static str cpl_301_reason = str_init("Moved permanently");
static str cpl_302_reason = str_init("Moved temporarily");

#define check_overflow_by_ptr(_ptr_,_intr_,_error_) \
	do {\
		if ( (char*)(_ptr_)>(_intr_)->script.len+(_intr_)->script.s ) {\
			LM_ERR("overflow detected ip=%p ptr=%p in "\
			"func. %s, line %d\n",(_intr_)->ip,_ptr_,__FILE__,__LINE__);\
			goto _error_; \
		} \
	}while(0)

#define check_overflow_by_offset(_len_,_intr_,_error_) \
	do {\
		if ( (char*)((_intr_)->ip+(_len_)) > \
		(_intr_)->script.len+(_intr_)->script.s ) {\
예제 #10
0
 */

#include <regex.h>
#include "ldap.h"

#include "h350_mod.h"
#include "h350_exp_fn.h"

#include "../../pvar.h"
#include "../../ut.h"
#include "../../mem/mem.h"

#define H350_SIPURI_LOOKUP_LDAP_FILTER "(&(objectClass=SIPIdentity)(SIPIdentitySIPURI=%s))"
#define H350_AUTH_FILTER_PATTERN "(&(objectClass=SIPIdentity)(SIPIdentityUserName=%s))"

static str h350_call_pref_name = str_init("callPreferenceURI");
static str h350_sip_pwd_name = str_init("SIPIdentityPassword");
static str h350_service_level_name = str_init("SIPIdentityServiceLevel");

#define H350_CALL_PREF_REGEX "^([^ ]+) +([a-zA-Z]+)(:([0-9]+))?$"

#define SIP_URI_ESCAPED_MAX_LEN 1024
#define AVP_NAME_STR_BUF_LEN 1024
#define DIGEST_USERNAME_BUF_SIZE 2048

static regex_t* call_pref_preg;

int h350_sipuri_lookup(struct sip_msg* _msg, pv_elem_t* _sip_uri)
{
	str sip_uri, sip_uri_escaped;
	int ld_result_count;
예제 #11
0
 * @{
 *
 * <h1>Overview of Operation</h1>
 * This module provides a web interface for RPC management interface.
 * It is built on top of the xhttp API module.
 */

/** @file
 *
 * This is the main file of xhttp_rpc module which contains all the functions
 * related to http processing, as well as the module interface.
 */

MODULE_VERSION

str XHTTP_RPC_REASON_OK = str_init("OK");
str XHTTP_RPC_CONTENT_TYPE_TEXT_HTML = str_init("text/html");


xhttp_rpc_mod_cmds_t *xhttp_rpc_mod_cmds = NULL;
int xhttp_rpc_mod_cmds_size = 0;

/* FIXME: this should be initialized in ../../core/ver.c */
int full_version_len;
int ver_name_len;

static int mod_init(void);
static int child_init(int rank);
static int xhttp_rpc_dispatch(sip_msg_t* msg, char* s1, char* s2);

예제 #12
0
void str_deinit(string *str) {
    if (str->data != NULL) {
        free((void*)(str->data));
        str_init(str);
    }
}
예제 #13
0
파일: dispatcher.c 프로젝트: gbour/kamailio
static int** ds_ping_reply_codes = NULL;
static int* ds_ping_reply_codes_cnt;

int ds_hash_size = 0;
int ds_hash_expire = 7200;
int ds_hash_initexpire = 7200;
int ds_hash_check_interval = 30;

str ds_outbound_proxy = {0, 0};

/* tm */
struct tm_binds tmb;

/*db */
str ds_db_url            = {NULL, 0};
str ds_set_id_col        = str_init(DS_SET_ID_COL);
str ds_dest_uri_col      = str_init(DS_DEST_URI_COL);
str ds_dest_flags_col    = str_init(DS_DEST_FLAGS_COL);
str ds_dest_priority_col = str_init(DS_DEST_PRIORITY_COL);
str ds_dest_attrs_col    = str_init(DS_DEST_ATTRS_COL);
str ds_table_name        = str_init(DS_TABLE_NAME);

str ds_setid_pvname   = {NULL, 0};
pv_spec_t ds_setid_pv;
str ds_attrs_pvname   = {NULL, 0};
pv_spec_t ds_attrs_pv;

/** module functions */
static int mod_init(void);
static int child_init(int);
예제 #14
0
파일: matrix.c 프로젝트: krys1976/kamailio
#include "../../core/rpc_lookup.h"


#include "db_matrix.h"

MODULE_VERSION




#define MAXCOLS 1000




str matrix_db_url = str_init(DEFAULT_RODB_URL);




/**
 * Generic parameter that holds a string, an int or an pseudo-variable
 * @todo replace this with gparam_t
 */
struct multiparam_t {
	enum {
		MP_INT,
		MP_STR,
		MP_AVP,
		MP_PVE,
	} type;
예제 #15
0
#define DOMAIN_ATTRS_TABLE_VERSION 1

#define DOMAIN_TABLE "domain"
#define DOMAIN_ATTRS_TABLE "domain_attrs"
#define DID_COL "did"
#define DOMAIN_COL "domain"
#define NAME_COL "name"
#define TYPE_COL "type"
#define VALUE_COL "value"

static int domain_init_rpc(void);

/*
 * Module parameter variables
 */
str db_url = str_init(DEFAULT_RODB_URL);
str domain_table = str_init(DOMAIN_TABLE); /* Name of domain table */
str domain_attrs_table = str_init(DOMAIN_ATTRS_TABLE);
str did_col = str_init(DID_COL);       /* Name of domain id column */
str domain_col = str_init(DOMAIN_COL);       /* Name of domain column */
str name_col = str_init(NAME_COL);   /* Name of attribute name column */
str type_col = str_init(TYPE_COL);   /* Name of attribute type column */
str value_col = str_init(VALUE_COL); /* Name of attribute value column */
int domain_reg_myself = 0;

/*
 * Other module variables
 */
struct domain_list ***hash_table = 0;	/* Pointer to current hash table pointer */
struct domain_list **hash_table_1 = 0;	/* Pointer to hash table 1 */
struct domain_list **hash_table_2 = 0;	/* Pointer to hash table 2 */
예제 #16
0
#include "../../dprint.h"
#include "../../mem/mem.h"
#include "../../mem/shm_mem.h"
#include "../../ut.h"
#include "../../error.h"
#include "../../prime_hash.h"
#include "../../db/db.h"
#include "carrierroute.h"
#include "load_data.h"
#include "route_fifo.h"
#include "carrier_tree.h"
#include "route_func.h"


str db_url = {NULL, 0};
str db_table = str_init("carrierroute");
str db_failure_table = str_init("carrierfailureroute");
str subscriber_table = str_init("subscriber");
str carrier_table = str_init("route_tree");

static str id_col = str_init("id");
static str carrier_col = str_init("carrier");
static str domain_col = str_init("domain");
static str scan_prefix_col = str_init("scan_prefix");
static str flags_col = str_init("flags");
static str mask_col = str_init("mask");
static str prob_col = str_init("prob");
static str rewrite_host_col = str_init("rewrite_host");
static str strip_col = str_init("strip");
static str rewrite_prefix_col = str_init("rewrite_prefix");
static str rewrite_suffix_col = str_init("rewrite_suffix");
예제 #17
0
		tprefix VARCHAR(32) NOT NULL,
		tvalue VARCHAR(128) DEFAULT '' NOT NULL,
		CONSTRAINT tprefix_idx UNIQUE (tprefix)
		) ENGINE=MyISAM;
INSERT INTO version (table_name, table_version) values ('mtrees','1');
CREATE TABLE mtrees (
		id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
		tname VARCHAR(128) NOT NULL,
		tprefix VARCHAR(32) NOT NULL,
		tvalue VARCHAR(128) DEFAULT '' NOT NULL,
		CONSTRAINT tname_tprefix_idx UNIQUE (tname, tprefix)
		) ENGINE=MyISAM;
#endif

/** parameters */
static str db_url = str_init(DEFAULT_DB_URL);
/* default name created by sql scripts is 'mtrees'
 * - don't set it here with default value, only via config param */
static str db_table = str_init("");
static str tname_column   = str_init("tname");
static str tprefix_column = str_init("tprefix");
static str tvalue_column  = str_init("tvalue");

/* List of allowed chars for a prefix*/
str mt_char_list = str_init("0123456789");

static str value_param = str_init("$avp(s:tvalue)");
static str values_param = str_init("$avp(s:tvalues)");
static str dstid_param = str_init("$avp(s:tdstid)");
static str weight_param = str_init("$avp(s:tweight)");
static str count_param = str_init("$avp(s:tcount)");
예제 #18
0
파일: dbase.c 프로젝트: vladpaiu/opensips
#include <mysql/mysqld_error.h>
#include <mysql/mysql_version.h>
#include "../../mem/mem.h"
#include "../../dprint.h"
#include "../../db/db_query.h"
#include "../../db/db_async.h"
#include "../../db/db_ut.h"
#include "../../db/db_insertq.h"
#include "val.h"
#include "my_con.h"
#include "res.h"
#include "row.h"
#include "db_mysql.h"
#include "dbase.h"

static str mysql_event_name = str_init("E_MYSQL_CONNECTION");
static str mysql_url_str = str_init("url");
static str mysql_stat_str = str_init("status");
static str mysql_stat_connected_str = str_init("connected");
static str mysql_stat_disconnected_str = str_init("disconnected");
static event_id_t mysql_evi_id = EVI_ERROR;
static int mysql_last_event = 0; /* ensures an event is
									raised only when status changes */

int mysql_register_event(void)
{
	mysql_evi_id = evi_publish_event(mysql_event_name);
	if (mysql_evi_id == EVI_ERROR) {
		LM_ERR("cannot register event\n");
		return -1;
	}
예제 #19
0
파일: rx.c 프로젝트: castro732/X-Weather
void main()
{

   
   
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT1);
   enable_interrupts(global);
   
   setup_psp(PSP_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   setup_adc( ADC_OFF );


   //setup_adc_ports(NO_ANALOGS|VREF_VREF);


  // setup_oscillator(OSC_8MHZ|OSC_TIMER1|OSC_PLL_OFF);   
   
   
   glcd_init(ON);    
   
   
   
         int8 axt,axp,axv;
         axt = read_eeprom(0x01);
         axp = read_eeprom(0x02);
         axv = read_eeprom(0x03);
   
         if(axt==1)
         {
            UniTemp[0]="C";
         }
         if(axt==2)
         {
            UniTemp[0]="F";
         }
         if(axp==1)
         {
            UniPres[0]="Pa";
         }
         if(axp==2)
         {
            UniPres[0]="mBa";
         }
         if(axv==1)
         {
            UniVel[0]="m/s";
         }
         if(axv==2)
         {
            UniVel[0]="km/h";
         }
         if(axv==3)
         {
            UniVel[0]="Nud";
         }
         
         
         
   
  
   
   int16 auxi;
   int8 type,z;
   int8 string[10];
   int16 tt;
   int32 pp;
   char tprint [15];
   char pprint [15];
   char ttt[10];
   char ppp[10];
      char temp[] = "T:";
      char pres[] = "P:";
      
   for (z=0;z<15;z++)
      {
         tprint[z]=0;
         pprint[z]=0;
      }
   //firstrun = read_eeprom(0x00);      
  

      draw_sect();
   while (1)
   {
     
      
      
      
      if (firstrun==71)
      {
         glcd_loadscreen();
         glcd_showlogo();
         delay_ms(1500);
         menu_mainmenu();
         firstrun = 0;
         write_eeprom(0x00, firstrun);
      }
      
      if (config==1)
      {
        
        
        
        
        
         menu_mainmenu();
         if(UniTemp[1]=="C")
         {
            write_eeprom(0x01, 1);
         }
         else if(UniTemp[1]=="F")
         {
            write_eeprom(0x01, 2);
         }
         if(UniPres[1]=="P")
         {
            write_eeprom(0x02, 1);
         }
         else if(UniPres[1]=="m")
         {
            write_eeprom(0x02, 2);
         }
         if(UniVel[1]=="m")
         {
            write_eeprom(0x03, 1);
         }
         else if(UniVel[1]=="k")
         {
            write_eeprom(0x03, 2);
         }
         else if(UniVel[1]=="N")
         {
            write_eeprom(0x03, 3);
         }
         
        
         
         pressed=0;
         config=0;
      }
      
      if (try==1)
      {
         
               try=0;
               output_toggle(PIN_C2);
      }
      
      while(bkbhit) 
      {
         auxi = bgetc();
         if (auxi==0x54)
         {
            type=1;
            for(i=0;i<15;i++)
            {                   
               string[i]=0x00;                          
            }
            i = 0;
         }
         if (auxi==0x50)
         {
            type=2;
            for(i=0;i<15;i++)
            {                   
               string[i]=0x00;                          
            }
            i = 0;
         }
         if (auxi!=0x0D)
         {
            
         }
         if (type==1)      //Temperatura
         {
         
            if ((auxi!=0x0D)&&(auxi!=0x54))
            {
               string[i] = auxi;
               i++;
            }
            if (auxi==0x0D)
            {
               str_init(tprint);
               tt = atol(string);  
               sprintf(ttt,"%3.1w",tt);
               strcat(tprint,temp);
               strcat(tprint,ttt);
               strcat(tprint,UniTemp);
                draw_sect();
               glcd_text_sec(1, 1, tprint, OFF);
               glcd_update();
               
            }
         }
         if (type==2)      //Presion
         {
            if ((auxi!=0x0D)&&(auxi!=0x50))
            {
               string[i] = auxi;
               i++;
            }
            if (auxi==0x0D)
            {
               str_init(pprint);
               pp = atoi32(string);
               sprintf(ppp,"%3.1w",pp);
               strcat(pprint,pres);
               strcat(pprint,ppp);
               strcat(pprint,UniPres);  
                draw_sect();
               glcd_text_sec(1, 2, pprint, OFF);
               glcd_update();
            }
         }
         
         glcd_update();
         //END KBHIT
      }
      
      
      glcd_update();
      //ENDWHILE
   }
//ENDMAIN
}
예제 #20
0
#include "enum_mod.h"
#include <stdio.h>
#include <stdlib.h>
#include "../../core/sr_module.h"
#include "../../core/error.h"
#include "../../core/mod_fix.h"
#include "enum.h"

MODULE_VERSION


/*
 * Module parameter variables
 */
str suffix = str_init("e164.arpa.");
str param = str_init("");
str i_branchlabel = str_init("i");
str i_suffix = str_init("e164.arpa.");
str i_bl_alg = str_init("cc");

str service = {0,0};

/*
 * Exported functions
 */
static cmd_export_t cmds[] = {
	{"enum_query", (cmd_function)enum_query_0, 0, 0, 0, REQUEST_ROUTE},
	{"enum_query", (cmd_function)enum_query_1, 1, fixup_spve_null, 0,
	 REQUEST_ROUTE},
	{"enum_query", (cmd_function)enum_query_2, 2, fixup_spve_str, 0,
예제 #21
0
static void control_udp_incoming(struct obj *obj, str *buf, struct sockaddr_in6 *sin, char *addr) {
	struct control_udp *u = (void *) obj;
	int ret;
	int ovec[100];
	char **out;
	struct msghdr mh;
	struct iovec iov[10];
	str cookie, *reply;

	ret = pcre_exec(u->parse_re, u->parse_ree, buf->s, buf->len, 0, 0, ovec, G_N_ELEMENTS(ovec));
	if (ret <= 0) {
		ret = pcre_exec(u->fallback_re, NULL, buf->s, buf->len, 0, 0, ovec, G_N_ELEMENTS(ovec));
		if (ret <= 0) {
			ilog(LOG_WARNING, "Unable to parse command line from udp:%s: %.*s", addr, STR_FMT(buf));
			return;
		}

		ilog(LOG_WARNING, "Failed to properly parse UDP command line '%.*s' from %s, using fallback RE", STR_FMT(buf), addr);

		pcre_get_substring_list(buf->s, ovec, ret, (const char ***) &out);

		ZERO(mh);
		mh.msg_name = sin;
		mh.msg_namelen = sizeof(*sin);
		mh.msg_iov = iov;

		iov[0].iov_base = (void *) out[RE_UDP_COOKIE];
		iov[0].iov_len = strlen(out[RE_UDP_COOKIE]);
		if (out[RE_UDP_UL_CMD] && (chrtoupper(out[RE_UDP_UL_CMD][0]) == 'U' || chrtoupper(out[RE_UDP_UL_CMD][0]) == 'L')) {
			iov[1].iov_base = (void *) out[4];
			iov[1].iov_len = strlen(out[4]);
			iov[2].iov_base = (void *) out[3];
			iov[2].iov_len = strlen(out[3]);
			iov[3].iov_base = "\n";
			iov[3].iov_len = 1;
			mh.msg_iovlen = 4;
		}
		else {
			iov[1].iov_base = " E8\n";
			iov[1].iov_len = 4;
			mh.msg_iovlen = 2;
		}

		sendmsg(u->udp_listener.fd, &mh, 0);

		pcre_free(out);

		return;
	}

	ilog(LOG_INFO, "Got valid command from udp:%s: %.*s", addr, STR_FMT(buf));

	pcre_get_substring_list(buf->s, ovec, ret, (const char ***) &out);

	str_init(&cookie, (void *) out[RE_UDP_COOKIE]);
	reply = cookie_cache_lookup(&u->cookie_cache, &cookie);
	if (reply) {
		ilog(LOG_INFO, "Detected command from udp:%s as a duplicate", addr);
		sendto(u->udp_listener.fd, reply->s, reply->len, 0, (struct sockaddr *) sin, sizeof(*sin));
		free(reply);
		goto out;
	}

	if (chrtoupper(out[RE_UDP_UL_CMD][0]) == 'U')
		reply = call_update_udp(out, u->callmaster);
	else if (chrtoupper(out[RE_UDP_UL_CMD][0]) == 'L')
		reply = call_lookup_udp(out, u->callmaster);
	else if (chrtoupper(out[RE_UDP_DQ_CMD][0]) == 'D')
		reply = call_delete_udp(out, u->callmaster);
	else if (chrtoupper(out[RE_UDP_DQ_CMD][0]) == 'Q')
		reply = call_query_udp(out, u->callmaster);
	else if (chrtoupper(out[RE_UDP_V_CMD][0]) == 'V') {
		ZERO(mh);
		mh.msg_name = sin;
		mh.msg_namelen = sizeof(*sin);
		mh.msg_iov = iov;
		mh.msg_iovlen = 2;

		iov[0].iov_base = (void *) out[RE_UDP_COOKIE];
		iov[0].iov_len = strlen(out[RE_UDP_COOKIE]);
		iov[1].iov_base = " ";
		iov[1].iov_len = 1;

		if (chrtoupper(out[RE_UDP_V_FLAGS][0]) == 'F') {
			ret = 0;
			if (!strcmp(out[RE_UDP_V_PARMS], "20040107"))
				ret = 1;
			else if (!strcmp(out[RE_UDP_V_PARMS], "20050322"))
				ret = 1;
			else if (!strcmp(out[RE_UDP_V_PARMS], "20060704"))
				ret = 1;
			iov[2].iov_base = ret ? "1\n" : "0\n";
			iov[2].iov_len = 2;
			mh.msg_iovlen++;
		}
		else {
			iov[2].iov_base = "20040107\n";
			iov[2].iov_len = 9;
			mh.msg_iovlen++;
		}
		sendmsg(u->udp_listener.fd, &mh, 0);
	}

	if (reply) {
		sendto(u->udp_listener.fd, reply->s, reply->len, 0, (struct sockaddr *) sin, sizeof(*sin));
		cookie_cache_insert(&u->cookie_cache, &cookie, reply);
		free(reply);
	}
	else
		cookie_cache_remove(&u->cookie_cache, &cookie);

out:
	pcre_free(out);
	log_info_clear();
}
예제 #22
0
static void trace_onreq_in(struct cell* t, int type, struct tmcb_params *ps);
static void trace_onreq_out(struct cell* t, int type, struct tmcb_params *ps);
static void trace_onreply_in(struct cell* t, int type, struct tmcb_params *ps);
static void trace_onreply_out(struct cell* t, int type, struct tmcb_params *ps);
static void trace_sl_onreply_out(sl_cbp_t *slcb);
static void trace_sl_ack_in(sl_cbp_t *slcb);

static int trace_send_hep_duplicate(str *body, str *from, str *to, struct dest_info*);
static int pipport2su (char *pipport, union sockaddr_union *tmp_su, unsigned int *proto);

int siptrace_net_data_recv(void *data);
int siptrace_net_data_send(void *data);
static int _siptrace_mode = 0;


static str db_url             = str_init(DEFAULT_DB_URL);
static str siptrace_table     = str_init("sip_trace");
static str date_column        = str_init("time_stamp");  /* 00 */
static str callid_column      = str_init("callid");      /* 01 */
static str traced_user_column = str_init("traced_user"); /* 02 */
static str msg_column         = str_init("msg");         /* 03 */
static str method_column      = str_init("method");      /* 04 */
static str status_column      = str_init("status");      /* 05 */
static str fromip_column      = str_init("fromip");      /* 06 */
static str toip_column        = str_init("toip");        /* 07 */
static str fromtag_column     = str_init("fromtag");     /* 08 */
static str direction_column   = str_init("direction");   /* 09 */
static str time_us_column     = str_init("time_us");     /* 10 */
static str totag_column       = str_init("totag");       /* 11 */

#define NR_KEYS 12
예제 #23
0
 * Kamailio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */


#include "ht_dmq.h"
#include "ht_api.h"

static str ht_dmq_content_type = str_init("application/json");
static str dmq_200_rpl  = str_init("OK");
static str dmq_400_rpl  = str_init("Bad Request");
static str dmq_500_rpl  = str_init("Server Internal Error");

typedef struct _ht_dmq_repdata {
	int action;
	str htname;
	str cname;
	int type;
	int intval;
	str strval;
	int expire;
} ht_dmq_repdata_t;

dmq_api_t ht_dmqb;
예제 #24
0
파일: reply.c 프로젝트: NormB/opensips
#define TEMP_GRUU_HEADER "tgruu."
#define TEMP_GRUU_HEADER_SIZE (sizeof(TEMP_GRUU_HEADER) - 1)

#define GR_PARAM ";gr="
#define GR_PARAM_SIZE (sizeof(GR_PARAM) - 1)

#define GR_NO_VAL ";gr"
#define GR_NO_VAL_SIZE (sizeof(GR_NO_VAL) - 1)

#define CONTACT_SEP ", "
#define CONTACT_SEP_LEN (sizeof(CONTACT_SEP) - 1)

extern str gruu_secret;
extern int disable_gruu;
str default_gruu_secret=str_init("0p3nS1pS");

/*! \brief
 * Buffer for Contact header field
 */
static struct {
	char* buf;
	int buf_len;
	int data_len;
} contact = {0, 0, 0};


static inline int calc_temp_gruu_len(str* aor,str* instance,str *callid)
{
	int time_len,temp_gr_len;
예제 #25
0
파일: ldap_mod.c 프로젝트: 4N7HR4X/kamailio
		char* filter_component, char* dst_avp_name);
static int w_ldap_result_check_1(struct sip_msg* msg, 
		char* attr_name_check_str, char* param);
static int w_ldap_result_check_2(struct sip_msg* msg,
		char* attr_name_check_str, char* attr_val_re);


/* 
* Default module parameter values 
*/
#define DEF_LDAP_CONFIG "/usr/local/etc/kamailio/ldap.cfg"

/*
* Module parameter variables
*/
str ldap_config = str_init(DEF_LDAP_CONFIG);
static dictionary* config_vals = NULL;

/*
* Exported functions
*/
static cmd_export_t cmds[] = {
	{"ldap_search",            (cmd_function)w_ldap_search,            1, 
		ldap_search_fixup, 0,
		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
	{"ldap_result",            (cmd_function)w_ldap_result1,           1, 
		ldap_result_fixup, 0,
		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
	{"ldap_result",            (cmd_function)w_ldap_result2,           2, 
		ldap_result_fixup, 0,
		REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
예제 #26
0
파일: reply.c 프로젝트: NormB/opensips
/*! \brief
 * Send a reply
 */
int send_reply(struct sip_msg* _m, unsigned int _flags)
{
	str unsup = str_init(SUPPORTED_PATH_STR);
	long code;
	str msg = str_init(MSG_200); /* makes gcc shut up */
	char* buf;

	if (contact.data_len > 0) {
		add_lump_rpl( _m, contact.buf, contact.data_len, LUMP_RPL_HDR|LUMP_RPL_NODUP|LUMP_RPL_NOFREE);
		contact.data_len = 0;
	}

	if (rerrno == R_FINE && (_flags&REG_SAVE_PATH_FLAG) && _m->path_vec.s) {
		if ( (_flags&REG_SAVE_PATH_OFF_FLAG)==0 ) {
			if (parse_supported(_m)<0 && (_flags&REG_SAVE_PATH_STRICT_FLAG)) {
				rerrno = R_PATH_UNSUP;
				if (add_unsupported(_m, &unsup) < 0)
					return -1;
				if (add_path(_m, &_m->path_vec) < 0)
					return -1;
			}
			else if (get_supported(_m) & F_SUPPORTED_PATH) {
				if (add_path(_m, &_m->path_vec) < 0)
					return -1;
			} else if ((_flags&REG_SAVE_PATH_STRICT_FLAG)) {
				rerrno = R_PATH_UNSUP;
				if (add_unsupported(_m, &unsup) < 0)
					return -1;
				if (add_path(_m, &_m->path_vec) < 0)
					return -1;
			}
		}
	}

	code = rerr_codes[rerrno];
	switch(code) {
	case 200: msg.s = MSG_200; msg.len = sizeof(MSG_200)-1; break;
	case 400: msg.s = MSG_400; msg.len = sizeof(MSG_400)-1;break;
	case 420: msg.s = MSG_420; msg.len = sizeof(MSG_420)-1;break;
	case 500: msg.s = MSG_500; msg.len = sizeof(MSG_500)-1;break;
	case 503: msg.s = MSG_503; msg.len = sizeof(MSG_503)-1;break;
	}

	if (code != 200) {
		buf = (char*)pkg_malloc(E_INFO_LEN + error_info[rerrno].len + CRLF_LEN + 1);
		if (!buf) {
			LM_ERR("no pkg memory left\n");
			return -1;
		}
		memcpy(buf, E_INFO, E_INFO_LEN);
		memcpy(buf + E_INFO_LEN, error_info[rerrno].s, error_info[rerrno].len);
		memcpy(buf + E_INFO_LEN + error_info[rerrno].len, CRLF, CRLF_LEN);
		add_lump_rpl( _m, buf, E_INFO_LEN + error_info[rerrno].len + CRLF_LEN,
			LUMP_RPL_HDR|LUMP_RPL_NODUP);

		if (code >= 500 && code < 600 && retry_after) {
			if (add_retry_after(_m) < 0) {
				return -1;
			}
		}
	}

	if (sigb.reply(_m, code, &msg, NULL) == -1) {
		LM_ERR("failed to send %ld %.*s\n", code, msg.len,msg.s);
		return -1;
	} else return 0;
}
예제 #27
0
파일: save.c 프로젝트: halan/kamailio
/*! \brief
 * Fills the common part (for all contacts) of the info structure
 */
static inline ucontact_info_t* pack_ci( struct sip_msg* _m, contact_t* _c,
											unsigned int _e, unsigned int _f)
{
	static ucontact_info_t ci;
	static str no_ua = str_init("n/a");
	static str callid;
	static str path_received = {0,0};
	static str path;
	static str received = {0,0};
	static int received_found;
	static unsigned int allowed, allow_parsed;
	static struct sip_msg *m = 0;
	int_str val;

	if (_m!=0) {
		memset( &ci, 0, sizeof(ucontact_info_t));

		/* Get callid of the message */
		callid = _m->callid->body;
		trim_trailing(&callid);
		if (callid.len > CALLID_MAX_SIZE) {
			rerrno = R_CALLID_LEN;
			LM_ERR("callid too long\n");
			goto error;
		}
		ci.callid = &callid;

		/* Get CSeq number of the message */
		if (str2int(&get_cseq(_m)->number, (unsigned int*)&ci.cseq) < 0) {
			rerrno = R_INV_CSEQ;
			LM_ERR("failed to convert cseq number\n");
			goto error;
		}

		/* set received socket */
		if (_m->flags&sock_flag) {
			ci.sock = get_sock_hdr(_m);
			if (ci.sock==0)
				ci.sock = _m->rcv.bind_address;
		} else {
			ci.sock = _m->rcv.bind_address;
		}

		/* additional info from message */
		if (parse_headers(_m, HDR_USERAGENT_F, 0) != -1 && _m->user_agent &&
		_m->user_agent->body.len>0 && _m->user_agent->body.len<UA_MAX_SIZE) {
			ci.user_agent = &_m->user_agent->body;
		} else {
			ci.user_agent = &no_ua;
		}

		/* extract Path headers */
		if (path_enabled) {
			if (build_path_vector(_m, &path, &path_received) < 0) {
				rerrno = R_PARSE_PATH;
				goto error;
			}
			if (path.len && path.s) {
				ci.path = &path;
				if (path_mode != PATH_MODE_OFF) {
					/* save in msg too for reply */
					if (set_path_vector(_m, &path) < 0) {
						rerrno = R_PARSE_PATH;
						goto error;
					}
				}
			}
		}

		ci.last_modified = act_time;

		/* set flags */
		ci.flags  = _f;
		getbflagsval(0, &ci.cflags);

		/* get received */
		if (path_received.len && path_received.s) {
			ci.cflags |= ul.nat_flag;
			ci.received = path_received;
		}

		allow_parsed = 0; /* not parsed yet */
		received_found = 0; /* not found yet */
		m = _m; /* remember the message */
	}

	if(_c!=0) {
		/* hook uri address - should be more than 'sip:' chars */
		if(_c->uri.s!=NULL && _c->uri.len>4)
			ci.c = &_c->uri;

		/* Calculate q value of the contact */
		if (calc_contact_q(_c->q, &ci.q) < 0) {
			rerrno = R_INV_Q;
			LM_ERR("failed to calculate q\n");
			goto error;
		}

		/* set expire time */
		ci.expires = _e;

		/* Get methods of contact */
		if (_c->methods) {
			if (parse_methods(&(_c->methods->body), &ci.methods) < 0) {
				rerrno = R_PARSE;
				LM_ERR("failed to parse contact methods\n");
				goto error;
			}
		} else {
			/* check on Allow hdr */
			if (allow_parsed == 0) {
				if (m && parse_allow( m ) != -1) {
					allowed = get_allow_methods(m);
				} else {
					allowed = ALL_METHODS;
				}
				allow_parsed = 1;
			}
			ci.methods = allowed;
		}

		/* get received */
		if (ci.received.len==0) {
			if (_c->received) {
				ci.received = _c->received->body;
			} else {
				if (received_found==0) {
					memset(&val, 0, sizeof(int_str));
					if (rcv_avp_name.n!=0
								&& search_first_avp(rcv_avp_type, rcv_avp_name, &val, 0)
								&& val.s.len > 0) {
						if (val.s.len>RECEIVED_MAX_SIZE) {
							rerrno = R_CONTACT_LEN;
							LM_ERR("received too long\n");
							goto error;
						}
						received = val.s;
					} else {
						received.s = 0;
						received.len = 0;
					}
					received_found = 1;
				}
				ci.received = received;
			}
		}
		if(_c->instance!=NULL && _c->instance->body.len>0)
			ci.instance = _c->instance->body;
		if(_c->instance!=NULL && _c->reg_id!=NULL && _c->reg_id->body.len>0) {
			if(str2int(&_c->reg_id->body, &ci.reg_id)<0 || ci.reg_id==0)
			{
				LM_ERR("invalid reg-id value\n");
				goto error;
			}
		}
		if(sruid_next(&_reg_sruid)<0)
			goto error;
		ci.ruid = _reg_sruid.uid;
		LM_DBG("generated ruid is: %.*s\n", ci.ruid.len, ci.ruid.s);
	}

	return &ci;
error:
	return 0;
}
예제 #28
0
파일: b2b_logic.c 프로젝트: ryzhov/ATS0
/*
 * arguments: b2bl_key, new_dest, entity (1 - client)
 * */
static struct mi_root* mi_b2b_bridge(struct mi_root* cmd, void* param)
{
	struct mi_node* node= NULL;
	str key;
	b2bl_tuple_t* tuple;
	str new_dest;
	unsigned int entity_no = 0;
	b2bl_entity_id_t* entity, *old_entity, *bridging_entity;
	struct sip_uri uri;
	str meth_inv = {INVITE, INVITE_LEN};
	str meth_bye = {BYE, BYE_LEN};
	unsigned int hash_index, local_index;
	str ok= str_init("ok");
	b2b_req_data_t req_data;
	b2b_rpl_data_t rpl_data;

	node = cmd->node.kids;
	if(node == NULL)
		return 0;

	/* b2bl_key */
	key = node->value;
	if(key.s == NULL || key.len== 0)
	{
		LM_ERR("Wrong b2b_logic key parameter\n");
		return init_mi_tree(404, "Empty b2bl key", 14);
	}

	/* new destination- must be a valid SIP URI */
	node = node->next;
	if(node == NULL)
		return 0;
	
	new_dest = node->value;
	if(new_dest.s == NULL || new_dest.len == 0)
	{
		LM_ERR("Empty new dest parameter\n");
		return init_mi_tree(404, "Empty parameter", 15);
	}

	if(parse_uri(new_dest.s, new_dest.len, &uri)< 0)
	{
		LM_ERR("Bad argument. Not a valid uri [%.*s]\n", new_dest.len, new_dest.s);
		return init_mi_tree(404, "Bad parameter", 13);
	}

	/* the last parameter is optional, if present and 1 - >
	 * means that destination from the current call must be
	 * bridged to the new destination */
	node = node->next;
	if(node)
	{
		if (node->value.len==1)
		{
			if(strncmp(node->value.s, "0", 1)==0)
				entity_no = 0;
			else if(strncmp(node->value.s, "1", 1)==0)
				entity_no = 1;
			else
				return init_mi_tree(404, "Invalid entity no parameter", 27);
		}
		else
		{
			return init_mi_tree(404, "Invalid entity no parameter", 27);
		}
	}
	else
	{
		return init_mi_tree(404, "Invalid entity no parameter", 27);
	}

	if(b2bl_parse_key(&key, &hash_index, &local_index) < 0)
	{
		LM_ERR("Failed to parse key '%.*s'\n", key.len, key.s);
		return 0;
	}

	entity = b2bl_create_new_entity(B2B_CLIENT, 0, &new_dest, 0, 0, 0, 0);
	if(entity == NULL)
	{
		LM_ERR("Failed to create new b2b entity\n");
		return 0;
	}

	lock_get(&b2bl_htable[hash_index].lock);

	tuple = b2bl_search_tuple_safe(hash_index, local_index);
	if(tuple == NULL)
	{
		LM_ERR("No entity found\n");
		goto error;
	}

	bridging_entity = tuple->bridge_entities[entity_no];
	old_entity = tuple->bridge_entities[(entity_no?0:1)];

	if(old_entity == NULL || bridging_entity == NULL)
	{
		LM_ERR("Wrong dialog id\n");
		goto error;
	}

	if(old_entity->next || old_entity->prev)
	{
		LM_ERR("Can not disconnect entity [%p]\n", old_entity);
		b2bl_print_tuple(tuple, L_ERR);
		goto error;
	}

	/* send BYE to old client */
	if(old_entity->disconnected)
	{
		memset(&rpl_data, 0, sizeof(b2b_rpl_data_t));
		PREP_RPL_DATA(old_entity);
		rpl_data.method =METHOD_BYE;
		rpl_data.code =200;
		rpl_data.text =&ok;
		b2b_api.send_reply(&rpl_data);
	}
	else
	{
		old_entity->disconnected = 1;
		memset(&req_data, 0, sizeof(b2b_req_data_t));
		PREP_REQ_DATA(old_entity);
		req_data.method =&meth_bye;
		b2b_api.send_request(&req_data);
	}

	if (0 == b2bl_drop_entity(old_entity, tuple))
	{
		LM_ERR("Inconsistent tuple [%p]\n", tuple);
		b2bl_print_tuple(tuple, L_ERR);
		goto error;
	}

	if (old_entity->peer->peer == old_entity)
		old_entity->peer->peer = NULL;
	else
	{
		LM_ERR("Unexpected chain: old_entity=[%p] and old_entity->peer->peer=[%p]\n",
			old_entity, old_entity->peer->peer);
		goto error;
	}
	old_entity->peer = NULL;

	tuple->bridge_entities[0]= bridging_entity;
	tuple->bridge_entities[1]= entity;

	bridging_entity->peer = entity;
	entity->peer = bridging_entity;

	tuple->scenario_state = B2B_BRIDGING_STATE;

	memset(&req_data, 0, sizeof(b2b_req_data_t));
	PREP_REQ_DATA(bridging_entity);
	req_data.method =&meth_inv;
	b2b_api.send_request(&req_data);

	lock_release(&b2bl_htable[hash_index].lock);

	return init_mi_tree(200, "OK", 2);

error:
	if(tuple)
		b2b_mark_todel(tuple);
	lock_release(&b2bl_htable[hash_index].lock);
	return 0;
}
예제 #29
0
static mi_response_t *mi_b2b_bridge(const mi_params_t *params,
							int entity_no, str *prov_media)
{
	str key;
	b2bl_tuple_t* tuple;
	str new_dest;
	b2bl_entity_id_t* entity, *old_entity, *bridging_entity, *prov_entity = 0;
	struct sip_uri uri;
	str meth_inv = {INVITE, INVITE_LEN};
	str meth_bye = {BYE, BYE_LEN};
	unsigned int hash_index, local_index;
	str ok= str_init("ok");
	b2b_req_data_t req_data;
	b2b_rpl_data_t rpl_data;
	int ret;

	if (get_mi_string_param(params, "dialog_id", &key.s, &key.len) < 0)
		return init_mi_param_error();

	if (get_mi_string_param(params, "new_uri", &new_dest.s, &new_dest.len) < 0)
		return init_mi_param_error();

	if(parse_uri(new_dest.s, new_dest.len, &uri)< 0)
	{
		LM_ERR("Bad argument. Not a valid uri [%.*s]\n", new_dest.len, new_dest.s);
		return init_mi_error(404, MI_SSTR("Invalid uri for the new destination"));
	}

	/* if 'flag' parameter is 1 - >
	 * means that destination from the current call must be
	 * bridged to the new destination */
	if (entity_no != 0 && entity_no != 1)
		return init_mi_error(404, MI_SSTR("Invalid 'flag' parameter"));

	if (prov_media) {
		/* parse new uri */
		if(parse_uri(prov_media->s, prov_media->len, &uri)< 0)
		{
			LM_ERR("Bad argument. Not a valid provisional media uri [%.*s]\n",
				   new_dest.len, new_dest.s);
			return init_mi_error(404, MI_SSTR("Bad 'prov_media_uri' parameter"));
		}
		prov_entity = b2bl_create_new_entity(B2B_CLIENT,
						0, prov_media, 0, 0, 0, 0, 0);
		if (!prov_entity) {
			LM_ERR("Failed to create new b2b entity\n");
			goto free;
		}
	}

	ret = b2bl_get_tuple_key(&key, &hash_index, &local_index);
	if(ret < 0)
	{
		if (ret == -1)
			LM_ERR("Failed to parse key or find an entity [%.*s]\n",
					key.len, key.s);
		else
			LM_ERR("Could not find entity [%.*s]\n",
					key.len, key.s);
		goto free;
	}

	entity = b2bl_create_new_entity(B2B_CLIENT, 0, &new_dest, 0, 0, 0, 0, 0);
	if(entity == NULL)
	{
		LM_ERR("Failed to create new b2b entity\n");
		goto free;
	}

	lock_get(&b2bl_htable[hash_index].lock);

	tuple = b2bl_search_tuple_safe(hash_index, local_index);
	if(tuple == NULL)
	{
		LM_ERR("No entity found\n");
		goto error;
	}

	if (!tuple->bridge_entities[entity_no] ||
	tuple->bridge_entities[entity_no]->disconnected)
	{
		LM_ERR("Can not bridge requested entity [%p]\n",
			tuple->bridge_entities[entity_no]);
		goto error;
	}

	bridging_entity = tuple->bridge_entities[entity_no];
	old_entity = tuple->bridge_entities[(entity_no?0:1)];

	if(old_entity == NULL || bridging_entity == NULL)
	{
		LM_ERR("Wrong dialog id\n");
		goto error;
	}

	if(old_entity->next || old_entity->prev)
	{
		LM_ERR("Can not disconnect entity [%p]\n", old_entity);
		b2bl_print_tuple(tuple, L_ERR);
		goto error;
	}

	if(bridging_entity->state != B2BL_ENT_CONFIRMED)
	{
		LM_ERR("Wrong state for entity ek= [%.*s], tk=[%.*s]\n",
			bridging_entity->key.len,bridging_entity->key.s,
			tuple->key->len, tuple->key->s);
		goto error;
	}

	b2bl_print_tuple(tuple, L_DBG);

	/* send BYE to old client */
	if(old_entity->disconnected)
	{
		memset(&rpl_data, 0, sizeof(b2b_rpl_data_t));
		PREP_RPL_DATA(old_entity);
		rpl_data.method =METHOD_BYE;
		rpl_data.code =200;
		rpl_data.text =&ok;
		b2b_api.send_reply(&rpl_data);
	}
	else
	{
		old_entity->disconnected = 1;
		memset(&req_data, 0, sizeof(b2b_req_data_t));
		PREP_REQ_DATA(old_entity);
		req_data.method =&meth_bye;
		b2b_api.send_request(&req_data);
	}

	if (0 == b2bl_drop_entity(old_entity, tuple))
	{
		LM_ERR("Inconsistent tuple [%p]\n", tuple);
		b2bl_print_tuple(tuple, L_ERR);
		goto error;
	}

	if (old_entity->peer->peer == old_entity)
		old_entity->peer->peer = NULL;
	else
	{
		LM_ERR("Unexpected chain: old_entity=[%p] and old_entity->peer->peer=[%p]\n",
			old_entity, old_entity->peer->peer);
		goto error;
	}
	old_entity->peer = NULL;

	tuple->bridge_entities[0]= bridging_entity;
	if (prov_entity) {
		tuple->bridge_entities[1]= prov_entity;
		tuple->bridge_entities[2]= entity;
		/* we don't have to free it anymore */
		prov_entity = 0;
	} else {
		tuple->bridge_entities[1]= entity;
		bridging_entity->peer = entity;
		entity->peer = bridging_entity;
	}

	tuple->scenario_state = B2B_BRIDGING_STATE;
	bridging_entity->state = 0;
	bridging_entity->sdp_type = B2BL_SDP_LATE;

	memset(&req_data, 0, sizeof(b2b_req_data_t));
	PREP_REQ_DATA(bridging_entity);
	req_data.method =&meth_inv;
	b2b_api.send_request(&req_data);

	lock_release(&b2bl_htable[hash_index].lock);

	return init_mi_result_ok();

error:
	if(tuple)
		b2b_mark_todel(tuple);
	lock_release(&b2bl_htable[hash_index].lock);
free:
	if (prov_entity)
		shm_free(prov_entity);
	return 0;
}
예제 #30
0
파일: regex_mod.c 프로젝트: SipSeb/kamailio
static int regex_init_rpc(void)
{
	if (rpc_register_array(regex_rpc_cmds)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}

/**
 *
 */
/* clang-format off */
static sr_kemi_t sr_kemi_regex_exports[] = {
	{ str_init("regex"), str_init("pcre_match"),
		SR_KEMIP_INT, ki_pcre_match,
		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
	},
	{ str_init("regex"), str_init("pcre_match_group"),
		SR_KEMIP_INT, ki_pcre_match_group,
		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
	},

	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};
/* clang-format on */

/**