DEFINITION C_Tdpv_660004659 "Tdpvgsm"
DEFINITION ERR_DUPL_660004659 0x0D0
DEFINITION MODULE_660004659 0xA000
DEFINITION ERR_DISTR_660004659 0x110
DEFINITION ERR_CONV_660004659 0x0E0
DEFINITION Multidistribution_Non_660004659 0
DEFINITION DISTRIBUTION_SPECIALE_660004659 0
DEFINITION NUMTAB_660004659 4
DEFINITION TRAI_KO_660004659 -1
REGISTRE ENTIER EFFICACE_660004659
REGISTRE ENTIER date_fin_660004659
REGISTRE ENTIER sessionTerm_660004659
REGISTRE ENTIER val_sessTerm_660004659
REGISTRE ENTIER TransSessTerm_660004659
REGISTRE ENTIER Node_660004659
REGISTRE ENTIER type_cra_660004659
REGISTRE ENTIER longueur_660004659
REGISTRE ENTIER long_MSISDN_660004659
REGISTRE ENTIER ele0_660004659
REGISTRE ENTIER ele1_660004659
REGISTRE ENTIER ele2_660004659
REGISTRE ENTIER date_audit_660004659
REGISTRE ENTIER Start_Date_660004659
REGISTRE ENTIER Date_Debut_660004659
REGISTRE ENTIER Request_Time_660004659
REGISTRE ENTIER Request_660004659
REGISTRE ENTIER Date_Fin_660004659
REGISTRE ENTIER End_Time_660004659
REGISTRE ENTIER erreur_660004659
REGISTRE ENTIER ERREUR_660004659
REGISTRE ENTIER code_rejet_660004659
REGISTRE ENTIER res_660004659
REGISTRE ENTIER v_CORLStatus_660004659
REGISTRE ENTIER flag_rdt_660004659
REGISTRE ENTIER cpteur_660004659
REGISTRE ENTIER TelSvc_660004659
REGISTRE POINTEUR pt_val_sessTerm_660004659
REGISTRE POINTEUR pt_TransSessTerm_660004659
REGISTRE POINTEUR pt_call_660004659
REGISTRE POINTEUR pt_calling_660004659
REGISTRE POINTEUR pt_calling_DCB_660004659
REGISTRE POINTEUR pt_motif_660004659
REGISTRE POINTEUR pt_Dialled_660004659
REGISTRE POINTEUR pt_Dialled_DCB_660004659
REGISTRE POINTEUR pt_Dial_660004659
REGISTRE POINTEUR pt_IMSI_660004659
REGISTRE POINTEUR pt_IMSI_DCB_660004659
REGISTRE POINTEUR pt_valeurIN_660004659
REGISTRE POINTEUR pt_networkInfo_660004659
REGISTRE POINTEUR pt_localisation_660004659
REGISTRE POINTEUR pt_CORLStatus_660004659
REGISTRE POINTEUR pt_localisation_DCB_660004659
REGISTRE POINTEUR pt_SubRecordType_660004659
REGISTRE POINTEUR pt_1_660004659
REGISTRE POINTEUR pt_TelSvc_660004659
REGISTRE POINTEUR pt_cle_660004659
REGISTRE POINTEUR pt_AX_IDEMET_660004659
################################################################################
#
# Pcode de distribution PRIMS : TprimsRCSe_dis.src
#
# history :
#     Creation le 04/10/12 en G3R8 lot1
#     15/11/12 EEC/JLG G3R8 lot3 QC1140 evolution format des champs SgsnAddr et ggsnAddr
#     28/11/12 EEC/JLG G3R8 lot3 QC1140 evolution format par defaut de tlserv
# 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
################################################################################





pt_AX_IDEMET_660004659 = "pt_AX_IDEMET11111111"

val_sessTerm_660004659 = 0
sessionTerm_660004659 = 0
date_fin_660004659 = 0
Node_660004659 = -1
type_cra_660004659 = 0
EFFICACE_660004659 = 1
longueur_660004659 = -1
ele0_660004659 = 0
ele1_660004659 = 0
ele2_660004659 = 0
long_MSISDN_660004659 = 0
Start_Date_660004659 = 0
Date_Debut_660004659 = -1
erreur_660004659 = -1
code_rejet_660004659 = 0
res_660004659 = 0
v_CORLStatus_660004659 = -1
Request_Time_660004659 = 0
Request_660004659 = -1
Date_Fin_660004659 = -1
End_Time_660004659 = 0
flag_rdt_660004659 = 0
cpteur_660004659 = 0

pt_val_sessTerm_660004659 = C_Tdpv_660004659

