DEFINITION C_ORIGINATING_860027502 0x00
DEFINITION C_TERMINATING_860027502 0x01
DEFINITION C_SUCCESSFUL_860027502 0x01
DEFINITION C_UNSUCCESSFUL_860027502 0x02
DEFINITION C_Article_860027502 "Tv2oipSBC"
REGISTRE ENTIER erreur_860027502
REGISTRE ENTIER code_errone_860027502
REGISTRE ENTIER result_860027502
REGISTRE ENTIER ROLE_OF_NODE_860027502
REGISTRE ENTIER EFFICIENCY_860027502
REGISTRE ENTIER longueur_860027502
REGISTRE ENTIER DUREE_860027502
REGISTRE ENTIER indice_860027502
REGISTRE POINTEUR pt_MESSAGE_860027502
REGISTRE POINTEUR pt_TEMP_860027502
REGISTRE POINTEUR pt_TEMP1_860027502
REGISTRE POINTEUR pt_CALLINGNB_860027502
REGISTRE POINTEUR pt_CALLEDNB_860027502
REGISTRE POINTEUR pt_TERMIPADDR_860027502
REGISTRE POINTEUR pt_ACCESSCALLID_860027502
REGISTRE POINTEUR pt_DATE_860027502
REGISTRE POINTEUR pt_adr_DATE_860027502
REGISTRE POINTEUR pt_DATE_CET_860027502
REGISTRE POINTEUR pt_annee_860027502


#####################################################################
# TRAITEMENT
#
#	Tv2oipSBC : DC plateforme SIP
#
##################################################################################################################
#
##################################################################################################################
#	HISTORIQUE
# 
# 23/10/2014 - THE/DRE - G4R8 Creation
# 26/11/2014 - THE/DRE - G4R8 QC858 QC860
# 23/01/2015 - THE/DRE - G4R8 QC873 
# 05/02/2015 - THE - G4R8 QC878 G4R8C7
# 27/03/2015 - THE - G4R8C8 - Si date 1970 envoi ELM QC891 et format Calling et called NB QC893 
#
####################################################################################################################

# Constantes


# Variables fonctionnelles


# Initialisation
result_860027502       = 0
ROLE_OF_NODE_860027502 = 0
EFFICIENCY_860027502   = 0
longueur_860027502     = 0
DUREE_860027502        = 0
indice_860027502       = 0


# DECLARATION POINTEUR


# Initialisation
pt_MESSAGE_860027502		 = "pt_MESSAGE12312312312312312312312312131213121312131213121312131232131213112131123112312131213112312131231123121"
pt_TEM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DNBpt_CALLEDNBpt_CALLEDNBpt_CALLEDNB"
pt_TERMIPADDR_860027502	 = "pt_TERMIPADDRpt_TERMIPADDRpt_TERMIPADDR"
pt_ACCESSCALLID_860027502	 = "pt_ACCESSCALLIDpt_ACCESSCALLIDpt_ACCESSCALLID"
pt_DATE_860027502			 = "pt_DATEpt_DATEpt_DATEpt_DATEpt_DATEpt_DATE"
pt_adr_DATE_860027502		 = "pt_adr_DATEpt_adr_DATEpt_adr_DATEpt_adr_DATE"
pt_DATE_CET_860027502		 = "pt_DATE_CETpt_DATE_CETpt_DATE_CETpt_DATE_CETpt_DATE_CETpt_DATE_CET"
pt_annee_860027502		 = "pt_anneept_anneept_annee"

i_strcpy(pt_MESSAGE_860027502,"")
i_strcpy(pt_TEMP_860027502,"")
i_strcpy(pt_TEMP1_860027502,"")
i_strcpy(pt_CALLINGNB_860027502,"")
i_strcpy(pt_CALLEDNB_860027502,"")
i_strcpy(pt_TERMIPADDR_860027502,"")
i_strcpy(pt_ACCESSCALLID_860027502,"")
i_strcpy(pt_DATE_860027502,"")
i_strcpy(pt_adr_DATE_860027502,"")
i_strcpy(pt_DATE_CET_860027502,"")
i_strcpy(pt_annee_860027502,"")


