DEFINITION C_Tdpv_660004655 "Tdpvgsm"
DEFINITION NUMTAB_660004655 4
DEFINITION MODULE_660004655 0xA000
DEFINITION ERR_DUPL_660004655 0x0D0
DEFINITION ERR_DISTR_660004655 0x110
DEFINITION Multidistribution_Non_660004655 0
DEFINITION DISTRIBUTION_SPECIALE_660004655 0
DEFINITION TRAI_KO_660004655 -1
REGISTRE ENTIER EFFICACE_660004655
REGISTRE ENTIER erreur_660004655
REGISTRE ENTIER ERREUR_660004655
REGISTRE ENTIER code_rejet_660004655
REGISTRE ENTIER roleOfNode_660004655
REGISTRE ENTIER callStartTime_660004655
REGISTRE ENTIER CallDuration_660004655
REGISTRE ENTIER EndTime_660004655
REGISTRE ENTIER sessionTerm_660004655
REGISTRE ENTIER val_sessTerm_660004655
REGISTRE ENTIER callStatus_660004655
REGISTRE ENTIER Node_660004655
REGISTRE ENTIER longueur_660004655
REGISTRE ENTIER index_660004655
REGISTRE ENTIER position_660004655
REGISTRE ENTIER Flag_calling_660004655
REGISTRE ENTIER Flag_Dialled_660004655
REGISTRE ENTIER date_plat_660004655
REGISTRE ENTIER date_cra_660004655
REGISTRE ENTIER date_audit_660004655
REGISTRE ENTIER long_MSISDN_660004655
REGISTRE ENTIER ele0_660004655
REGISTRE ENTIER ele1_660004655
REGISTRE ENTIER ele2_660004655
REGISTRE ENTIER type_cra_660004655
REGISTRE ENTIER res_660004655
REGISTRE ENTIER flag_rdt_660004655
REGISTRE ENTIER date_fin_660004655
REGISTRE ENTIER TransSessTerm_660004655
REGISTRE ENTIER b_DTMF_660004655 
REGISTRE ENTIER indice_660004655
REGISTRE POINTEUR ptr_calling_660004655
REGISTRE POINTEUR ptr_Dialled_660004655
REGISTRE POINTEUR ptr_motif_660004655
REGISTRE POINTEUR ptr_callingN2_660004655
REGISTRE POINTEUR ptr_DialledN2_660004655
REGISTRE POINTEUR ptr_zero_660004655
REGISTRE POINTEUR ptr_interm_660004655
REGISTRE POINTEUR ptr_callingN2_DCB_660004655
REGISTRE POINTEUR ptr_DialledN2_DCB_660004655
REGISTRE POINTEUR ptr_IMSI_DCB_660004655
REGISTRE POINTEUR ptr_IMSI_660004655
REGISTRE POINTEUR ptr_AX_IDEMET_IMS_660004655
REGISTRE POINTEUR ptr_ICID_660004655
REGISTRE POINTEUR ptr_PrivateUSID_660004655
REGISTRE POINTEUR ptr_CSCFId_660004655
REGISTRE POINTEUR ptr_val_sessTerm_660004655
REGISTRE POINTEUR ptr_TransSessTerm_660004655
REGISTRE POINTEUR ptr_BUF1_660004655
REGISTRE POINTEUR ptr_BUF2_660004655
REGISTRE POINTEUR ptr_BUF3_660004655
################################################################################
#
#                             Pcode de distribution IMS_CSCF
#
# history :
# 		Creation le 07/07/09
#
# PKH 07/07/09 G2R3 offre MIPC lot2
# PKH 07/08/09 G2R3 correction QC424 remplacement de 88 ... 8F par 77 ... 7F
# JLG 02/11/09 G2R5 QC490 (alarme 1444 de troncature)
# JLG 18/11/09 G2R5 QC498, QC490 corrigee
# 08/12/2010 - JLG - G3R1lot4 Verification/Correction des variables (constantes, entiers, pointeurs)
# 29/02/2012 - JLG - G3R6 QC1005 modif alarme retour aiguillage
# 02/07/2014 - JLG - G5R1 QC1405, champ eec du DPV si g_ieec > 500
# 18/09/2014 - JLG - report G5R1C6 Remplacement de la fonction CONV_DCB_ASCII par i_get_art_str
# 08/10/2014 - JLG - report G5R1C6  test longueur pour memcpy
################################################################################






erreur_660004655 = 0
ERREUR_660004655 = 0
roleOfNode_660004655 = -1
callStartTime_660004655 = 0
CallDuration_660004655 = 0
EndTime_660004655 = 0
callStatus_660004655 = -1
Node_660004655=0
val_sessTerm_660004655 = 0
longueur_660004655 = 0
index_660004655 = 0
position_660004655 = 0
Flag_calling_660004655 = 0
Flag_Dialled_660004655 = 0
date_plat_660004655 = 0
date_cra_660004655 = 0
long_MSISDN_660004655 = 0
ele0_660004655 = -1
ele1_660004655 = -1
ele2_660004655 = -1
type_cra_660004655 = 0
EFFICACE_660004655 = 1
code_rejet_660004655 = 0
res_660004655 = 0
date_fin_660004655 = 0
b_DTMF_660004655 = 0
indice_660004655 = 0