pt_val_sessTerm_660004659 = "pt_val_sessTerm21"
pt_TransSessTerm_660004659 = "pt_TransSessTerm9"
pt_call_660004659 = "pt_call7676767676767676767676767667676767676767676767676767676767676767676767676767676767767676776767676767611111111111111111111"
pt_calling_660004659 = "pt_calling3838383838383838383838383838383838383838383838388383838383838383838838383838383838838383838383831111111111111111111111"
pt_calling_DCB_660004659 = "pt_calling_DCB3333333333333333333333333333333333333333333333333333333"
pt_Dialled_660004659 = "pt_Dialled2525252525252525252525252525252525252525252552525252525252525252525252525252525252525252525252525111111111111111111111"
pt_Dialled_DCB_660004659 = "pt_Dialled_DCB2222222222222222222222222222222222222222222222222221111"
pt_Dial_660004659    = "pt_Dial2929292929292929292929292929292929229292929292922929292929292929292929292929922929299292929229929291111111111111111111111"
pt_IMSI_660004659 = "pt_IMSI_DCB757575757575757757575757575757575757575757575755757575775577557757575755757577557755775755775757557111111111111111111"
pt_IMSI_DCB_660004659 = "pt_IMSI85858585858585858585858585858585858585858588558585858585858585"
pt_valeurIN_660004659 = "pt_valeurIN09090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090909090990909"
pt_networkInfo_660004659 = "pt_networkInfo721727127171277127717271762721721727717271727717627172172717727172712771277127712717217277877717217721726722627261"
pt_motif_660004659 = "pt_motif31313131331313311313131313131313131313313313313131133131313131133313131313131131331311313313313131313311333311331313333131131333131313313113"
pt_localisation_660004659 = "pt_localisation5151515151515151515151515155151515151111111111111111111111111111111111111111111111111111111111111111111111111"
pt_CORLStatus_660004659 = "pt_CORLStatus1"
pt_localisation_DCB_660004659 = "pt_localisation_DCB37837837837837837837837837387383783783738371138373"
pt_SubRecordType_660004659 = "pt_SubRecordType8080808080808080808088808808088088080808080808088081110808080808080808080808080808080800808808080808080808080801"
i_strcpy(pt_val_sessTerm_660004659,"")
i_strcpy(pt_TransSessTerm_660004659,"")
i_strcpy(pt_call_660004659,"")
i_strcpy(pt_calling_660004659,"")
i_strcpy(pt_Dialled_660004659,"")
i_strcpy(pt_Dial_660004659,"")
i_strcpy(pt_Dialled_DCB_660004659,"")
i_strcpy(pt_calling_DCB_660004659,"")
i_strcpy(pt_IMSI_DCB_660004659,"")
i_strcpy(pt_IMSI_660004659,"")
i_strcpy(pt_valeurIN_660004659,"")
i_strcpy(pt_networkInfo_660004659,"")
i_strcpy(pt_motif_660004659,"")
i_strcpy(pt_localisation_660004659,"")
i_strcpy(pt_CORLStatus_660004659,"")
i_strcpy(pt_localisation_DCB_660004659,"")
i_strcpy(pt_SubRecordType_660004659,"")


pt_1_660004659="pt_1_11111111111111111111111111111"
pt_TelSvc_660004659="pt_TelSvc_2222222222222222222"
pt_cle_660004659="pt_cle_4444444444444444444444"

trace ("---------------------------------")
trace ("  PRIMS_RCSE Distribution    ")
trace ("---------------------------------")

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

SI (flag_rdt_660004659 == 0)
ALORS
  erreur_660004659 = i_add_opt("E_Redistri2")
FINSI
erreur_660004659 = i_set_attr_val_n($E_Redistri2::EnvoiRedis, 0)

########################################################
# Cpt applicatif CPT_RDT=1509 (REDISTRIBUTION)
########################################################
date_fin_660004659 = i_get_art_field(g_iartin, $TprimsRCSe::dfin)
erreur_660004659 = i_incr_redist_dist_660004265(date_fin_660004659)

erreur_660004659 = i_cree_art("Conv_URS", g_iartout10)

#-------------#
#AX_IDEMET
#-------------#
#  Sdate Platine
erreur_660004659 = i_format_str2( pt_1_660004659, "%s%s", "AX_IDEMET_", i_LireEECSGTQS(g_ieec))
i_strcpy(pt_AX_IDEMET_660004659, i_get_tab_field("VariableContexte", i_get_art_field(g_iartin, $TprimsRCSe::StartTime_SDATE), pt_1_660004659))


#-----------------------------#
# Calcul de TransSessTerm
#-----------------------------#