############################################################################################################################################
trace (" __LINE__ #### DEBUT du Pcode de Traitement :__FILE__ #### ")
############################################################################################################################################
erreur_860027502 = i_dup_art_id(g_iartin, g_iartout)

# Les DC caracterisent les communications  efficaces et inefficaces transmises par les SBC. Ils sont exploites dans le cadre d analyses QoS 
# et ne sont pas envoyes en facturation. Ils sont uniquement distribues a SYMPHONIE. 

# G4R8 QC860
# G4R8 QC873
#### IngCallId #############################
#erreur = i_get_art_str(g_iartout, $Tv2oipSBC::IngCallId, pt_TEMP)
#
#longueur = i_strlen( pt_TEMP )
#SI longueur > 59
#ALORS
#	erreur = i_resize_tlv( g_iartout, "T3IngCallId", "IngCallId", 59 )
#	erreur = i_set_art_str( g_iartout, $Tv2oipSBC::IngCallId, pt_TEMP )
#FINSI


#### SESSION_END_TIME_MET #############################
# G4R8 QC858
erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3sessEndTime, $Tv2oipSBC::SessionEndTime, 0 )
#erreur = i_dup_chp_1val(g_iartin, g_iartout, $Tv2oipSBC::dfin, $Tv2oipSBC::SessionEndTime)

# G4R8C8 QC891
erreur_860027502 = i_get_art_str(g_iartout, $Tv2oipSBC::H323DsconnctTim, pt_DATE_CET_860027502 )

i_strcpy( pt_DATE_860027502, CONV_DATE_CET_860027343 (pt_DATE_CET_860027502 ) )

SI i_strplcmp( pt_DATE_860027502, "1970",0,4) == 0
ALORS
	#trace ("__FILE__:__LINE__ #### TEST #### DATE Invalide #### TEST #### ")
	i_strcpy(pt_MESSAGE_860027502," Valeur de H323DisconnectTime invalide")	
	code_errone_860027502 = 0x5040
	erreur_860027502 = i_PlvMessEmettre( 6384, 1, g_iartin, "", 3, code_errone_860027502, C_Article_860027502, pt_MESSAGE_860027502)
	SAUT STOCKE_ERRONE
FINSI

longueur_860027502 = i_conv_ascii_dcb(pt_DATE_860027502, pt_adr_DATE_860027502)
erreur_860027502 = i_memcpy_art_field_n(g_iartout, $Tv2oipSBC::SessionEndTime, pt_adr_DATE_860027502, longueur_860027502 )


#### DATE creee dans metachamp dfin ######################
# G4R8C8 QC891
DUREE_860027502 = i_get_art_field(g_iartin,$Tv2oipSBC::DUREE)

SI DUREE_860027502 == 0
ALORS
	erreur_860027502=i_get_art_str(g_iartin, $Tv2oipSBC::H323SetupTime, pt_DATE_CET_860027502)
SINON
	erreur_860027502=i_get_art_str(g_iartin, $Tv2oipSBC::H323ConnectTime, pt_DATE_CET_860027502)
FINSI
	
SI (i_adequation_chaine_expreg (pt_DATE_CET_860027502, "^\"") == 0) 
ALORS
	i_get_sub_str(pt_DATE_CET_860027502,1,-2,pt_DATE_CET_860027502)
FINSI

i_get_sub_str(pt_DATE_CET_860027502, 24, 27, pt_annee_860027502)

SI (i_strplcmp( pt_annee_860027502, "1970", 0, 4 ) != 0 )
ALORS
	i_strcpy( pt_DATE_860027502, CONV_DATE_CET_860027343 (pt_DATE_CET_860027502 ) )
	longueur_860027502 = i_strlen( pt_DATE_860027502)
	erreur_860027502 = i_memcpy_art_field_n(g_iartout, $Tv2oipSBC::DATE, pt_DATE_860027502, longueur_860027502 )