ptr_PrivateUSID_660004655 = "ptr_PrivateUSID45454545454545454545454545454545454545454545454545454545454545451111111111111111111111111111111111111111111111111"
ptr_AX_IDEMET_IMS_660004655 ="ptr_AX_IDEMET_IMS11111111111111111111111111111111111111111111111111"
ptr_calling_660004655  = "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
ptr_Dialled_660004655 = "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888811188888888888888888888888888888888888"
ptr_motif_660004655    = "333333333333333333333333333333333333333333333333333"
ptr_callingN2_660004655= "ptr_callingN25555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
ptr_DialledN2_660004655 = "ptr_DialledN21010100101010101010101010101010101010101001110101001001101010010110101010101010101001010101010101011001010100101010101"
ptr_zero_660004655 = "666666666666666666666666666666"
ptr_interm_660004655 = "77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777788888888"
ptr_callingN2_DCB_660004655 = "21212121212121212121121212121212121212121212112121212121212122122121212121212212112121221122211121212121212121211221"
ptr_DialledN2_DCB_660004655 = "31313131313131313133131313313133131331313313313113313113131331313311331131331131331133113131331313311313133131313113"
ptr_IMSI_660004655 = "ptr_IMSI5656565655655656556565656656566565656555656556565565656565656565656565656565656565656"
ptr_ICID_660004655 = "ptr_ICID787878787878787878778787878787878787878787877877878778787878787877788777887787877878877878871111111111111111111111111111"
ptr_IMSI_DCB_660004655 = "ptr_IMSI_DCB123123123122331231231231231231231231231231231231231231231231231231231213123123123"
ptr_CSCFId_660004655 = "ptr_CSCFId2525252525252252525252525252525252525252525252252525252255225225252255252225252225252552255111111111111111111111111111"
ptr_val_sessTerm_660004655 = "ptr_val_sessTerm231231231"
ptr_TransSessTerm_660004655 = "ptr_TransSessTerm"
ptr_BUF1_660004655 = "ptr_BUF1546546546546546546546546546546546546546546546546546546546546546546546546546546546546546546546546546456454645645464564564546"
ptr_BUF2_660004655 = "ptr_BUF2979797979797979797979979797979979797979799797979799797979797979797997979797979797979797979797997977979797979797979797979797"
ptr_BUF3_660004655 = "ptr_BUF376767676767667767767776767767676767676767766677667667676767767676766767767676767667677667677666676776767676676776766776767667"

i_strcpy(ptr_AX_IDEMET_IMS_660004655,"")
i_strcpy(ptr_calling_660004655,"")
i_strcpy (ptr_Dialled_660004655,"")
i_strcpy(ptr_motif_660004655,"")
i_strcpy(ptr_callingN2_660004655,"")
i_strcpy(ptr_zero_660004655,"")
i_strcpy(ptr_interm_660004655,"")
i_strcpy(ptr_DialledN2_660004655,"")
i_strcpy(ptr_callingN2_DCB_660004655,"")
i_strcpy (ptr_DialledN2_DCB_660004655,"")
i_strcpy(ptr_IMSI_660004655,"")
i_strcpy(ptr_IMSI_DCB_660004655,"")
i_strcpy(ptr_ICID_660004655,"")
i_strcpy(ptr_PrivateUSID_660004655,"")
i_strcpy(ptr_CSCFId_660004655,"")
i_strcpy(ptr_val_sessTerm_660004655, "")
i_strcpy(ptr_TransSessTerm_660004655, "")
i_strcpy(ptr_BUF1_660004655,"")
i_strcpy(ptr_BUF2_660004655,"")
i_strcpy(ptr_BUF3_660004655,"")

trace ("---------------------------------")
trace ("	Tims_CSCF Distribution	 ")
trace ("---------------------------------")


##################################################################################
# Identification de la provenance de l'article
# flag_rdt : nb de passage en redistribution (lecture de l'enveloppe obligatoire)
##################################################################################
flag_rdt_660004655 = -1
flag_rdt_660004655 = i_LireRedistCpt()

SI (flag_rdt_660004655 == 0)
ALORS
	erreur_660004655 = i_add_opt( "E_Redistri2" )
FINSI
erreur_660004655 = i_set_attr_val_n( $E_Redistri2::EnvoiRedis, 0)

########################################################
# Cpt applicatif CPT_RDT=1509 (REDISTRIBUTION)
########################################################
# FE_0028 comptabilisation des CRAs issus de la redistribution
date_fin_660004655 = i_get_art_field(g_iartin,$Tims_CSCF::dfin)
erreur_660004655 = i_incr_redist_dist_660004265(date_fin_660004655)

erreur_660004655 = i_cree_art("Conv_URS",g_iartout10)

################## Date_Audit et date_plat (date_audit ramenee a heure platine)
date_audit_660004655=i_date_audit()
trace1("[Tims_CSCF_dist] date_audit=%x",date_audit_660004655)

date_plat_660004655 = i_DHgetLocalTime(NUMTAB_660004655, 7, date_audit_660004655)

#AX_IDEMET
i_strcpy(ptr_AX_IDEMET_IMS_660004655, i_get_tab_field("VariableContexte",i_get_art_field(g_iartin,$Tims_CSCF::callStartTime),"AX_IDEMET_IMS"))


# Calcul de TransSessTerm
TransSessTerm_660004655 = 0xFF
sessionTerm_660004655 = i_get_art_field(g_iartin, $Tims_CSCF::sessionTerm)
# Recuperation de la valeur absolue
SI sessionTerm_660004655 < 0
ALORS
	val_sessTerm_660004655 = sessionTerm_660004655 - (2 * sessionTerm_660004655)
SINON
	val_sessTerm_660004655 = sessionTerm_660004655
FINSI