#TransSessTerm = 0xFF
SI (i_valid_field_n(g_iartin, $TprimsRCSe::sessionTerm))
ALORS
  sessionTerm_660004659 = i_get_art_field(g_iartin, $TprimsRCSe::sessionTerm)
  # Recuperation de la valeur absolue
  SI sessionTerm_660004659 < 0
  ALORS
    val_sessTerm_660004659 = sessionTerm_660004659 - (2 * sessionTerm_660004659)
  SINON
    val_sessTerm_660004659 = sessionTerm_660004659
  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_660004659/100
  g_iartout10.chgcarDCB[2] = (val_sessTerm_660004659 - (g_iartout10.chgcarDCB[1]*100)) /10
  g_iartout10.chgcarDCB[3] = val_sessTerm_660004659 - (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_660004659 = i_get_art_str(g_iartout10, $Conv_URS::chgcarDCB, pt_val_sessTerm_660004659)
  i_get_sub_str(pt_val_sessTerm_660004659, 1, 3, pt_val_sessTerm_660004659)

  i_strcpy(pt_TransSessTerm_660004659, i_get_tab_field("SCSCFRecordClosing", date_fin_660004659, pt_val_sessTerm_660004659))

  SI (i_strcmp(pt_TransSessTerm_660004659, g_inull)) != 0
  ALORS
    TransSessTerm_660004659 = CONV_ASCIINUMHEX_INT_660004265(pt_TransSessTerm_660004659)
  SINON
    TransSessTerm_660004659 = 0xFF
  FINSI
FINSI

#--------------------------#
#Localisation
#--------------------------#
SI (i_valid_field_n(g_iartin, $TprimsRCSe::networkInfo))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::networkInfo, pt_networkInfo_660004659)
  erreur_660004659 = i_format_str2(pt_valeurIN_660004659, "%s%s", pt_networkInfo_660004659, ";")
  trace("<<__LINE__>> networkInfo present ")
  #i_strcpy(pt_valeurIN,pt_networkInfo)

#recherche du motif au debut de la chaine
  SI !(i_strplcmp(pt_valeurIN_660004659, "lac=", 0, 4))
  ALORS
    erreur_660004659 = i_recupererValeur(pt_valeurIN_660004659, pt_motif_660004659, longueur_660004659 - 1, ';')
    i_get_sub_str(pt_valeurIN_660004659, 4, -1, pt_localisation_660004659)
    longueur_660004659 = i_strlen(pt_localisation_660004659)
    SI (longueur_660004659 > 5)
    ALORS
      i_get_sub_str(pt_localisation_660004659, 0, 4, pt_localisation_660004659)
    FINSI
    SAUT BOUCLE_FIN
  FINSI

#recherche du motif non au debut de la chaine
  longueur_660004659 = i_strlen(pt_valeurIN_660004659)
  cpteur_660004659 = 0
  POINT BOUCLE_RECHERCHE
  SI (cpteur_660004659 <= longueur_660004659)
  ALORS
    erreur_660004659 = i_recupererValeur(pt_valeurIN_660004659, pt_motif_660004659, longueur_660004659 - 1, ';')
    SI !(i_strplcmp(pt_motif_660004659, "lac=", 0, 4))
    ALORS
      i_get_sub_str(pt_motif_660004659, 4, -1, pt_localisation_660004659)
      longueur_660004659 = i_strlen(pt_localisation_660004659)

      SI (longueur_660004659 > 5)
      ALORS
        i_get_sub_str(pt_localisation_660004659, 0, 4, pt_localisation_660004659)
      FINSI
      SAUT BOUCLE_FIN
    SINON
      cpteur_660004659 = cpteur_660004659 + 1
      longueur_660004659 = i_strlen(pt_valeurIN_660004659)
      SAUT BOUCLE_RECHERCHE
    FINSI
  FINSI
FINSI
POINT BOUCLE_FIN


#--------------------------#
#TelSvc
#si dans la table "TYPE_TELSVC" on a RCS_0220;42 correspondance TelSvc= 0x42
#code 0220 signifiant : 02 = conference , 2 = sendrecv , 0 = pas de conference =>
#il s'agit d'un CRA "Instant messaging" auquel il faut associer le teleservice 42
#--------------------------#
# QC1140
TelSvc_660004659 = 0xFF
SI (i_valid_field_n(g_iartin, $TprimsRCSe::ComputedInf08))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::ComputedInf08, pt_1_660004659)
  i_get_sub_str(pt_1_660004659, -4, -1, pt_1_660004659)
  erreur_660004659 = i_format_str2( pt_cle_660004659, "%s%s", "RCS_", pt_1_660004659)
  i_strcpy(pt_TelSvc_660004659, i_get_tab_field("TYPE_TELSVC", date_fin_660004659, pt_cle_660004659))
  SI (i_strcmp(pt_TelSvc_660004659,"") != 0)
  ALORS
    i_get_sub_str(pt_TelSvc_660004659, 0, 1, pt_TelSvc_660004659)
    TelSvc_660004659 = CONV_ASCIINUMHEX_INT_660004265(pt_TelSvc_660004659)
  FINSI
FINSI


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

