Пример #1
0
char * strtoupper(IN OUT char * a){
	int i = 0;
	int len = strlen(a);
	for(i = 0 ; i < len ; i ++){
		a[i] = chrtoupper(a[i]);
	}
	return a;
}
Пример #2
0
static int addr_parse_udp(struct stream_params *sp, char **out) {
	u_int32_t ip4;
	const char *cp;
	char c;
	int i;

	ZERO(*sp);

	SP_SET(sp, SEND);
	SP_SET(sp, RECV);
	sp->protocol = &transport_protocols[PROTO_RTP_AVP];

	if (out[RE_UDP_UL_ADDR4] && *out[RE_UDP_UL_ADDR4]) {
		ip4 = inet_addr(out[RE_UDP_UL_ADDR4]);
		if (ip4 == -1)
			goto fail;
		in4_to_6(&sp->rtp_endpoint.ip46, ip4);
	}
	else if (out[RE_UDP_UL_ADDR6] && *out[RE_UDP_UL_ADDR6]) {
		if (inet_pton(AF_INET6, out[RE_UDP_UL_ADDR6], &sp->rtp_endpoint.ip46) != 1)
			goto fail;
	}
	else
		goto fail;

	sp->rtp_endpoint.port = atoi(out[RE_UDP_UL_PORT]);
	if (!sp->rtp_endpoint.port && strcmp(out[RE_UDP_UL_PORT], "0"))
		goto fail;

	if (out[RE_UDP_UL_FLAGS] && *out[RE_UDP_UL_FLAGS]) {
		i = 0;
		for (cp =out[RE_UDP_UL_FLAGS]; *cp && i < 2; cp++) {
			c = chrtoupper(*cp);
			if (c == 'E')
				str_init(&sp->direction[i++], "external");
			else if (c == 'I')
				str_init(&sp->direction[i++], "internal");
		}
	}

	if (out[RE_UDP_UL_NUM] && *out[RE_UDP_UL_NUM])
		sp->index = atoi(out[RE_UDP_UL_NUM]);
	if (!sp->index)
		sp->index = 1;
	sp->consecutive_ports = 1;

	sp->rtcp_endpoint = sp->rtp_endpoint;
	sp->rtcp_endpoint.port++;

	return 0;
fail:
	return -1;
}
Пример #3
0
static int addr_parse_udp(struct stream_params *sp, char **out) {
	u_int32_t ip4;
	const char *cp;
	char c;
	int i;

	ZERO(*sp);
	if (out[RE_UDP_UL_ADDR4] && *out[RE_UDP_UL_ADDR4]) {
		ip4 = inet_addr(out[RE_UDP_UL_ADDR4]);
		if (ip4 == -1)
			goto fail;
		in4_to_6(&sp->rtp_endpoint.ip46, ip4);
	}
	else if (out[RE_UDP_UL_ADDR6] && *out[RE_UDP_UL_ADDR6]) {
		if (inet_pton(AF_INET6, out[RE_UDP_UL_ADDR6], &sp->rtp_endpoint.ip46) != 1)
			goto fail;
	}
	else
		goto fail;

	sp->rtp_endpoint.port = atoi(out[RE_UDP_UL_PORT]);
	if (!sp->rtp_endpoint.port && strcmp(out[RE_UDP_UL_PORT], "0"))
		goto fail;

	if (out[RE_UDP_UL_FLAGS] && *out[RE_UDP_UL_FLAGS]) {
		i = 0;
		for (cp =out[RE_UDP_UL_FLAGS]; *cp && i < 2; cp++) {
			c = chrtoupper(*cp);
			if (c == 'E')
				sp->direction[i++] = DIR_EXTERNAL;
			else if (c == 'I')
				sp->direction[i++] = DIR_INTERNAL;
		}
	}

	if (out[RE_UDP_UL_NUM] && *out[RE_UDP_UL_NUM])
		sp->index = atoi(out[RE_UDP_UL_NUM]);
	if (!sp->index)
		sp->index = 1;
	sp->consecutive_ports = 1;

	return 0;
fail:
	return -1;
}
Пример #4
0
static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *sin, char *addr,
		struct udp_listener *ul) {
	struct control_udp *u = (void *) obj;
	int ret;
	int ovec[100];
	char **out;
	struct iovec iov[10];
	unsigned int iovlen;
	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);

		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;
			iovlen = 4;
		}
		else {
			iov[1].iov_base = " E8\n";
			iov[1].iov_len = 4;
			iovlen = 2;
		}

		socket_sendiov(&ul->sock, iov, iovlen, sin);

		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);
		socket_sendto(&ul->sock, reply->s, reply->len, sin);
		free(reply);
		goto out;
	}

	if (out[RE_UDP_UL_CALLID])
		log_info_c_string(out[RE_UDP_UL_CALLID]);
	else if (out[RE_UDP_DQ_CALLID])
		log_info_c_string(out[RE_UDP_DQ_CALLID]);

	if (chrtoupper(out[RE_UDP_UL_CMD][0]) == 'U')
		reply = call_update_udp(out, u->callmaster, addr, sin);
	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') {
		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;
			iovlen++;
		}
		else {
			iov[2].iov_base = "20040107\n";
			iov[2].iov_len = 9;
			iovlen++;
		}
		socket_sendiov(&ul->sock, iov, iovlen, sin);
	}

	if (reply) {
		socket_sendto(&ul->sock, reply->s, reply->len, 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();
}
Пример #5
0
/*----------------------------------------------------------------
  LocatePron
 
  This function locates the one-based Nth pronunciation for a word in
  the dictionary.  N is specified by the argument aEntryNumber.  This
  function returns the byte entry location in the dictionary if the
  Nth pronunciation for the word exists, otherwise it returns 0.
 
 ----------------------------------------------------------------*/
int CTIesrDict::LocatePron( char* aWord, unsigned int aEntryNumber )
{
   int startLocation;
   int pronLocation;
   char dictWord[MAX_STR];
   unsigned int entryNumber;
   int noMatch;

   char *ucWord;

   // User should not request the zeroth entry.
   if( aEntryNumber == 0 )
      return 0;


   try
   {
      ucWord = new char[ strlen( aWord ) + 1];
   }
   catch( std::bad_alloc &ex )
   {
      return 0;
   }

   strcpy( ucWord, aWord );
   chrtoupper( ucWord );


#ifdef _TIESRDICT_USE_TIESRDT
   if( doLetterMap )
   {
      CTIesrDict::Errors error = map_dt_letters( ucWord );
      if( error != ErrNone )
      {
         delete [] ucWord;
         return 0;
      }
   }
#endif



   // Check for existence of the word in the dictionary
   startLocation = lookup( ucWord );
   if( startLocation == -1 )
   {
      delete []ucWord;
      return 0;
   }


   // Found an entry for the word in the dictionary.
   // Search backward in dictionary to find the first entry of this word.
   noMatch = 0;

   while( !noMatch && startLocation > first )
   {
      // Go to prior entry location in dictionary
      pronLocation = dec_entry( startLocation );

      // Prior word at the entry location
      dictWord[0] = '\0';
      expand_str( dictWord, pronLocation );

      // If the dictionary word matches the word we want, then continue searching backward
      noMatch = compare_str( ucWord, dictWord );
      if( !noMatch )
      {
         startLocation = pronLocation;
      }
   }


   // If user wants the first entry, it is the present one
   if( aEntryNumber == 1 )
   {
      delete [] ucWord;
      return startLocation;
   }


   // User wants an entry number > 1 for the word.
   // Try searching forward for the entry number the user wants
   entryNumber = 1;
   noMatch = 0;
   while( !noMatch && startLocation < last )
   {
      // Go to next entry location in dictionary
      pronLocation = inc_entry( startLocation );

      // Word at the present entry location
      dictWord[0] = '\0';
      expand_str( dictWord, pronLocation );

      // If the dictionary word matches the word wanted then increment count
      // and determine if it is the entry number wanted
      noMatch = compare_str( ucWord, dictWord );
      if( !noMatch )
      {
         entryNumber++;

         // Return this entry, which is the entry number wanted
         if( entryNumber == aEntryNumber )
         {
            delete [] ucWord;
            return pronLocation;
         }

         // Continue searching, have not found desired entry number yet
         startLocation = pronLocation;
      }
      else
      {
         // No more words match, and the wanted entry has not been found
         delete [] ucWord;
         return 0;
      }

   }

   // Did not find the wanted entry number for the wanted word
   delete [] ucWord;
   return 0;

}
Пример #6
0
/*----------------------------------------------------------------
GetNextEntry
 
This function should only be called after a call to GetPronEntry.  It
provides a means of obtaining the next pronunciation of the word
specified in GetPronEntry.  If the next pronunciation does not exist,
aPron will have zero in the first character, and if aPronString is
not NULL, it will be set to "", and the fuction will return
ErrNotInDictionary.  This function call is provided so that
dictionary search does not need to be done for each of multiple
pronunciations looked up in the dictionary.
 
----------------------------------------------------------------*/
CTIesrDict::Errors CTIesrDict::GetNextEntry( char aPron[], char *aPronString )
{
   int pronLocation;


   // Check that a word has been looked up by GetPronEntry
   if( m_word == NULL || strcmp( m_word, "" ) == 0 )
   {
      aPron[0] = 0;
      if( aPronString )
         aPronString[0] = '\0';
      return ErrFail;
   }


   // Try to find a valid dictionary entry location for the next
   // word entry.

   // If no dictionary entry has been looked up yet,
   // try to find the first dictionary entry.
   if( m_entryLocation == 0 )
   {
      pronLocation = LocatePron( m_word, 1 );
   }

      // Otherwise, if not at end of dictionary try to find next entry.
   else if( m_entryLocation < last )
   {
      char dictWord[MAX_STR];
      dictWord[0] = '\0';
      char ucWord[MAX_STR];
      CTIesrDict::Errors error;

      strcpy( ucWord, m_word );
      chrtoupper( ucWord );

#ifdef _TIESRDICT_USE_TIESRDT
      // Convert word to indices if using TIesrDT and letter value >127
      if( doLetterMap )
      {
         error = map_dt_letters( ucWord );
         if( error != ErrNone )
         {
            return error;
         }
      }
#endif


      pronLocation = inc_entry( m_entryLocation );
      expand_str( dictWord, pronLocation );

      // Next word entry does not match word
      if( strcmp( dictWord, ucWord ) != 0 )
      {
         pronLocation = 0;
      }
   }

      // At the end of dictionary
   else
      pronLocation = 0;


   // If no valid location, then no more entries of this word exist
   // in the dictionary
   if( pronLocation < first || pronLocation > last )
   {
      aPron[0] = 0;
      if( aPronString )
         aPronString[0] = '\0';

      return ErrNotInDictionary;
   }


   // A valid word exists in the next dictionary location
   m_entryLocation = pronLocation;

   // Get the pronunciation of the word according to the dictionary
   print_pron( m_word, m_entryLocation, m_defaultPron, aPron );
   if( aPronString )
      PronToString( aPron, aPronString );

   m_entryNumber++;

   return ErrNone;
}
Пример #7
0
/*----------------------------------------------------------------
GetPronEntry
 
Get the Nth pronunciation entry of a word specified by aWord.  The
value of N is specified by the argument aEntryNumber.  If
aEntryNumber is zero, then the default rule-based pronunciation is
returned without consulting the dictionary.  Otherwise the Nth
pronunciation of the word in the dictionary is returned.  If the Nth
pronunciation does not exist, the default rule-based pronunciation will be
provided in aPron and aPronString, and ErrNotInDictionary will be
returned. If no default pronunciation exists, aPron will have zero in the first
character, and if aPronString is not NULL, it will be set to "".
 
----------------------------------------------------------------*/
CTIesrDict::Errors CTIesrDict::GetPronEntry( const char *aWord,
        const unsigned int aEntryNumber,
        char aPron[], char *aPronString )
{
   Errors error;
   int phone;


   // No dictionary lookup yet
   m_entryLocation = 0;
   m_entryNumber = 0;

   // Reallocate space to hold the word and its default pronunciation
   delete [] m_defaultPron;
   m_defaultPron = NULL;

   delete [] m_word;
   m_word = NULL;

   try
   {
      m_word = new char[ strlen( aWord ) + 1 ];

      // Create space to hold the phones of the default pronunciation of the word.
      m_defaultPron = new char[ MAXPHONESPERWORD + 1];
   }
   catch( std::bad_alloc &ex )
   {
      return ErrMemory;
   }

   // Copy of the word in upper case
   strcpy( m_word, aWord );
   chrtoupper( m_word );


   // Get default pronunciation and check for failure
   error = GetDefaultPron( m_word, m_defaultPron );
   if( error != ErrNone )
   {
      strcpy( m_word, "" );
      return ErrFail;
   }


   // Copy default pronunciation phone indices and pron string to output.
   // This will be replaced if the desired dictionary entry is found.
   for( phone = 0; phone <= m_defaultPron[0]; phone++ )
   {
      aPron[phone] = m_defaultPron[phone];
   }

   if( aPronString )
      PronToString( m_defaultPron, aPronString );


   // User only wants the rule-based pronunciation
   if( aEntryNumber == 0 )
      return ErrNone;


   // User requested a pronunciation from the dictionary.  Get the
   // location of the requested entry in the dictionary for this word.
   m_entryLocation = LocatePron( m_word, aEntryNumber );
   if( m_entryLocation == 0 )
      return ErrNotInDictionary;


   // Get the pronunciation of the word according to the dictionary
   print_pron( m_word, m_entryLocation, m_defaultPron, aPron );
   if( aPronString )
      PronToString( aPron, aPronString );

   m_entryNumber = aEntryNumber;

   return ErrNone;
}
Пример #8
0
/*----------------------------------------------------------------
GetNumberEntries
 
Get the number of entries in the dictionary for a word specified by
aWord.  Note that this does NOT include the rule-based default
pronunciation, only the number of pronunciations in the dictionary.
Hence the number returned in aNumberEntries can be zero.
 
----------------------------------------------------------------*/
CTIesrDict::Errors CTIesrDict::GetNumberEntries( const char* aWord, unsigned int *aNumberEntries )
{
   int startLocation;
   int pronLocation;
   int noMatch;
   char dictWord[MAX_STR];
   char *ucWord;
   int numEntries;
   CTIesrDict::Errors error;

   *aNumberEntries = 0;
   numEntries = 0;

   // convert the word to upper case.
   try
   {
      ucWord = new char[ strlen( aWord ) + 1];
   }
   catch( std::bad_alloc &ex )
   {
      return ErrMemory;
   }

   strcpy( ucWord, aWord );
   chrtoupper( ucWord );


#ifdef _TIESRDICT_USE_TIESRDT
   // Convert word to indices if using TIesrDT and letter value >127
   if( doLetterMap )
   {
      error = map_dt_letters( ucWord );
      if( error != ErrNone )
      {
         delete [] ucWord;
         return error;
      }
   }
#endif


   // Check for existence of the word in the dictionary
   startLocation = lookup( ucWord );
   if( startLocation == -1 )
   {
      delete [] ucWord;
      return ErrNone;
   }

   // Found an entry in the dictionary
   numEntries++;
   pronLocation = startLocation;
   noMatch = 0;

   // Search backward in dictionary to find all prior entries that match
   while( !noMatch && pronLocation > first )
   {
      // Go to prior entry location in dictionary
      pronLocation = dec_entry( pronLocation );

      // Prior word at the entry location
      dictWord[0] = '\0';
      expand_str( dictWord, pronLocation );

      // If the dictionary word matches the word we want, then increment count
      noMatch = compare_str( ucWord, dictWord );
      if( !noMatch )
      {
         numEntries++;
      }
   }

   // Look forward in the dictionary for subsequent matching entries
   pronLocation = startLocation;
   noMatch = 0;

   while( !noMatch && pronLocation < last )
   {
      // Go to next entry location in dictionary
      pronLocation = inc_entry( pronLocation );

      // Prior word at the entry location
      dictWord[0] = '\0';
      expand_str( dictWord, pronLocation );

      // If the dictionary word matches the word we want then increment count
      noMatch = compare_str( ucWord, dictWord );
      if( !noMatch )
      {
         numEntries++;
      }
   }

   *aNumberEntries = numEntries;

   delete [] ucWord;
   return ErrNone;
}
Пример #9
0
CTIesrDict::Errors CTIesrDict::GetPron( const char *aWord,
        char aPron[],
        char *aPronString )
{
   CTIesrDict::Errors error;
   int idx;
   char *ucWord;


   // Delete any existing lookup for GetPronEntry and GetNextEntry
   delete [] m_word;
   m_word = NULL;

   delete [] m_defaultPron;
   m_defaultPron = NULL;

   m_entryLocation = 0;
   m_entryNumber = 0;


   // Modifiable buffer holding word to look up in upper case
   try
   {
      ucWord = new char[ strlen( aWord ) + 1 ];
   }
   catch( std::bad_alloc &ex )
   {
      return ErrMemory;
   }

   strcpy( ucWord, aWord );
   chrtoupper( ucWord );


   // Get the default pronunciation
   error = GetDefaultPron( ucWord, aPron );
   if( error != ErrNone )
   {
      delete [] ucWord;
      return ErrFail;
   }




#ifdef _TIESRDICT_USE_TIESRDT
   // Convert word to indices if using TIesrDT and letter value >127
   if( doLetterMap )
   {
      error = map_dt_letters( ucWord );
      if( error != ErrNone )
      {
         delete [] ucWord;
         return error;
      }
   }
#endif


   /* dictionary lookup */
   idx = lookup( ucWord );

   // If word found in dictionary, do use the exception
   if( idx != -1 )
   {
      /* use exception.*/
      // Note: decode_entry finds and uses first word entry in dictionary
      decode_entry( ucWord, idx, aPron );
   }


   // Done with word text
   delete [] ucWord;


   // output the pronunciation string from dictionary lookup
   if( aPronString != NULL )
   {
      PronToString( aPron, aPronString );
   }

   return ErrNone;
}
Пример #10
0
/*----------------------------------------------------------------
GetDefaultPron
 
Get the default, that is rule-based pronunciation for a word.
 
----------------------------------------------------------------*/
CTIesrDict::Errors CTIesrDict::GetDefaultPron( const char* aWord, char aPron[] )
{
   int idx;
   unsigned int dirLen;

   unsigned char *pathName = NULL;
   char *pron_ascii = NULL;
   char *pron_ascii_2 = NULL;
   char *buf = NULL;

   int maxString;

   CTIesrDict::Errors error = ErrNone;

#ifndef _TIESRDICT_USE_TIESRDT
   Boolean result;



   // Protect epd_make_case.  It can't handle non-alphabetic chars
   for( idx = 0; idx < (int) strlen( aWord ); idx++ )
   {
      if( !( ( aWord[idx] > 64 && aWord[idx] < 91 ) ||
              ( aWord[idx] > 96 && aWord[idx] < 123 ) ) )
      {
         return ErrInput;
      }
   }

   // directory containing the dictionary information
   dirLen = strlen( direct ) + strlen( lang ) + 3;
   try
   {
      pathName = new char[ dirLen ];
   }
   catch( std::bad_alloc &ex )
   {
      error = ErrMemory;
      goto FinishPron;
   }

   // Make pathName
   strcpy( pathName, direct );
   strcat( pathName, PATH_SEPARATOR );
   strcat( pathName, lang );
   strcat( pathName, PATH_SEPARATOR );


#else
   // Allow only characters supported by the language
   for( idx = 0; idx < (int) strlen( aWord ); idx++ )
   {
      if( letterMap[ (unsigned char) aWord[idx] ] == '\0' )
      {
         error = ErrInput;
         goto FinishPron;
      }
   }

#endif


   // word pronunciation phone string length must not exceed this estimate
   maxString = MAXPHONESPERWORD*MAXPHONENAME;

   try
   {
      pron_ascii = new char[maxString];
      pron_ascii_2 = new char[maxString];

      // Modifiable buffer holding word to look up
      buf = new char[ strlen( aWord ) + 1];
   }
   catch( std::bad_alloc &ex )
   {
      error = ErrMemory;
      goto FinishPron;
   }


   // Copy word to buf and convert to uppercase
   strcpy( buf, aWord );
   chrtoupper( buf );


   // get default pronunciation, using TIesrDT or dtmakeup depending
   // on which API was compiled.
#ifdef _TIESRDICT_USE_TIESRDT
   TIesrDT_Error_t dtError;

   if( doDTLookup )
   {
      dtError = TIesrDT_Pron( tiesrDT, buf, pron_ascii, maxString );

      // TIesrDT can return an empty string for default pronunciation
      if( dtError != TIesrDTErrorNone /*|| strlen( pron_ascii ) == 0 */ )
      {
         error = ErrFail;
         goto FinishPron;
      }
   }
   else
   {
      pron_ascii[0] = '\0';
   }
#else
   result = epd_make_case( buf, pron_ascii, maxString, pathName, true );
   if( result != true || strlen( pron_ascii ) == 0 )
   {
      error = ErrFail;
      goto FinishPron;
   }
#endif


   // Map to include stop closures in word phones if needed
   if( doClosure )
   {
      map_pron( pron_ascii, pron_ascii_2 );
   }
   else
   {
      strcpy( pron_ascii_2, pron_ascii );
   }

   // Convert ascii to phone indices
   pron2bin( pron_ascii_2, aPron );


FinishPron:
#ifndef _TIESRDICT_USE_TIESRDT
   delete [] pathName;
#endif
   delete [] pron_ascii;
   delete [] pron_ascii_2;
   delete [] buf;

   return error;
}