# Utilisation du champ chgcar de CONV_URS car il presente la structure souhaitee (tableau DCB de 4 elements)
# Remplissage du champ en transformant la valeur en hexa : 100 en decimal -> 100 en hexa
g_iartout10.chgcarDCB[0] = 0
g_iartout10.chgcarDCB[1] = val_sessTerm_660004655/100
g_iartout10.chgcarDCB[2] = (val_sessTerm_660004655 - (g_iartout10.chgcarDCB[1]*100)) /10
g_iartout10.chgcarDCB[3] = val_sessTerm_660004655 - (g_iartout10.chgcarDCB[1]*100) - (g_iartout10.chgcarDCB[2]*10)
# G5R1C5 Remplacement de la fonction CONV_DCB_ASCII par i_get_art_str
# Conversion en ASCII pour appel a la table externe
# On considere avoir uniquement des valeurs comprises entre 100 et 999 : il faut donc retirer le 0 de bourrage a gauche
erreur_660004655 = i_get_art_str(g_iartout10, $Conv_URS::chgcarDCB, ptr_val_sessTerm_660004655)
i_get_sub_str(ptr_val_sessTerm_660004655, 1, 3, ptr_val_sessTerm_660004655)

i_strcpy(ptr_TransSessTerm_660004655, i_get_tab_field("SCSCFRecordClosing", date_fin_660004655, ptr_val_sessTerm_660004655))

SI (i_strcmp(ptr_TransSessTerm_660004655, g_inull)) != 0
ALORS
	TransSessTerm_660004655 = CONV_ASCIINUMHEX_INT_660004265(ptr_TransSessTerm_660004655)
FINSI	


# Calcul de callDuration

SI (i_valid_field_n(g_iartin, $Tims_CSCF::callStartTime))
ALORS
	callStartTime_660004655 = i_get_art_field(g_iartin, $Tims_CSCF::callStartTime)
	SI	(i_valid_field_n(g_iartin, $Tims_CSCF::callEndTime))
	ALORS
		EndTime_660004655 = i_get_art_field(g_iartin, $Tims_CSCF::callEndTime)
		CallDuration_660004655 = EndTime_660004655 - callStartTime_660004655
	SINON
		CallDuration_660004655 = 0
	FINSI
SINON
	CallDuration_660004655 = 0
FINSI


#calcul de callStatus

SI(i_valid_field_n(g_iartin,$Tims_CSCF::sessionTerm))
ALORS
	SI(i_get_art_field(g_iartin, $Tims_CSCF::sessionTerm)<=0 )
	ALORS
		trace("[Tims Trait] CallStatus is Succesful")
		#Successuf
		callStatus_660004655 = 0
	SINON
		trace("[Tims Trait] CallStatus is failure")
		#Unsuccessful
		callStatus_660004655 = 1
	FINSI
SINON
	callStatus_660004655 = 1
FINSI

#-----------------------------------#
#	Normalisation et troncature		#
#-----------------------------------#

# ------------1er phase de normalisation-------------------------#
#	suppression des suffixe si '@' trouve.
#	suppression des prefixe:                                     #
#   tel:*31* SIP:*31* tel:00 sip:00 tel:* sip:* tel: sip:        #
#   pour les champs :                                            #
#   callingPartAddr,DialledDigits,TransCalledNB					 #
#----------------------------------------------------------------#

#---------------T3_calling.callingPartAddr---------------------#

SI (!i_valid_field_n(g_iartin, $Tims_CSCF::callingPartAddr))
ALORS
	SAUT FIN_NOR1
FINSI

erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::callingPartAddr, ptr_calling_660004655)

trace2("-------Avant normalisation de callingPartAddr = %s------------",ptr_calling_660004655,"")
index_660004655 = 0
longueur_660004655=i_strlen(ptr_calling_660004655)
trace1("----------longueur=%d------------",longueur_660004655)
#recherche du caractere @ pour supprimer les suffixes eventuels
position_660004655 = RECHERCHE_CARACTERE_660004265 (ptr_calling_660004655,"@")
trace1("---------position=%d----------",position_660004655)
SI (position_660004655 < 0)
ALORS
	#pas de caractere '@' trouve dans ptr_calling
	trace ("pas de caractere @ dans callingPartAddr") 
	SAUT DEBUT_NOR1
SINON
	#suppression des suffixes apres @
	i_get_sub_str(ptr_calling_660004655,0,position_660004655 - 1,ptr_calling_660004655)
	longueur_660004655=i_strlen(ptr_calling_660004655)
FINSI


POINT DEBUT_NOR1


#detection des prefixes tel: et sip:
i_get_sub_str (ptr_calling_660004655,index_660004655,index_660004655+3,ptr_motif_660004655)
SI (i_strcmp("tel:",ptr_motif_660004655)==0 || i_strcmp("sip:",ptr_motif_660004655)==0)
ALORS
	trace ("suppression de tel: ou sip:")
	i_get_sub_str(ptr_calling_660004655,4,-1,ptr_calling_660004655)
	longueur_660004655 = i_strlen(ptr_calling_660004655)
FINSI


#Detection du caractere +
index_660004655 = 0
i_get_sub_str (ptr_calling_660004655,index_660004655,index_660004655,ptr_motif_660004655)
SI (i_strcmp("+",ptr_motif_660004655)==0)
ALORS
	trace ("suppression +")
	i_get_sub_str(ptr_calling_660004655,1,-1,ptr_calling_660004655)
	longueur_660004655 = i_strlen(ptr_calling_660004655)
FINSI