# ------------1er phase de normalisation-------------------------#
# suppression des prefixe: tel: et sip:
#   suppression si le 1er digit est +
#   suppresion des caracteres DTMF
#   suppression si les 2 premiers digits valent 00
#   suppression des suffixes ? partir du caracteres @
#   T3_callingNb,T3_DialledDigits
#   Ces traitements sont realis?s par la fonction NORMA_PRIMS
#----------------------------------------------------------------#

#----------------------------------------------------------------#
#   T3_callingNb/CallPrtAdr2Dat (Demandeur)
#----------------------------------------------------------------#
SI (i_valid_field_n(g_iartin, $TprimsRCSe::CallPrtAdr2Dat))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::CallPrtAdr2Dat, pt_call_660004659)
  i_strcpy (pt_calling_660004659, NORMA_PRIMS_660004265(pt_call_660004659))

  trace2("=====Normalisation CallPrtAdr2Dat %s", pt_calling_660004659, "")
FINSI

#----------------------------------------------------------------------------#
#   T3_DialledDigits/DialledDigits (Demande), pt_Dialled
#----------------------------------------------------------------------------#
SI (i_valid_field_n(g_iartin, $TprimsRCSe::DialledDigits))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::DialledDigits, pt_Dial_660004659)
  i_strcpy(pt_Dialled_660004659, NORMA_PRIMS_660004265(pt_Dial_660004659))
  trace2 ("=====Normalisation DialledDigits = %s", pt_Dialled_660004659, "")
FINSI

#-------------------
# Type d'appel RoleofNode
#--------------------
Node_660004659 = i_get_art_field(g_iartin, $TprimsRCSe::roleOfNode)
SI (Node_660004659 == 0)
ALORS
  type_cra_660004659 = 0xB1
SINON
  SI (Node_660004659 == 1)
  ALORS
    type_cra_660004659= 0xB2
  FINSI
FINSI

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

SI (i_dup_art_tab( g_iartin, g_iartout, C_Tdpv_660004659))
ALORS
  trace("ERREUR de duplication")
  ERREUR_660004659 = ERR_DUPL_660004659
  code_rejet_660004659 = MODULE_660004659 + ERREUR_660004659   + EFFICACE_660004659
  erreur_660004659 = i_PlvMessEmettre(6661, 2, g_iartin, "", 2, code_rejet_660004659, "Tdpvgsm", 0)
  SAUT DISTR_ERR
FINSI

############################################################################
# Mises au format DPV40,
############################################################################

#T3t1
#T3t1.1 type    :D  :-  :MSET :FF
erreur_660004659 = i_set_art_field(g_iartout, $Tdpvgsm::type,type_cra_660004659)

#T3t1.2 tentite   :-  :-  :MSET :17
#T3t1.3 idemet    :-  :-  :MSET :FF
SI (i_strcmp(pt_AX_IDEMET_660004659,"") != 0)
ALORS
        erreur_660004659 = affectation_tab_660004265(g_iartout, $Tdpvgsm::idemet, pt_AX_IDEMET_660004659)
SINON
        erreur_660004659 = affectation_tab_660004265(g_iartout, $Tdpvgsm::idemet, "33009000000FFFFFFF")
FINSI

#T3t1.4 IMSI    :-  :-  :MSET :99 Calcule plus bas (MSISDN doit etre connu)

#T3t1.5 DATE    :-  :-  :1VAL :callStartTime
# Sdate Platine
Start_Date_660004659=i_get_art_field(g_iartin, $TprimsRCSe::StartTime_SDATE)
Date_Debut_660004659 = i_DHgetLocalTime(NUMTAB_660004659, 7, Start_Date_660004659)
SI ( Date_Debut_660004659 == 0)
ALORS
  trace ("erreur conversion date StartTime_SDATE")
  ERREUR_660004659 = ERR_CONV_660004659
  code_rejet_660004659 = MODULE_660004659 + ERREUR_660004659   + EFFICACE_660004659
  erreur_660004659 = i_PlvMessEmettre(6662, 2, g_iartin, "", 2, code_rejet_660004659, "callStartTime", 0)
  SAUT DISTR_ERR
SINON
  erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::DATE, Date_Debut_660004659)
FINSI

#T3t1.6 DUREE   :-  :-  :MSET :00
erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::DUREE, i_get_art_field(g_iartin, $TprimsRCSe::dduree))

#T3t1.7 svcsup    :D  :-  :MSET :FF:1
#T3t1.8 tlserv    :-  :-  :MSET :FF:1
SI (TelSvc_660004659 != 0xFF)
ALORS
  erreur_660004659 = i_set_art_field(g_iartout, $Tdpvgsm::tlserv, TelSvc_660004659)
FINSI

#T3t1.9 support1  :-  :-  :MSET :FF:1
#T3t1.10 systype    :-  :-  :MSET :05
#T3t1.11 reserve2 :-  :-  :MSET :FF:1
#T3t1.12 origine    :-  :-  :MSET :FF:1