FINSI


#### CALLING_NB #############################

erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3CallingNb, $Tv2oipSBC::CallingNb, 0 )
erreur_860027502 = i_get_art_str(g_iartout, $Tv2oipSBC::CallgStationId, pt_CALLINGNB_860027502)

# G4R8C8 QC893
indice_860027502 = RECHERCHE_CHAINE_860027343(pt_CALLINGNB_860027502, ">")
result_860027502 = RECHERCHE_CHAINE_860027343(pt_CALLINGNB_860027502, "<")

SI indice_860027502 >= 0 && result_860027502 >=0
ALORS
	SI ( indice_860027502 > result_860027502 ) && ( indice_860027502 - result_860027502 > 1 )
	ALORS
		erreur_860027502 = i_recupererValeur(pt_CALLINGNB_860027502, pt_TEMP_860027502, i_strlen(pt_CALLINGNB_860027502), '>')
		erreur_860027502 = i_recupererValeur(pt_TEMP_860027502, pt_CALLINGNB_860027502, i_strlen(pt_TEMP_860027502), '<')
		i_strcpy(pt_CALLINGNB_860027502, pt_TEMP_860027502 )
	FINSI
FINSI

#erreur = i_adequation_chaine_expreg (pt_CALLINGNB, ">")
#
#SI erreur == 0
#ALORS
#	erreur = i_adequation_chaine_expreg (pt_CALLINGNB, "<")
#	SI erreur == 0
#	ALORS
#		erreur = i_recupererValeur(pt_CALLINGNB, pt_TEMP, i_strlen(pt_CALLINGNB), '>')
#		erreur = i_recupererValeur(pt_TEMP, pt_CALLINGNB, i_strlen(pt_TEMP), '<')
#		i_strcpy(pt_CALLINGNB, pt_TEMP )
#	FINSI
#FINSI

erreur_860027502 = i_adequation_chaine_expreg (pt_CALLINGNB_860027502, "\"")
SI erreur_860027502 == 0
ALORS
	i_strcpy(pt_TEMP_860027502,REMPLACE_CHAINE_860027343(pt_CALLINGNB_860027502,"\"","\0"))
	i_strcpy(pt_CALLINGNB_860027502,pt_TEMP_860027502)
FINSI

#erreur = i_set_art_str(g_iartout, $Tv2oipSBC::CallingNb, pt_CALLINGNB )
erreur_860027502 = i_resize_tlv( g_iartout, "T3CallingNb", "CallingNb", i_strlen(pt_CALLINGNB_860027502) )
erreur_860027502 = i_memcpy_art_field_n(g_iartout, $Tv2oipSBC::CallingNb, pt_CALLINGNB_860027502, i_strlen(pt_CALLINGNB_860027502))


#### CALLED_NB #############################

erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3CalledNb, $Tv2oipSBC::CalledNb, 0 )
erreur_860027502 = i_get_art_str(g_iartout, $Tv2oipSBC::CalledStationId, pt_CALLEDNB_860027502)

# G4R8C8 QC893
indice_860027502 = RECHERCHE_CHAINE_860027343(pt_CALLEDNB_860027502, ">")
result_860027502 = RECHERCHE_CHAINE_860027343(pt_CALLEDNB_860027502, "<")

SI indice_860027502 >= 0 && result_860027502 >=0
ALORS
	SI ( indice_860027502 > result_860027502 ) && ( indice_860027502 - result_860027502 > 1 )
	ALORS
		erreur_860027502 = i_recupererValeur(pt_CALLEDNB_860027502, pt_TEMP_860027502, i_strlen(pt_CALLEDNB_860027502), '>')
		erreur_860027502 = i_recupererValeur(pt_TEMP_860027502, pt_CALLEDNB_860027502, i_strlen(pt_TEMP_860027502), '<')
		i_strcpy(pt_CALLEDNB_860027502, pt_TEMP_860027502 )
	FINSI