#Detection des prefixes 00 
index_660004655 = 0
i_get_sub_str (ptr_calling_660004655,index_660004655,index_660004655+1,ptr_motif_660004655)
trace2("------cas 00 ptr_motif=%s---------",ptr_motif_660004655,"")
SI (i_strcmp("00",ptr_motif_660004655)==0)	          
ALORS
	trace ("suppression de 00")
	i_get_sub_str(ptr_calling_660004655,2,-1,ptr_calling_660004655)
	longueur_660004655 = i_strlen(ptr_calling_660004655)
FINSI

	

#detection des caracteres DTMF
i_get_sub_str (ptr_calling_660004655,0,0,ptr_BUF1_660004655)
i_get_sub_str (ptr_calling_660004655,0,1,ptr_BUF2_660004655)


SI ( i_strcmp("*#", ptr_BUF2_660004655) == 0)
ALORS
	b_DTMF_660004655=2
	trace ("presence des caracteres DTMF *#")
SINON
	SI ( i_strcmp("*", ptr_BUF1_660004655) == 0) || ( i_strcmp("#", ptr_BUF1_660004655) == 0)
	ALORS
		b_DTMF_660004655=1
		trace ("presence du caractere DTMF * ou #")
	FINSI
FINSI

#presence  DTMF *#---*
SI (b_DTMF_660004655 == 2)
ALORS
	indice_660004655 = 1
	POINT DEB_BOUCLE1
	indice_660004655 = indice_660004655 + 1
	SI (indice_660004655 < longueur_660004655)
	ALORS
		i_get_sub_str(ptr_calling_660004655, indice_660004655, indice_660004655, ptr_BUF3_660004655)
		SI i_strcmp(ptr_BUF3_660004655,"*") == 0 || i_strcmp(ptr_BUF3_660004655,"#") == 0
		ALORS
			indice_660004655 = indice_660004655 + 1
			SAUT FIN_BOUCLE_COMMUN
		SINON
			SAUT DEB_BOUCLE1
		FINSI
	FINSI
FINSI


#presence DTMF  *---* ou #---#

SI (b_DTMF_660004655 == 1)
ALORS
	indice_660004655  = 0
	POINT DEB_BOUCLE2
	indice_660004655 = indice_660004655 + 1
	SI (indice_660004655 < longueur_660004655)
	ALORS
		i_get_sub_str(ptr_calling_660004655, indice_660004655, indice_660004655, ptr_BUF3_660004655)
		SI i_strcmp(ptr_BUF3_660004655,"*") == 0 || i_strcmp(ptr_BUF3_660004655,"#") == 0
		ALORS
			indice_660004655 = indice_660004655 + 1
			SAUT FIN_BOUCLE_COMMUN
		SINON
			SAUT DEB_BOUCLE2
		FINSI
	FINSI
FINSI


POINT FIN_BOUCLE_COMMUN

SI (b_DTMF_660004655 == 1 || b_DTMF_660004655 == 2)
ALORS
#Suppression des sequences DTMF
	i_get_sub_str(ptr_calling_660004655,indice_660004655,-1,ptr_calling_660004655)
	longueur_660004655=i_strlen(ptr_calling_660004655) 
FINSI

POINT FIN_NOR1

trace2("-----apres normalisation 1 etape de callingPartAddr:%s------",ptr_calling_660004655,"")

#-----------------------------------#
# 2eme  Etape de la normalisation	#
# sauf pour le champ TransCalledNB	#
#-----------------------------------#
# ptr_calling (callingPartAde)

i_strcpy(ptr_callingN2_660004655, ptr_calling_660004655)
#longueur=i_strlen(ptr_calling)
SI (longueur_660004655 <= 6)
ALORS
	#N? court on ajoute 33
	trace2("----cas ptr_calling court = %s------",ptr_calling_660004655,"") 
	erreur_660004655=i_format_str2(ptr_callingN2_660004655,"%s%s","33",ptr_calling_660004655)
	Flag_calling_660004655=1
	trace2("-------------ptr_callingN2 ajout de 33 cas  court = %s--------",ptr_callingN2_660004655,"")
SINON
	trace2("----cas ptr_calling non court = %s -----------",ptr_calling_660004655,"")
	i_get_sub_str(ptr_calling_660004655, 0, 0, ptr_zero_660004655)
	trace2("------------ptr_zero=%s---------",ptr_zero_660004655,"")
	SI (i_strcmp("0",ptr_zero_660004655)==0 && longueur_660004655 >=10)
	ALORS
		i_get_sub_str (ptr_calling_660004655,1,-1,ptr_interm_660004655)
		erreur_660004655 = i_format_str2(ptr_callingN2_660004655,"%s%s","33",ptr_interm_660004655)
		trace2("-----cas ptr_callingN2 non court ajout 33 = %s--------", ptr_callingN2_660004655,"")  
		Flag_calling_660004655=1
	FINSI
FINSI



#-------------------------------#
#	T3_dialledD.DialledDigits	#
#-------------------------------#
#reinitialisation
b_DTMF_660004655 = 0
indice_660004655  = 0

SI (!i_valid_field_n(g_iartin, $Tims_CSCF::DialledDigits))
ALORS
	SAUT FIN_NOR2
FINSI

erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::DialledDigits, ptr_Dialled_660004655)
index_660004655 = 0
longueur_660004655 = i_strlen(ptr_Dialled_660004655)

#recherche du caracyere @ pour supprimer les suffixes eventuels
position_660004655 = RECHERCHE_CARACTERE_660004265(ptr_Dialled_660004655,"@")

SI (position_660004655 < 0)
ALORS
	#pas de caractere '@' trouve dans ptr_Dialled
	trace("------pas de caractere '@' trouve dans ptr_Dialled---------")
	SAUT DEBUT_NOR2