#T3t1.13 indeff   :-  :-  :MSET :00:1
SI (i_valid_field_n(g_iartin, $TprimsRCSe::callStatus))
ALORS
  erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::indeff, i_get_art_field(g_iartin, $TprimsRCSe::callStatus))
FINSI

#T3t1.14 tterm    :-  :-  :MSET :FF:1
SI (i_valid_field_n(g_iartin, $TprimsRCSe::sessionTerm))
ALORS
  erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::tterm, TransSessTerm_660004659)
FINSI

#T3t1.15 indtax   :-  :-  :MSET :FF:1
#T3t1.16 nbUT   :-  :-  :MSET :FF:4
#T3t1.17 chgcar   :-  :-  :MSET :FF:2
#T3t1.18 couleur    :-  :-  :MSET :FF:1

#T3t2 idpart
#0xB1
SI (type_cra_660004659 == 0xB1)
ALORS
  SI (i_strplcmp (pt_Dialled_660004659," ", 0, 1) != 0)
  ALORS
    longueur_660004659=i_conv_ascii_dcb(pt_Dialled_660004659, pt_Dialled_DCB_660004659)
		# test longueur pour memcpy
		SI (longueur_660004659 > 19)
		ALORS
			longueur_660004659 = 19
		FINSI
    erreur_660004659 = i_resize_tlv(g_iartout, "T3t2", "idpart", longueur_660004659*8)
    erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::idpart, pt_Dialled_DCB_660004659, longueur_660004659)
  SINON
    longueur_660004659=i_strlen(pt_Dialled_660004659)
    SI (longueur_660004659 > 19)
    ALORS
      longueur_660004659 = 19
    FINSI
    erreur_660004659 = i_resize_tlv(g_iartout, "T3t2", "idpart", longueur_660004659*8)
    erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::idpart, pt_Dialled_660004659, longueur_660004659)
    erreur_660004659 = i_set_art_fieldtab(g_iartout, $Tdpvgsm::idpart, 0, 0x00)
  FINSI
SINON
  #0xB2
  SI (type_cra_660004659 == 0xB2)
  ALORS
    SI (i_strplcmp (pt_calling_660004659," ",0,1) != 0)
    ALORS
      longueur_660004659=i_conv_ascii_dcb(pt_calling_660004659, pt_calling_DCB_660004659)
			# test longueur pour memcpy
			SI (longueur_660004659 > 19)
			ALORS
				longueur_660004659 = 19
			FINSI
      erreur_660004659 = i_resize_tlv(g_iartout, "T3t2", "idpart", longueur_660004659*8)
      erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::idpart, pt_calling_DCB_660004659, longueur_660004659)
    SINON
      longueur_660004659=i_strlen(pt_calling_660004659)
      SI (longueur_660004659 > 19)
      ALORS
        longueur_660004659 = 19
      FINSI
      erreur_660004659 = i_resize_tlv(g_iartout, "T3t2", "idpart", longueur_660004659*8)
      erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::idpart,pt_calling_660004659, longueur_660004659)
      erreur_660004659 = i_set_art_fieldtab(g_iartout, $Tdpvgsm::idpart, 0, 0x00)
    FINSI
  FINSI
FINSI

#T3t3 local
SI (i_valid_field_n(g_iartin, $TprimsRCSe::networkInfo))
ALORS
  longueur_660004659 = i_conv_ascii_dcb(pt_localisation_660004659, pt_localisation_DCB_660004659)
	# test longueur pour memcpy
	SI (longueur_660004659 > 9)
	ALORS
		longueur_660004659 = 9
	FINSI
  erreur_660004659 = i_resize_tlv(g_iartout, "T3t3", "local", longueur_660004659*8)
  erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::local, pt_localisation_DCB_660004659, longueur_660004659)
SINON
  erreur_660004659 = i_supprChamp(g_iartout, "T3t3")
FINSI

#T3t4 MSISDN
#0xB1
SI (type_cra_660004659 == 0xB1)
ALORS
  SI (i_strplcmp (pt_calling_660004659," ",0,1) != 0)
  ALORS
    longueur_660004659=i_conv_ascii_dcb(pt_calling_660004659, pt_calling_DCB_660004659)
		# test longueur pour memcpy
		SI (longueur_660004659 > 19)
		ALORS
			longueur_660004659 = 19
		FINSI
    erreur_660004659 = i_resize_tlv(g_iartout, "T3t4", "MSISDN", longueur_660004659*8)
    erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::MSISDN, pt_calling_DCB_660004659, longueur_660004659)
  SINON
    longueur_660004659=i_strlen(pt_calling_660004659)
    SI (longueur_660004659 > 19)
    ALORS
      longueur_660004659 = 19
    FINSI
    erreur_660004659 = i_resize_tlv(g_iartout, "T3t4", "MSISDN", longueur_660004659*8)
    erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::MSISDN, pt_calling_660004659, longueur_660004659)
    erreur_660004659 = i_set_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN, 0, 0x00)
  FINSI