FINSI

#erreur = i_adequation_chaine_expreg (pt_CALLEDNB, ">")
#
#SI erreur == 0
#ALORS
#	erreur = i_adequation_chaine_expreg (pt_CALLEDNB, "<")
#	SI erreur == 0
#	ALORS
#		erreur = i_recupererValeur(pt_CALLEDNB, pt_TEMP, i_strlen(pt_CALLEDNB), '>')
#		erreur = i_recupererValeur(pt_TEMP, pt_CALLEDNB, i_strlen(pt_TEMP), '<')
#		i_strcpy(pt_CALLEDNB, pt_TEMP )
#	FINSI
#FINSI

erreur_860027502 = i_adequation_chaine_expreg (pt_CALLEDNB_860027502, "\"")
SI erreur_860027502 == 0
ALORS
	i_strcpy(pt_TEMP_860027502,REMPLACE_CHAINE_860027343(pt_CALLEDNB_860027502,"\"","\0"))
	i_strcpy(pt_CALLEDNB_860027502,pt_TEMP_860027502)
FINSI

longueur_860027502 = i_strlen(pt_CALLEDNB_860027502)
#erreur = i_set_art_str(g_iartout, $Tv2oipSBC::CallingNb, pt_CALLINGNB )
erreur_860027502 = i_resize_tlv( g_iartout, "T3CalledNb", "CalledNb", longueur_860027502 )
erreur_860027502 = i_memcpy_art_field_n(g_iartout, $Tv2oipSBC::CalledNb, pt_CALLEDNB_860027502, longueur_860027502)


#### EFFICIENCY #############################
erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3Efficiency, $Tv2oipSBC::Efficiency, 0 )

result_860027502 = i_get_art_field(g_iartout, $Tv2oipSBC::SIPStatus)

SI result_860027502 == 0x00
ALORS
	EFFICIENCY_860027502 = C_SUCCESSFUL_860027502
SINON
	EFFICIENCY_860027502 = C_UNSUCCESSFUL_860027502
FINSI

erreur_860027502 = i_set_art_field(g_iartout, $Tv2oipSBC::Efficiency, EFFICIENCY_860027502 )


#### ROLE_OF_NODE #############################
erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3roleOfNode, $Tv2oipSBC::RoleOfNode, 0 )

erreur_860027502 = i_get_art_str(g_iartout, $Tv2oipSBC::IngRealm, pt_TEMP_860027502)

erreur_860027502 = i_adequation_chaine_expreg (pt_TEMP_860027502, "\"")
SI erreur_860027502 == 0
ALORS
	i_strcpy(pt_TEMP1_860027502,REMPLACE_CHAINE_860027343(pt_TEMP_860027502,"\"","\0"))
FINSI

# G4R8 QC858 replace pt_TEMP1 par pt_TEMP
SI ( i_adequation_chaine_expreg (pt_TEMP_860027502, "^access") == 0 )
ALORS
	ROLE_OF_NODE_860027502 = C_ORIGINATING_860027502
SINON
	ROLE_OF_NODE_860027502 = C_TERMINATING_860027502
FINSI

erreur_860027502 = i_set_art_field(g_iartout, $Tv2oipSBC::RoleOfNode, ROLE_OF_NODE_860027502 )


#### TERM_IP_ADDR #############################
erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3TermIPAddr, $Tv2oipSBC::TermIPAddr, 0 )

SI ROLE_OF_NODE_860027502 == C_ORIGINATING_860027502
ALORS
	erreur_860027502 = i_get_art_str( g_iartout, $Tv2oipSBC::IngRemoteAddr, pt_TERMIPADDR_860027502 )
SINON
	erreur_860027502 = i_get_art_str( g_iartout, $Tv2oipSBC::EgrRemoteAddr, pt_TERMIPADDR_860027502 )
FINSI