SINON
	trace("-------ptr_Dialled suppression des suffixes apres @---------")
	i_get_sub_str(ptr_Dialled_660004655,0,position_660004655 - 1,ptr_Dialled_660004655)
	longueur_660004655=i_strlen(ptr_Dialled_660004655)
	trace2("-------------ptr_Dialled sans suffixe @...=%s------------",ptr_Dialled_660004655,"")
FINSI

POINT DEBUT_NOR2

#------------
#Detection des prefix : tel: ou sip:
i_get_sub_str (ptr_Dialled_660004655,index_660004655,index_660004655+3,ptr_motif_660004655)
SI (i_strcmp("tel:",ptr_motif_660004655)==0 || i_strcmp("sip:",ptr_motif_660004655)==0)
ALORS
	trace2 ("------suppression du prefix : %s------",ptr_motif_660004655,"")
	i_get_sub_str(ptr_Dialled_660004655,4,-1,ptr_Dialled_660004655)
	longueur_660004655 = i_strlen(ptr_Dialled_660004655)
FINSI
trace1("-------1 longueur de ptr_Dialled apres suppression de sip: = %d-----------",longueur_660004655)
index_660004655 = 0
#Detection des prefixes 00 
i_get_sub_str (ptr_Dialled_660004655,index_660004655,index_660004655+1,ptr_motif_660004655)
trace2("-----cas 00 pour ptr_Dialled ptr_motif= %s------",ptr_motif_660004655,"")
SI (i_strcmp("00",ptr_motif_660004655)==0)
ALORS
	trace ("suppression de 00")
	i_get_sub_str(ptr_Dialled_660004655,2,-1,ptr_Dialled_660004655)
	longueur_660004655 = i_strlen(ptr_Dialled_660004655)
FINSI
trace1("-------2 longueur de ptr_Dialled apres suppression de sip: = %d-----------",longueur_660004655)
index_660004655 = 0
#detection des prefixes +
i_get_sub_str (ptr_Dialled_660004655,index_660004655,index_660004655,ptr_motif_660004655)
SI (i_strcmp("+",ptr_motif_660004655)==0)
ALORS
	trace ("suppression de +")
	i_get_sub_str(ptr_Dialled_660004655,1,-1,ptr_Dialled_660004655)
	longueur_660004655 = i_strlen(ptr_Dialled_660004655)
FINSI
trace1("-------3 longueur de ptr_Dialled apres suppression de sip: = %d-----------",longueur_660004655)

#detection des caracteres DTMF
i_get_sub_str (ptr_Dialled_660004655,0,0,ptr_BUF1_660004655)
i_get_sub_str (ptr_Dialled_660004655,0,1,ptr_BUF2_660004655)

SI ( i_strcmp("*#", ptr_BUF2_660004655) == 0)
ALORS
	b_DTMF_660004655=2
	trace ("presence des caracteres DTMF *#")
SINON
	SI ( i_strcmp("*", ptr_BUF1_660004655) == 0) || ( i_strcmp("#", ptr_BUF1_660004655) == 0)
	ALORS
		b_DTMF_660004655=1
		trace ("presence du caractere DTMF * ou #")
	FINSI
FINSI

#presence  DTMF *#---*
SI (b_DTMF_660004655 == 2)
ALORS
	indice_660004655 = 1
	POINT DEB_BOUCLE3
	indice_660004655 = indice_660004655 + 1
	SI (indice_660004655 < longueur_660004655)
	ALORS
		i_get_sub_str(ptr_Dialled_660004655, indice_660004655,indice_660004655, ptr_BUF3_660004655)
		SI i_strcmp(ptr_BUF3_660004655,"*") == 0 || i_strcmp(ptr_BUF3_660004655,"#") == 0
		ALORS
			indice_660004655 = indice_660004655 + 1
			SAUT FIN_BOUCLE_COMMUN1
		SINON
			SAUT DEB_BOUCLE3
		FINSI
	FINSI
FINSI

#presence DTMF  *---* ou #---#

SI (b_DTMF_660004655 == 1)
ALORS
	indice_660004655  = 0
	POINT DEB_BOUCLE4
	indice_660004655 = indice_660004655 + 1
	SI (indice_660004655 < longueur_660004655)
	ALORS
		i_get_sub_str(ptr_Dialled_660004655, indice_660004655, indice_660004655, ptr_BUF3_660004655)
		SI i_strcmp(ptr_BUF3_660004655,"*") == 0 || i_strcmp(ptr_BUF3_660004655,"#") == 0
		ALORS
			indice_660004655 = indice_660004655 + 1
			SAUT FIN_BOUCLE_COMMUN1
		SINON
			SAUT DEB_BOUCLE4
		FINSI
	FINSI
FINSI

POINT FIN_BOUCLE_COMMUN1

SI (b_DTMF_660004655 == 1 || b_DTMF_660004655 == 2)
ALORS
#Suppression des sequences DTMF
	i_get_sub_str(ptr_Dialled_660004655,indice_660004655,-1,ptr_Dialled_660004655)
	longueur_660004655=i_strlen(ptr_Dialled_660004655)
FINSI
trace1("-------4 longueur de ptr_Dialled apres suppression DTMF: = %d-----------",longueur_660004655)

POINT FIN_NOR2

#-----------------------------------#
# 2eme  Etape de la normalisation	#
# sauf pour le champ TransCalledNB	#
#-----------------------------------#
# ptr_Dialled (DialledDigits)