SINON
  #0xB2
  SI (type_cra_660004659 == 0xB2)
  ALORS
    SI (i_strplcmp (pt_Dialled_660004659, " ", 0, 1) != 0)
    ALORS
      longueur_660004659=i_conv_ascii_dcb(pt_Dialled_660004659, pt_Dialled_DCB_660004659)
			# test longueur pour memcpy
			SI (longueur_660004659 > 19)
			ALORS
				longueur_660004659 = 19
			FINSI
      erreur_660004659 = i_resize_tlv(g_iartout, "T3t4", "MSISDN", longueur_660004659*8)
      erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::MSISDN, pt_Dialled_DCB_660004659, longueur_660004659)
    SINON
      longueur_660004659=i_strlen(pt_Dialled_660004659)
      SI (longueur_660004659 > 19)
      ALORS
        longueur_660004659 = 19
      FINSI
      erreur_660004659 = i_resize_tlv(g_iartout, "T3t4", "MSISDN", longueur_660004659*8)
      erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::MSISDN, pt_Dialled_660004659,longueur_660004659)
      erreur_660004659 = i_set_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN, 0, 0x00)
    FINSI
  FINSI
FINSI

# tronquer a 15 octets, IMSI depend de MSISDN
#T3t1.4  IMSI   :-  :-  :MSET :99
SI (i_valid_field_n(g_iartin, $TprimsRCSe::IMSI))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::IMSI, pt_IMSI_660004659)
  i_get_sub_str (pt_IMSI_660004659, 0, 14, pt_IMSI_660004659)
  longueur_660004659=i_conv_ascii_dcb(pt_IMSI_660004659, pt_IMSI_DCB_660004659)
  erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::IMSI, pt_IMSI_DCB_660004659, longueur_660004659)
SINON
  long_MSISDN_660004659 = i_get_art_field(g_iartout, $Tdpvgsm::MSISDN - 1)
  ele0_660004659=i_get_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN,0)
  ele1_660004659=i_get_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN,1)
  ele2_660004659=i_get_art_fieldtab(g_iartout, $Tdpvgsm::MSISDN,2)
  SI (long_MSISDN_660004659 == 6 && ele0_660004659 ==3 && ele1_660004659 ==3 && (ele2_660004659 != 6 && ele2_660004659 != 7))
  ALORS
    erreur_660004659=affectation_tab_660004265(g_iartout, $Tdpvgsm::IMSI, "777777777777777F")
  SINON
    erreur_660004659=affectation_tab_660004265(g_iartout, $Tdpvgsm::IMSI, "999999999999999F")
  FINSI
FINSI

#T3t7 estalloc
#  Sdate Platine
SI (i_valid_field_n(g_iartin, $TprimsRCSe::srvRequesTime))
ALORS
  erreur_660004659 = i_ajoutChamp(g_iartout, "T3t7", "estalloc", 0x01)
  Request_Time_660004659=i_get_art_field(g_iartin, $TprimsRCSe::srvRequesTime) + 86400
  Request_660004659 = i_DHgetLocalTime(NUMTAB_660004659, 7, Request_Time_660004659)
  erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::estalloc, Request_660004659)
FINSI

#T3t23 Mailldpart
SI (i_valid_field_n(g_iartin, $TprimsRCSe::DialledDigits) && type_cra_660004659 == 0xB1)
ALORS
  longueur_660004659 = i_strlen(pt_Dial_660004659)
  erreur_660004659 = i_resize_tlv(g_iartout,"T3t23","MailIdpart",longueur_660004659)
  erreur_660004659 = i_set_art_str(g_iartout, $Tdpvgsm::MailIdpart, pt_Dial_660004659)
SINON
  SI (i_valid_field_n(g_iartin, $TprimsRCSe::CallPrtAdr2Dat) &&  type_cra_660004659 == 0xB2)
  ALORS
    longueur_660004659 = i_strlen(pt_call_660004659)
    erreur_660004659 = i_resize_tlv(g_iartout,"T3t23","MailIdpart",longueur_660004659)
    erreur_660004659 = i_set_art_str(g_iartout, $Tdpvgsm::MailIdpart, pt_call_660004659)
  FINSI
FINSI

#T2t24 MailMsOrEntity
SI (i_valid_field_n(g_iartin, $TprimsRCSe::CallPrtAdr2Dat) && type_cra_660004659 == 0xB1)
ALORS
  longueur_660004659 = i_strlen(pt_call_660004659)
  erreur_660004659 = i_resize_tlv(g_iartout,"T3t24","MailMsOrEntity",longueur_660004659)
  erreur_660004659 = i_set_art_str(g_iartout, $Tdpvgsm::MailMsOrEntity, pt_call_660004659)