erreur_860027502 = i_adequation_chaine_expreg (pt_TERMIPADDR_860027502, "\"")
SI erreur_860027502 == 0
ALORS
	i_strcpy(pt_TEMP_860027502,REMPLACE_CHAINE_860027343(pt_TERMIPADDR_860027502,"\"","\0"))
	i_strcpy(pt_TERMIPADDR_860027502,pt_TEMP_860027502)
FINSI

longueur_860027502 = i_strlen(pt_TERMIPADDR_860027502 )
erreur_860027502 = i_resize_tlv( g_iartout, "T3TermIPAddr", "TermIPAddr", longueur_860027502 )
erreur_860027502 = i_set_art_str( g_iartout, $Tv2oipSBC::TermIPAddr, pt_TERMIPADDR_860027502 )


#### ACCESS_CALL_ID #############################
erreur_860027502 = i_ajoutChampNum(g_iartout, $Tv2oipSBC::T3AccessCallId, $Tv2oipSBC::AccessCallId, 0 )

SI ROLE_OF_NODE_860027502 == C_ORIGINATING_860027502
ALORS
	erreur_860027502 = i_get_art_str( g_iartout, $Tv2oipSBC::EgrCallId, pt_ACCESSCALLID_860027502 )
SINON
	# G4R8C5 QC873
	erreur_860027502 = i_get_art_str( g_iartout, $Tv2oipSBC::IngCallId, pt_TEMP_860027502 )

	#### IngCallId #############################
	longueur_860027502 = i_strlen( pt_TEMP_860027502 )
	SI longueur_860027502 > 59
	ALORS
		i_get_sub_str( pt_TEMP_860027502, 0, 58, pt_TEMP_860027502 )
# G4R8C7 QC878
#		i_strcpy( pt_ACCESSCALLID, pt_TEMP )
	FINSI
	i_strcpy( pt_ACCESSCALLID_860027502, pt_TEMP_860027502 )
FINSI

erreur_860027502 = i_adequation_chaine_expreg (pt_ACCESSCALLID_860027502, "\"")
SI erreur_860027502 == 0
ALORS
	i_strcpy(pt_TEMP_860027502,REMPLACE_CHAINE_860027343(pt_ACCESSCALLID_860027502,"\"","\0"))
	i_strcpy(pt_ACCESSCALLID_860027502,pt_TEMP_860027502)
FINSI

longueur_860027502 = i_strlen(pt_ACCESSCALLID_860027502 )
erreur_860027502 = i_resize_tlv( g_iartout, "T3AccessCallId", "AccessCallId", longueur_860027502 )
erreur_860027502 = i_set_art_str( g_iartout, $Tv2oipSBC::AccessCallId, pt_ACCESSCALLID_860027502 )


SAUT STOCKE_OK


#==============================================================================
#	Stockage en valide
#==============================================================================

POINT   STOCKE_OK

#trace("[Tv2oip_tr] #trace Stockage en valide")
erreur_860027502 = i_stocke_art(g_iartout, 0, PT_OK, 0)

RETOUR TRAIT_OK

#==============================================================================
#	Stockage en errone
#==============================================================================

POINT  STOCKE_ERRONE

#trace("[Tv2oip_tr] Stockage en ERRONE ")

erreur_860027502 = i_make_art_rej(g_iartin, g_iartout5, code_errone_860027502)
erreur_860027502 = i_stocke_art(g_iartout5, 0, PT_ERRONE, 0)

RETOUR TRAIT_OK

#==============================================================================
#	Stockage en elimine
#==============================================================================

POINT  STOCKE_ELM

#trace("[Tv2oip_tr] Stockage en ELIMINE ")

#erreur = i_stocke_art(g_iartin, 0, PT_ELIMINE, 0)
erreur_860027502 = i_stocke_art(g_iartin, 0, PT_DIVERS, 0)

RETOUR TRAIT_OK

#--------------Fin Pcode Traitement Tv2oip_tr.src-------------------------