i_strcpy(ptr_DialledN2_660004655, ptr_Dialled_660004655)
#longueur=i_strlen(ptr_Dialled)
trace1("-------5 longueur de ptr_Dialled = %d----------",longueur_660004655)
SI ( longueur_660004655 <= 6)
ALORS
	#N? court on ajoute 33
	trace1 ("------court longueur = %d-----",longueur_660004655)
	trace("--ptr_Dialled cas numero court--")
	erreur_660004655=i_format_str2(ptr_DialledN2_660004655,"%s%s","33",ptr_Dialled_660004655)
	trace2("-------ptr_DialledN2=%s---------",ptr_DialledN2_660004655,"")
	Flag_Dialled_660004655=1
SINON
	i_get_sub_str(ptr_Dialled_660004655, 0, 0, ptr_zero_660004655)
	SI (i_strcmp("0",ptr_zero_660004655)==0 && longueur_660004655 >=10)
	ALORS
		trace ("cas ptr_Dialled long")
		i_get_sub_str (ptr_Dialled_660004655,1,-1,ptr_interm_660004655)
		erreur_660004655 = i_format_str2(ptr_DialledN2_660004655,"%s%s","33",ptr_interm_660004655)
		trace2("-----------ptr_DialledN2=%s-------",ptr_DialledN2_660004655,"")
		Flag_Dialled_660004655=1
	FINSI
FINSI


##--------------------------------#
##	T3_TrnsNb.TransCalledNB				#
##--------------------------------#

Node_660004655 = i_get_art_field(g_iartin, $Tims_CSCF::roleOfNode)
SI (Node_660004655 == 0)
ALORS
	type_cra_660004655 = 0xB1
SINON
	SI (Node_660004655 == 1)
	ALORS
		type_cra_660004655= 0xB2
	FINSI
FINSI

#-----------------------------------#
# Duplication Tdpvgsm (g_iartout)
#-----------------------------------#

SI (i_dup_art_tab( g_iartin, g_iartout, C_Tdpv_660004655))
ALORS
	trace("ERREUR de duplication")
	ERREUR_660004655 = ERR_DUPL_660004655
	code_rejet_660004655 = MODULE_660004655 + ERREUR_660004655 + EFFICACE_660004655
	erreur_660004655 = i_PlvMessEmettre(6650,2,g_iartin,"",3,code_rejet_660004655,type_cra_660004655, "Tdpvgsm")
	SAUT DISTR_ERR
FINSI

############################################################################
# Mises au format DPV33,
############################################################################

#T3t1
#T3t1.1type
erreur_660004655 = i_set_art_field(g_iartout, $Tdpvgsm::type,type_cra_660004655)


#T3t1.3 idemet
# a revoir pour la date d'interro de la table ext
SI (i_strcmp(ptr_AX_IDEMET_IMS_660004655,g_inull)) != 0
ALORS
	longueur_660004655= 0
	longueur_660004655=i_strlen(ptr_AX_IDEMET_IMS_660004655)
	erreur_660004655 = i_set_art_str(g_iartout10,$Conv_URS::recipAddAlp, ptr_AX_IDEMET_IMS_660004655)
	index_660004655=0
	POINT BOUCLE0
	SI (index_660004655 < longueur_660004655)
	ALORS
		SI (g_iartout10.recipAddHex[index_660004655] < 0x40)
		ALORS
			g_iartout.idemet[index_660004655]=g_iartout10.recipAddHex[index_660004655] - 0x30
		SINON
			g_iartout.idemet[index_660004655]=g_iartout10.recipAddHex[index_660004655] - 0x37
		FINSI
		index_660004655=index_660004655+1
		SAUT BOUCLE0
	FINSI
SINON
	#i_strcpy(pt_IDEMET_IMS,"33009000000FFFFFFF")
	#longueur = g_iartout.idemet!NELEM
	g_iartout.idemet[0]= 0x3
	g_iartout.idemet[1]= 0x3
	g_iartout.idemet[2]= 0x0
	g_iartout.idemet[3]= 0x0
	g_iartout.idemet[4]= 0x9
	index_660004655 = 5
	POINT BOUCLE
	SI index_660004655 < 11
	ALORS
		g_iartout.idemet[index_660004655]= 0x0
		index_660004655 = index_660004655 + 1
		SAUT BOUCLE
	FINSI
FINSI

#T3t2 idpart
#0xB1
SI (Node_660004655==0)
ALORS
	SI (Flag_Dialled_660004655 == 1)
	ALORS
		longueur_660004655=i_conv_ascii_dcb(ptr_DialledN2_660004655,ptr_DialledN2_DCB_660004655)
		# test longueur pour memcpy
		SI (longueur_660004655 > 19)
		ALORS
			longueur_660004655 = 19
		FINSI
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t2","idpart",longueur_660004655*8)
		erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::idpart,ptr_DialledN2_DCB_660004655,longueur_660004655)
	SINON
		longueur_660004655=i_conv_ascii_dcb(ptr_Dialled_660004655,ptr_DialledN2_DCB_660004655)
		# test longueur pour memcpy
		SI (longueur_660004655 > 19)
		ALORS
			longueur_660004655 = 19
		FINSI
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t2","idpart",longueur_660004655*8)
		erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::idpart,ptr_DialledN2_DCB_660004655,longueur_660004655)
	FINSI