SINON
  SI (i_valid_field_n(g_iartin, $TprimsRCSe::DialledDigits)  &&  type_cra_660004659 == 0xB2)
  ALORS
    longueur_660004659 = i_strlen(pt_Dial_660004659)
    erreur_660004659 = i_resize_tlv(g_iartout,"T3t24","MailMsOrEntity",longueur_660004659)
    erreur_660004659 = i_set_art_str(g_iartout, $Tdpvgsm::MailMsOrEntity, pt_Dial_660004659)
  FINSI
FINSI

#T3t30
#T4t30.1
date_audit_660004659 = i_DHgetLocalTime(NUMTAB_660004659, 7, i_date_audit())
erreur_660004659 = i_set_art_field(g_iartout, $Tdpvgsm::timeInCE, date_audit_660004659)

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

#T3t43 
#T4t43.3 transactionDesc :- :-  :1VAL :ICID

#T3t66
#V4T66.1.1 RecSeqNumber :D  :-  :1VAL :recordSeqNb
#SI (i_valid_field_n(g_iartin, $TprimsRCSe::recordSeqNb))
#ALORS
# erreur=i_set_art_field(g_iartout, $Tdpvgsm::RecSeqNumber, i_get_art_field(g_iartin, $TprimsRCSe::recordSeqNb))
#FINSI

#V4T66.1.2 SigVolum :D  :-  :1VAL :SigVolum
#SI (i_valid_field_n(g_iartin, $TprimsRCSe::SigVolum))
#ALORS
# erreur=i_set_art_field(g_iartout, $Tdpvgsm::SigVolum, i_get_art_field(g_iartin, $TprimsRCSe::SigVolum) )
#FINSI

#V4T66.1.3  ExtBearVolum  :D  :-  :1VAL :ExtBearVolum
#SI (i_valid_field_n(g_iartin, $TprimsRCSe::ExtBearVolum))
#ALORS
# erreur=i_set_art_field(g_iartout, $Tdpvgsm::ExtBearVolum, i_get_art_field(g_iartin, $TprimsRCSe::ExtBearVolum))
#FINSI

#V4T66.1.4 TotalVolum :D  :-  :1VAL :TotalVolum
#SI (i_valid_field_n(g_iartin, $TprimsRCSe::TotalVolum))
#ALORS
# erreur=i_set_art_field(g_iartout, $Tdpvgsm::TotalVolum, i_get_art_field(g_iartin, $TprimsRCSe::TotalVolum))
#FINSI

#V4T66.1.5 CallEndTStamp   :D   :-    :1VAL :callEndTime
# Sdate Platine
SI (i_valid_field_n(g_iartin, $TprimsRCSe::callEndTime))
ALORS
  End_Time_660004659=i_get_art_field(g_iartin, $TprimsRCSe::callEndTime) + 86400
  Date_Fin_660004659 = i_DHgetLocalTime(NUMTAB_660004659, 7, End_Time_660004659)
  erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::CallEndTStamp, Date_Fin_660004659)
FINSI

#V4t66.1.6 CauseRecClose  :D  :-  :1VAL :CausForRecClos
#SI (i_valid_field_n(g_iartin, $TprimsRCSe::CausForRecClos))
#ALORS
# erreur=i_set_art_field(g_iartout, $Tdpvgsm::CauseRecClose, i_get_art_field(g_iartin, $TprimsRCSe::CausForRecClos))
#FINSI

#V4T66.1.7 SessionTerm  :D  :-  :1VAL :sessionTerm
#SI (i_valid_field_n(g_iartin, $TprimsRCSe::sessionTerm))
#ALORS
# erreur = i_set_art_field(g_iartout, $Tdpvgsm::SessionTerm, i_get_art_field(g_iartin, $TprimsRCSe::sessionTerm))
#FINSI

# cas de suppression du champ T4t66.1 .
SI (
  (i_valid_field_n(g_iartin, $TprimsRCSe::recordSeqNb))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::SigVolum))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::ExtBearVolum))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::TotalVolum))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::callEndTime))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::CausForRecClos))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::sessionTerm))
  + (i_valid_field_n(g_iartin, $TprimsRCSe::CORLStatus))
  ) == 0
ALORS
  erreur_660004659 = i_supprChamp(g_iartout, "T4t66.1")
FINSI

#V4T66.1.8 CORLStatus      :D   :-    :MSET :FF
SI (i_valid_field_n(g_iartin, $TprimsRCSe::CORLStatus))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::CORLStatus, pt_CORLStatus_660004659)
  v_CORLStatus_660004659 = CONV_ASCIINUMDEC_INT_660004265(pt_CORLStatus_660004659)
  SI  (v_CORLStatus_660004659 == -1)
  ALORS
    trace ( "[TprimsRCSe DISTR]  -- ERREUR conversion champ CORLStatus---")
  SINON
    erreur_660004659=i_set_art_field(g_iartout, $Tdpvgsm::CORLStatus, v_CORLStatus_660004659)
  FINSI