SINON
	#0xB2
	SI (Node_660004655 == 1)
	ALORS
		SI (Flag_calling_660004655==1)
		ALORS
			longueur_660004655=i_conv_ascii_dcb(ptr_callingN2_660004655,ptr_callingN2_DCB_660004655)
			# test longueur pour memcpy
			SI (longueur_660004655 > 19)
			ALORS
				longueur_660004655 = 19
			FINSI
			erreur_660004655 = i_resize_tlv(g_iartout,"T3t2","idpart",longueur_660004655*8)
			erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::idpart,ptr_callingN2_DCB_660004655,longueur_660004655)
		SINON
			longueur_660004655=i_conv_ascii_dcb(ptr_calling_660004655,ptr_DialledN2_DCB_660004655)
			# test longueur pour memcpy
			SI (longueur_660004655 > 19)
			ALORS
				longueur_660004655 = 19
			FINSI
			erreur_660004655 = i_resize_tlv(g_iartout,"T3t2","idpart",longueur_660004655*8)
			erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::idpart,ptr_DialledN2_DCB_660004655,longueur_660004655)
		FINSI
	FINSI
FINSI

#T3t4 MSISDN
#0xB1
SI (Node_660004655==0)
ALORS
	SI (Flag_calling_660004655==1)
	ALORS
		longueur_660004655=i_conv_ascii_dcb(ptr_callingN2_660004655,ptr_callingN2_DCB_660004655)
		# test longueur pour memcpy
		SI (longueur_660004655 > 19)
		ALORS
			longueur_660004655 = 19
		FINSI
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t4","MSISDN",longueur_660004655*8)
		erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::MSISDN,ptr_callingN2_DCB_660004655,longueur_660004655)
	SINON
		longueur_660004655=i_conv_ascii_dcb(ptr_calling_660004655,ptr_DialledN2_DCB_660004655)
		# test longueur pour memcpy
		SI (longueur_660004655 > 19)
		ALORS
			longueur_660004655 = 19
		FINSI
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t4","MSISDN",longueur_660004655*8)
		erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::MSISDN,ptr_DialledN2_DCB_660004655,longueur_660004655)
	FINSI
SINON
	#0xB2
	SI (Node_660004655 == 1)
	ALORS
		SI (Flag_Dialled_660004655 == 1)
		ALORS
			longueur_660004655=i_conv_ascii_dcb(ptr_DialledN2_660004655,ptr_DialledN2_DCB_660004655)
			# test longueur pour memcpy
			SI (longueur_660004655 > 19)
			ALORS
				longueur_660004655 = 19
			FINSI
			erreur_660004655 = i_resize_tlv(g_iartout,"T3t4","MSISDN",longueur_660004655*8)
			erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::MSISDN,ptr_DialledN2_DCB_660004655,longueur_660004655)
		SINON
			longueur_660004655=i_conv_ascii_dcb(ptr_Dialled_660004655,ptr_DialledN2_DCB_660004655)
			# test longueur pour memcpy
			SI (longueur_660004655 > 19)
			ALORS
				longueur_660004655 = 19
			FINSI
			erreur_660004655 = i_resize_tlv(g_iartout,"T3t4","MSISDN",longueur_660004655*8)
			erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::MSISDN,ptr_DialledN2_DCB_660004655,longueur_660004655)
		FINSI
	FINSI
FINSI

#T3t1.4  IMSI
#QC424, QC498 (suppression de "resize")
SI (i_valid_field_n(g_iartin, $Tims_CSCF::IMSI))
ALORS
	erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::IMSI, ptr_IMSI_660004655)
	longueur_660004655=i_conv_ascii_dcb(ptr_IMSI_660004655,ptr_IMSI_DCB_660004655)
	#erreur = i_resize_tlv(g_iartout,"T3t1.4","IMSI",longueur*8)
	erreur_660004655 = i_memcpy_art_field_n(g_iartout,$Tdpvgsm::IMSI,ptr_IMSI_DCB_660004655,longueur_660004655)
SINON
	long_MSISDN_660004655 = i_get_art_field(g_iartout, $Tdpvgsm::MSISDN - 1)
	ele0_660004655=i_get_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN,0)
	ele1_660004655=i_get_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN,1)
	ele2_660004655=i_get_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN,2)
	SI (long_MSISDN_660004655 == 6 && ele0_660004655 ==3 && ele1_660004655 ==3 && (ele2_660004655 != 6 && ele2_660004655 != 7))
	ALORS
		erreur_660004655=affectation_tab_660004265(g_iartout,$Tdpvgsm::IMSI,"777777777777777F")
	SINON
		erreur_660004655=affectation_tab_660004265(g_iartout,$Tdpvgsm::IMSI,"999999999999999F")
	FINSI
FINSI

#T3t1.5 DATE
date_cra_660004655=i_get_art_field(g_iartin,$Tims_CSCF::callStartTime)
erreur_660004655=i_set_art_field(g_iartout,$Tdpvgsm::DATE,date_cra_660004655)

#QC424
#T3t1.13 indeff
erreur_660004655=i_set_art_field(g_iartout,$Tdpvgsm::indeff,callStatus_660004655) 

#T3t1.14  tterm
erreur_660004655=i_set_art_field(g_iartout,$Tdpvgsm::tterm, TransSessTerm_660004655)

#T4t18.13 #accPointName1
# QC490
SI (i_valid_field_n(g_iartin, $Tims_CSCF::PrivateUSID))
ALORS
	erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::PrivateUSID, ptr_PrivateUSID_660004655)
	longueur_660004655 = i_strlen(ptr_PrivateUSID_660004655)
	SI (longueur_660004655 > 63)
	ALORS
		longueur_660004655 = 63
	FINSI
	erreur_660004655 = i_resize_tlv(g_iartout,"T4t18.13","accPointName1",longueur_660004655)
	erreur_660004655 = i_set_art_str(g_iartout10,$Conv_URS::APNA,ptr_PrivateUSID_660004655)
	#erreur = i_dup_chp_1val(g_iartout10,g_iartout,$Conv_URS::APNH,$Tdpvgsm::accPointName1)
	erreur_660004655 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::accPointName1, i_get_art_fieldptr(g_iartout10, $Conv_URS::APNH), longueur_660004655)