FINSI

# G3R8 lot3 evolution QC1140
#T4t66.2
#SgsnAddr	:-	:-	:MSET :00 (depend de $TprimsRCSe::SgsnAddr)
# format adresse IPV6 (longueur=16) ou IPV4 (longueur=4) ou DomaineName (chaine ascii sur max 128 octets)
longueur_660004659 = 0
SI (i_valid_field_n(g_iartin, $TprimsRCSe::SgsnAddr))
ALORS
  longueur_660004659 = i_get_art_field(g_iartin, $TprimsRCSe::SgsnAddr -1)
FINSI
SI (longueur_660004659 > 2)
ALORS
	# test longueur pour memcpy
	SI (longueur_660004659 > 16)
	ALORS
		longueur_660004659 = 16
	FINSI
  erreur_660004659 = i_resize_tlv(g_iartout, "T4t66.2", "SgsnAddr", longueur_660004659)
  erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::SgsnAddr, i_get_art_fieldptr(g_iartin, $TprimsRCSe::SgsnAddr), longueur_660004659)
SINON
  erreur_660004659 = i_supprChamp(g_iartout, "T4t66.2")
FINSI

# G3R8 lot3 evolution QC1140
#T4t66.3
#GGSNAddr	:-	:-	:MSET :00 (depend de $TprimsRCSe::ggsnAddr)
# format adresse IPV6 (longueur=16) ou IPV4 (longueur=4) ou DomaineName (chaine ascii sur max 128 octets)
longueur_660004659 = 0
SI (i_valid_field_n(g_iartin, $TprimsRCSe::ggsnAddr))
ALORS
  longueur_660004659 = i_get_art_field(g_iartin, $TprimsRCSe::ggsnAddr -1)
FINSI
SI (longueur_660004659 > 2)
ALORS
	# test longueur pour memcpy
	SI (longueur_660004659 > 16)
	ALORS
		longueur_660004659 = 16
	FINSI
  erreur_660004659 = i_resize_tlv(g_iartout, "T4t66.3", "GGSNAddr", longueur_660004659)
  erreur_660004659 = i_memcpy_art_field_n(g_iartout, $Tdpvgsm::GGSNAddr, i_get_art_fieldptr(g_iartin, $TprimsRCSe::ggsnAddr), longueur_660004659)
SINON
  erreur_660004659 = i_supprChamp(g_iartout, "T4t66.3")
FINSI

#V4t66.4 SubRecordType  :-  :-  :1VAL :SubRecordType
SI (i_valid_field_n(g_iartin, $TprimsRCSe::SubRecordType))
ALORS
  erreur_660004659 = i_get_art_str(g_iartin, $TprimsRCSe::SubRecordType, pt_SubRecordType_660004659)
  erreur_660004659 = i_set_art_str(g_iartout, $Tdpvgsm::SubRecordType, pt_SubRecordType_660004659)
FINSI

#V4t66.5 TransCalledNum :-  :-  :1VAL :CallPartyAdd
#V4t66.6 OriginatingIOI :-  :-  :1VAL :OriginatingIOI
#V4t66.7 TerminatingIOI :-  :-  :1VAL :TerminatingIOI
#V4t66.8 AccessNetInfo  :-  :-  :1VAL :networkInfo
#V4t66.9 SessionId  :-  :-  :1VAL :SessionID
#V4t66.10 NodeIdentifier  :-  :-  :1VAL :CSCFId
#V4t66.11 AppliServerId :-  :-  :1VAL :ASId
#V4t66.12 SIPMethod :-  :-  :1VAL :SIPmethod
#V4t66.13 PrivateUserId :-  :-  :1VAL :PrivateUSID

# cas de suppression champ T3t66
SI (i_get_art_field(g_iartout, $Tdpvgsm::L3t66) == 0)
ALORS
  erreur_660004659 = i_supprChamp(g_iartout, "T3t66")
FINSI

#T3t99
#T4t99.1 GretaTag :-      : :MSET :FF : 1
#T4t99.2 GMSCForwTerm :-      : :MSET :01 : 1
#T4t99.3 FilterNumber :-      : :CSTE :00


#-------------------------------
# Appel fonction aiguillage
#-------------------------------
erreur_660004659 = aiguillage2_660004590 (g_iartin, g_iartout, DISTRIBUTION_SPECIALE_660004659, Multidistribution_Non_660004659)
SI (erreur_660004659 == TRAI_KO_660004659)
ALORS
  trace("<<<__LINE__<<<__FILE__<<< Erreur retour fonction aiguillage2")
  SAUT DISTR_ERR
FINSI
RETOUR TRAIT_OK

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

POINT DISTR_ERR

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

RETOUR TRAIT_OK
#--------------------------------- fin TprimsRCSe_dist.src ---------------------------