FINSI

#QC490
#T4t20.2 #accPointName3
SI (i_valid_field_n(g_iartin, $Tims_CSCF::CSCFId))
ALORS
	erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::CSCFId, ptr_CSCFId_660004655)
	longueur_660004655 = i_strlen(ptr_CSCFId_660004655)
	SI (longueur_660004655 > 63)
	ALORS
		longueur_660004655 = 63
	FINSI
	erreur_660004655 = i_resize_tlv(g_iartout,"T4t20.2","accPointName3",longueur_660004655)
	erreur_660004655 = i_set_art_str(g_iartout10,$Conv_URS::APNA,ptr_CSCFId_660004655)
#	erreur = i_dup_chp_1val(g_iartout10,g_iartout,$Conv_URS::APNH,$Tdpvgsm::accPointName3)
	erreur_660004655 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::accPointName3, i_get_art_fieldptr(g_iartout10, $Conv_URS::APNH), longueur_660004655)
FINSI

#T3t23 #MailIdpart et #T3t24  #MailMsOrEntity
erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::callingPartAddr, ptr_calling_660004655)
longueur_660004655 = i_strlen(ptr_calling_660004655)
SI (type_cra_660004655 == 0xB1)
ALORS
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t24","MailMsOrEntity",longueur_660004655)
		erreur_660004655 = i_set_art_str(g_iartout, $Tdpvgsm::MailMsOrEntity,ptr_calling_660004655)		
SINON
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t23","MailIdpart",longueur_660004655)
		erreur_660004655 = i_set_art_str(g_iartout, $Tdpvgsm::MailIdpart,ptr_calling_660004655)
FINSI
	
erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::DialledDigits, ptr_Dialled_660004655)
longueur_660004655 = i_strlen(ptr_Dialled_660004655)
SI (type_cra_660004655 == 0xB1)
ALORS
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t23","MailIdpart",longueur_660004655)
		erreur_660004655 = i_set_art_str(g_iartout, $Tdpvgsm::MailIdpart,ptr_Dialled_660004655)
SINON
		erreur_660004655 = i_resize_tlv(g_iartout,"T3t24","MailMsOrEntity",longueur_660004655)
		erreur_660004655 = i_set_art_str(g_iartout, $Tdpvgsm::MailMsOrEntity,ptr_Dialled_660004655)		
FINSI		

############ V4T30.1 timeInCE = date audit en localtime
####### timeInCE
erreur_660004655 = i_set_art_field(g_iartout, $Tdpvgsm::timeInCE, date_plat_660004655)

############ V4T30.2 eec
# QC1405
SI (g_ieec > 500)
ALORS
  erreur_660004655 = i_set_art_field(g_iartout, $Tdpvgsm::eec, g_ieec - 500)
SINON
  erreur_660004655 = i_set_art_field(g_iartout, $Tdpvgsm::eec, g_ieec)
FINSI
#/QC1405


#T3t38.1 #origCallpartId
SI (i_valid_field_n(g_iartin, $Tims_CSCF::ICID))
ALORS
	erreur_660004655 = i_get_art_str(g_iartin, $Tims_CSCF::ICID, ptr_ICID_660004655)
	longueur_660004655 = g_iartin.ICID!NELEM
	SI (longueur_660004655 > 39)
	ALORS
		i_get_sub_str(ptr_ICID_660004655,0,38,ptr_ICID_660004655)
		erreur_660004655=i_set_art_str(g_iartout, $Tdpvgsm::origCallpartId,ptr_ICID_660004655)
	SINON
		erreur_660004655=i_set_art_str(g_iartout, $Tdpvgsm::origCallpartId,ptr_ICID_660004655)
	FINSI
FINSI

#T3t61
#T4t61.8 usrSpeechDur
erreur_660004655 = i_set_art_field(g_iartout, $Tdpvgsm::usrSpeechDur,CallDuration_660004655)

#-------------------------------
# Appel fonction aiguillage
#-------------------------------
erreur_660004655 = aiguillage2_660004590 (g_iartin, g_iartout, DISTRIBUTION_SPECIALE_660004655, Multidistribution_Non_660004655)
# QC1005
SI (erreur_660004655 == TRAI_KO_660004655)
ALORS
	trace("<<<__LINE__<<<__FILE__<<< Erreur retour fonction aiguillage2")
#	ERREUR = ERR_DISTR
#	code_rejet = ERREUR + EFFICACE
#	type_cra=i_get_art_field(g_iartout,$Tdpvgsm::type)
#	erreur=i_PlvMessEmettre(7500, 2, g_iartin, "", 1, code_rejet,type_cra,0)
	SAUT DISTR_ERR
FINSI
RETOUR TRAIT_OK

#--------------------------------
# Stockage en Errone
#---------------------------------

POINT DISTR_ERR

trace( "Stockage en errone de distribution")
res_660004655 = i_make_art_rej(g_iartin, g_iartout8, 0)
res_660004655 = i_stocke_art( g_iartout8, 0, PT_ERRONE, 0)

RETOUR TRAIT_OK
#--------------------------------- fin Tims_CSCF_dist.src ---------------------------
