Newer
Older
Import / projects / LGN-IP3870 / t / new / parser.py
import os
import config


class PARSER:

	def __init__(self):

		config.set_identity_record = 0
		config.user_id = None
		config.device_id = None
		config.iface_mac_address = None
		config.iface_ip_address = None
		config.iface_gw_ip_address = None
		config.firmware_version = None
		config.hardware_version = None

		config.set_info_request_record = 0
		config.info_request_command = None
		config.info_request_arg = None

		config.set_info_response_record = 0
		config.info_response_code = 0
		config.info_response_phrase = None
		config.firmware_version_available = None
		config.firmware_files_path = None
		config.firmware_files = []
		config.configuration_file = None

		config.set_firmware_update_request_record = 0
		config.firmware_update_request_arg = None

		config.set_firmware_update_response_record = 0
		config.firmware_update_response_code = 0
		config.firmware_version_available = None
		config.firmware_files_path = None
		config.firmware_files = []

		config.set_config_request_record = 0
		config.config_request_arg = None

		config.set_config_response_record = 0
		config.config_response_code = 0
		config.config_response_phrase = None

		config.set_dns_test_record = 0
		config.primary_dns_server = "0.0.0.0"
		config.secondary_dns_server = "0.0.0.0"

		config.set_outbound_proxy_sip_record = 0
		config.icmp_packets_sent = 0
		config.icmp_packets_received = 0
		config.icmp_packets_lost = 0
		config.roundtrip_time_min = 0
		config.roundtrip_time_max = 0
		config.roundtrip_time_avg = 0

		config.set_sip_register_record = 0
		config.sip_register_messages_sent = 0
		config.sip_register_messages_received = 0

		config.set_firmware_update = 0
		config.download_version = None
		config.download_directory	= None
		config.download_files = []

		config.set_firmware_file_request_record = 0
		config.firmware_file_request_command = "RETR"

		#changed

		config.set_firmware_file_response_record = 0
		config.firmware_file_response_code = []
		config.firmware_update_response_phrase = []
		config.firmware_file_response_crc = []




	def printall(self):
		print config.user_id
		print config.device_id
		print config.firmware_version
		print config.hardware_version
		print config.autoconfig_protocol_version
		print config.l5_protocol_used

		print config.info_request_command
		print config.info_request_arg

		print config.info_response_code
		print config.info_response_phrase

		print config.firmware_version_available
		print config.firmware_files_path
		print config.firmware_files

		print config.configuration_file

		print config.config_request_command
		print config.config_request_arg

		print config.config_response_code
		print config.config_response_phrase

		print config.primary_dns_server
		print config.secondary_dns_server
		print config.outbound_proxy_sip
		print config.outbound_proxy_sip_address

		print config.icmp_packets_sent
		print config.icmp_packets_received
		print config.icmp_packets_lost
		print config.roundtrip_time_min
		print config.roundtrip_time_max
		print config.roundtrip_time_avg

		print config.sip_register_response_code
		print config.sip_register_response_phrase



	def parser_identity_record(self, line):	#identity-record:

		list = []

		list = line.split()

		list = list[1:]

		config.set_identity_record = 1

		for f in list:

			if f.startswith("user-id="):
				config.user_id = f[len("user-id="):]

			elif f.startswith("device-id="):
				config.device_id = f[len("device-id="):]

			elif f.startswith("iface-mac-address="):
				config.iface_mac_address = f[len("iface-mac-address="):]

			elif f.startswith("iface-ip-address="):
				config.iface_ip_address = f[len("iface-ip-address="):]

			elif f.startswith("iface-gw-ip-address="):
				config.iface_gw_ip_address = f[len("iface-gw-ip-address="):]

			elif f.startswith("firmware-version="):
				config.firmware_version = f[len("firmware-version="):]

			elif f.startswith("hardware-version="):
				config.hardware_version= f[len("hardware-version="):]


	def parser_autoconfig_protocol_record(self, line):	#autoconfig-protocol-record:

		list = []

		list = line.split()

		list = list[1:]

		config.set_autoconfig_protocol_record = 1

		for f in list:

			if f.startswith("autoconfig-protocol-version="):
				config.autoconfig_protocol_version = f[len("autoconfig-protocol-version="):]

			elif f.startswith("l5-protocol-used="):
				config.l5_protocol_used = f[len("l5-protocol-used="):]


	def parser_info_request_record(self, line):	#info-request-record:

		list = []

		list = line.split()

		list = list[1:]

		config.set_info_request_record = 1

		for f in list:

			if f.startswith("info-request-command="):
				config.info_request_command = f[len("info-request-command="):]

			elif f.startswith("info-request-arg="):
				config.info_request_arg = f[len("info-request-arg="):]


	def parser_info_response_record(self, line):	#info-response-record:

		list = []

		list = line.split()

		list = list[1:]

		current = None

		config.set_info_response_record = 1

		for f in list:

			if f.startswith("info-response-code="):
				config.info_response_code = f[len("info-response-code="):]
				current = None

			elif f.startswith("info-response-phrase="):
				current = "InfoResponse"
				config.info_response_phrase = f[len("info-response-phrase="):]

			elif f.startswith("firmware-version-available"):
				current = None
				config.firmware_version_available = f[len("firmware-version-available="):]

			elif f.startswith("firmware-files-path="):
				current = None
				config.firmware_files_path = f[len("firmware-files-path="):]

			elif f.startswith("firmware-files="):
				current = "FirmwareFiles"
				config.firmware_files.append(f[len("firmware-files="):])

			elif f.startswith("configuration-file="):
				current = None
				config.configuration_file = f[len("configuration-file="):]

			elif current == "InfoResponse":
				config.info_response_phrase = config.info_response_phrase + ' '+f

			elif current == "FirmwareFiles":
				config.firmware_files.append(f)


	def parser_firmware_update_request_record(self, line):	#firmware_update_request_record

		list = []

		list = line.split()

		list = list[1:]

		config.set_firmware_update_request_record = 1

		for f in list:

			if f.startswith("firmware-update-request-command="):
				config.firmware_update_request_command = f[len("firmware-update-request-command="):]

			elif f.startswith("firmware-update-request-arg="):
				config.firmware_update_request_arg = f[len("firmware-update-request-arg="):]



	def parser_firmware_update_response_record(self, line):	#firmware_update_response_record

		list = []

		list = line.split()

		list = list[1:]

		current = None

		config.set_firmware_update_response_record = 1

		for f in list:


			if f.startswith("firmware-update-response-code="):
				current = None
				config.firmware_update_response_code = f[len("firmware-update-response-code="):]

			elif f.startswith("firmware-update-response-phrase="):
				current = "Response"
				config.firmware_update_response_phrase = f[len("firmware-update-response-phrase="):]

			elif f.startswith("firmware-version-available="):
				current = None
				config.firmware_version_available = f[len("firmware-version-available="):]

			elif f.startswith("firmware-files-path="):
				current = None
				config.firmware_files_path = f[len("firmware-files-path="):]

			elif f.startswith("firmware-files="):
				current = "FirmwareFiles"
				config.firmware_files.append(f[len("firmware-files="):])

			elif current == "Response":
				config.firmware_update_response_phrase = config.firmware_update_response_phrase + ' ' + f

			elif current == "FirmwareFiles":
				config.firmware_files.append(f)



	def parser_config_request_record(self, line):	#config-request-record:

		list = []

		list = line.split()

		list = list[1:]

		config.set_config_request_record = 1

		for f in list:


			if f.startswith("config-request-command="):
				config.config_request_command = f[len("config-request-command="):]

			elif f.startswith("config-request-arg="):
				config.config_request_arg = (f[len("config-request-arg="):])



	def parser_config_response_record(self, line):	#config-response-record:

		list = []

		list = line.split()

		list = list[1:]

		config.set_config_response_record = 1

		for f in list:


			if f.startswith("config-response-code="):
				config.config_response_code = f[len("config-response-code="):]

			elif f.startswith("config-response-phrase="):
				config.config_response_phrase = (f[len("config-response-phrase="):])

			else:
				config.config_response_phrase = config.config_response_phrase + ' '+f



	def parser_dns_test_record(self, line):	#dns-test-record:
		list = []

		list = line.split()

		list = list[1:]

		config.set_dns_test_record = 1
		#print '\neicho)))))))) parser_dns_test_record in parser() ==========='
		#print 'eicho))))))))) is it really necessary? ????????????????????????????'
		
		
		#eicho removes 06.04.26
		#읽지 않고, 세팅된 채 그대로 일단 고 ~!'
		#print '\neicho)))))))) parser_dns_test_record ================'
		for f in list:
			#KA: [20070709] configuration파일 내 정보가 없는 경우 default값으로 0.0.0.0 가져오지 않도록
			'''
			if f.startswith("primary-dns-server="):
				config.primary_dns_server = f[len("primary-dns-server="):]

			elif f.startswith("secondary-dns-server="):
				config.secondary_dns_server = (f[len("secondary-dns-server="):])
			'''
			#KA: [20070709] configuration파일 내 정보가 없는 경우 default값으로 0.0.0.0 가져오지 않도록 ==
			if f.startswith("outbound-proxy-sip="):
				config.outbound_proxy_sip = (f[len("outbound-proxy-sip="):])

			elif f.startswith("outbound-proxy-sip-address="):
				config.outbound_proxy_sip_address = (f[len("outbound-proxy-sip-address="):])
			
			#print 'f (x) = ', f

		#print 'eicho)))))))) end parser!!!===================\n'
			
		#'''

	def parser_outbound_proxy_sip_record(self, line):	#outbound-proxy-sip-record:

		list = []

		list = line.split()

		list = list[1:]

		config.set_outbound_proxy_sip_record = 1

		for f in list:


			if f.startswith("icmp-packets-sent="):
				config.icmp_packets_sent= (f[len("icmp-packets-sent="):])


			elif f.startswith("icmp-packets-received="):
				config.icmp_packets_received = (f[len("icmp-packets-received="):])


			elif f.startswith("icmp-packets-lost"):
				config.icmp_packets_lost = (f[len("icmp-packets-lost="):])


			elif f.startswith("roundtrip-time-min="):
				config.roundtrip_time_min = (f[len("roundtrip-time-min="):])


			elif f.startswith("roundtrip-time-max="):
				config.roundtrip_time_max = (f[len("roundtrip-time-max="):])


			elif f.startswith("roundtrip-time-avg="):
				config.roundtrip_time_avg = (f[len("roundtrip-time-avg="):])



	def parser_sip_register_record(self, line):	#sip-register-record:
		
		# new codes.. elpis 06.06.23
		list = []

		if line.endswith('\n'):
			line = line[:-1]

		list = line.split(": ")

		list = list[1].split(" ")

		for i in range(len(list)):
			if ( not list[i].startswith("sip-register-messages-sent=") and not list[i].startswith("sip-register-messages-received=") and not list[i].startswith("sip-register-response-code=") and not list[i].startswith("sip-register-response-phrase=") ):
				list[i-1] = list[i-1] + " " +  list[i]

		for i in range(len(list)):
			if list[i].startswith("sip-register-messages-sent="):
				config.sip_register_messages_sent = list[i].split('=')[1] 

			elif list[i].startswith("sip-register-messages-received="):
				config.sip_register_messages_received =  list[i].split('=')[1]

			elif list[i].startswith("sip-register-response-code="):
				config.sip_register_response_code =  list[i].split('=')[1]

			elif list[i].startswith("sip-register-response-phrase="):
				config.sip_register_response_phrase = list[i].split('=')[1]




	def parser_firmware_update(self, line): #parser information response

		config.download_files = []

		list = []

		list = line.split()

		list = list[1:]

		config.set_firmware_update = 1

		i=0

		for f in list:

			if i == 0:
				config.download_version = f

			if i == 1:
				config.download_directory = f


			if i > 1:
				config.download_files.append(f)

			i= i + 1

		config.firmware_version_available = config.download_version
		config.firmware_files_path = config.download_directory
		config.firmware_files = config.download_files




	def parser_firmware_file_request_record(self, line): #parser firmware file request record

		list = []

		list = line.split()

		list = list[1:]

		config.set_firmware_file_request_record = 1

		for f in list:

			if f.startswith("firmware-file-request-command="):
				config.firmware_file_request_command = (f[len("firmware-file-request-command="):])

			elif f.startswith("firmware-file-request-arg="):
				config.firmware_file_request_arg.append(f[len("firmware-file-request-arg="):])



	def parser_firmware_file_response_record(self, line): #parser firmware file response record

		list = []

		list = line.split()

		list = list[1:]

		config.set_firmware_file_response_record = 1

		for f in list:

			if f.startswith("firmware-file-response-code="):
				config.firmware_file_response_code  = (f[len("firmware-file-response-code="):])

			elif f.startswith("firmware-update-response-phrase="):
				config.firmware_update_response_phrase  = (f[len("firmware-update-response-phrase="):])

			elif f.startswith("firmware-file-response-crc="):
				config.firmware_file_response_crc.append(f[len("firmware-file-response-crc="):])

			else:
				config.firmware_update_response_phrase = config.firmware_update_response_phrase + ' ' + f


	def write_vdci_cfg(self):

		p = file("vdci.cfg", "r")

		f = file("vdci.bak", "w")

		for line in p:

			if line.startswith("DOMAIN") and config.registration_domain != "":

				f.write("DOMAIN=" + config.registration_domain + '\n')
#MMW
			elif line.startswith("PSTN_DOMAIN") and config.pstn_registration_domain != "":

				f.write("PSTN_DOMAIN=" + config.pstn_registration_domain + '\n')

#end of MMW

			elif line.startswith("EXPIRES") and config.registration_period != 0:
				f.write("EXPIRES=" + str(config.registration_period) + '\n')

			elif line.startswith("PROXY_PORT") and config.outbound_proxy_sip_port != 0:
				f.write("PROXY_PORT=" + str(config.outbound_proxy_sip_port) + '\n')

			elif line.startswith("PROXY_TRANSPORT") and config.outbound_proxy_sip_transport !="":
				f.write("PROXY_TRANSPORT=" + config.outbound_proxy_sip_transport + '\n')

#Roxia Begin jhbang 06.04.07
# eicho 06.05.01
			elif (line.startswith("PROXY_ADDR") or line.startswith("#PROXY_ADDR")) and config.outbound_proxy_sip_fqdn != "":
#Roxia End jhbang
				#f.write("PROXY_ADDR=" + config.outbound_proxy_sip_address + '\n')
				f.write("PROXY_ADDR=" + config.outbound_proxy_sip_fqdn + '\n')
# eicho end.
			elif line.startswith("LOCAL_PORT") and config.sip_local_port != 0:
				f.write("LOCAL_PORT=" + str(config.sip_local_port) + '\n')

			elif line.startswith("AUDIO_PORT") and config.sip_audio_port != 0:
				f.write("AUDIO_PORT=" + str(config.sip_audio_port) + '\n')

			elif line.startswith("VIDEO_PORT") and config.sip_video_port != 0:
				f.write("VIDEO_PORT=" + str(config.sip_video_port) + '\n')

			elif line.startswith("REGISTER_PORT") and	config.sip_register_port !=0:
				f.write("REGISTER_PORT=" + str(config.sip_register_port) + '\n')
#Roxia Begin jhbang 06.04.07
			elif line.startswith("CTBW") or line.startswith("#CTBW"):
				f.write('CTBW=160\n')
#Roxia End jhbang
			else:
				f.write(line)

		p.close()
		f.close()

		os.system("cp vdci.bak vdci.cfg")

# eicho add 06.05.03
	def read_dns_resolv(self):
		import profile
		#if profile.profile.get_profile() == 0:#pstn
		#	return
		
		try:
			firstdns = "0.0.0.0"
			seconddns = "0.0.0.0"

			f = file(config.dns_file, "r")
			#print 'DEBUG)))) read_dns_resolv() ====================='
			for line in f:
				list = line.split()
				if (firstdns == "0.0.0.0") or (firstdns == 'None'):
					firstdns = list[1]
				else:
					seconddns = list[1]
					
			f.close()
			config.primary_dns_server = firstdns
			config.secondary_dns_server = seconddns
		except:
			if config.update_debug:print "get DNS fail"
			

	def write_dns_resolv(self):

		import profile
		if profile.profile.get_profile() == 0:#pstn
			return
		#f = file("/etc/resolv.conf", "w")
		f = file(config.dns_file, "w")

		if (config.primary_dns_server != "None"):
			f.write("nameserver 0.0.0.0\n")
		else :
			f.write("nameserver " + str(config.primary_dns_server) + '\n')
		if(config.secondary_dns_server != "None"):
			f.write("nameserver 0.0.0.0\n")
		else:
			f.write("nameserver " + str(config.secondary_dns_server)  + '\n' )

		'''
		if (config.primary_dns_server != "0.0.0.0"):
			f.write("nameserver " + str(config.primary_dns_server) + '\n')
		if(config.secondary_dns_server != "0.0.0.0"):
			f.write("nameserver " + str(config.secondary_dns_server)  + '\n' )
		'''
		f.close()


# eicho add 06.05.01
	def conv_ipaddress(self, address_str):
	
		import socket

		# gethostbyname blocks, so use it wisely.
		
		try:
			#print 'eicho))) address_str = ', address_str
			self.inetaddr = socket.gethostbyname(address_str)
		except:
			self.inetaddr = '0.0.0.0'
		
		#print 'eicho))) conv_ipaddress. inetaddr = ', self.inetaddr
		return self.inetaddr

	def get_configuration_value(self, tag_str):
		
		if tag_str == 'outbound_proxy_sip' :
			return config.outbound_proxy_sip			
		elif tag_str == 'outbound_proxy_sip_fqdn' :
			return config.outbound_proxy_sip_fqdn
		elif tag_str == 'outbound_proxy_sip_port' :
			return config.outbound_proxy_sip_port
		elif tag_str == 'outbound_proxy_sip_address' :
			return config.outbound_proxy_sip_address
		elif tag_str == 'primary_dns_server' :
			return config.primary_dns_server
		elif tag_str == 'secondary_dns_server' :
			return config.secondary_dns_server
# eicho end.		
		
	def parser_configuration_record(self, line): #parser firmware file response record

		list = []

		list = line.split()

		list = list[1:]

# eicho removes following. 06.05.02
			
		'''
		config.primary_dns_server = "0.0.0.0"
		config.secondary_dns_server = "0.0.0.0"
		config.registration_domain = "telefonica.net"	
		config.registration_period = 3600
		config.outbound_proxy_sip_port = 5070
		config.outbound_proxy_sip_transport ="UDP"
		config.outbound_proxy_sip_address = "81.47.224.4"
		config.sip_local_port = 5060
		config.sip_audio_port = 23000
		config.sip_video_port = 24000
		config.sip_register_port = 5060
		'''
		
		if config.update_debug:
			print '\n> parser_configuration_record ================'

		for f in list:
			
			if f.startswith("primary-dns-server"):
				config.primary_dns_server  = (f[len("primary-dns-server="):])

			elif f.startswith("secondary-dns-server="):
				config.secondary_dns_server  = (f[len("secondary-dns-server="):])

			#실제로는 들어오지 않는 부분
			elif f.startswith("outbound-proxy-sip="):
				#config.outbound_proxy_sip  = (f[len("outbound-proxy-sip="):])
				config.outbound_proxy_sip_fqdn = (f[len("outbound-proxy-sip-address="):])
				
			# 이 부분으로 대체.
			elif f.startswith("outbound-proxy-sip-address="):
				config.outbound_proxy_sip_fqdn = (f[len("outbound-proxy-sip-address="):])
				config.outbound_proxy_sip_address  = self.conv_ipaddress(config.outbound_proxy_sip_fqdn)
				
			elif f.startswith("outbound-proxy-sip-port="):
				config.outbound_proxy_sip_port  = (f[len("outbound-proxy-sip-port="):])

			elif f.startswith("outbound-proxy-sip-transport="):
				config.outbound_proxy_sip_transport  = (f[len("outbound-proxy-sip-transport="):])

			elif f.startswith("registration-domain="):
				config.registration_domain  = (f[len("registration-domain="):])
#MMW
			elif f.startswith("pstn-registration-domain="):
				config.pstn_registration_domain  = (f[len("pstn-registration-domain="):])
#endif	//end of MMW


			elif f.startswith("registration-period="):
				config.registration_period = (f[len("registration-period="):])

			elif f.startswith("sip-local-port="):
				config.sip_local_port = (f[len("sip-local-port="):])

			elif f.startswith("sip-audio-port="):
				config.sip_audio_port = (f[len("sip-audio-port="):])

			elif f.startswith("sip-video-port="):
				config.sip_video_port = (f[len("sip-video-port="):])


			elif f.startswith("sip-register-port="):
				config.sip_register_port = (f[len("sip-register-port="):])

			elif f.startswith("ntp-server="):

				f2 = file("/usr/local/lgvp/ntp.cfg","w")
				f2.write("ntp-server="+str(f[len("ntp-server="):])+'\n')
				f2.close
		
		config.outbound_proxy_sip  = config.outbound_proxy_sip_fqdn + ":" + config.outbound_proxy_sip_port	
					# eicho)) 06.05.03
		self.write_vdci_cfg()	# CAUTION!!! config in parser.py is different to config.py on running.

		#if(config.primary_dns_server != "0.0.0.0"  or config.secondary_dns_server != "0.0.0.0"):
		#self.write_dns_resolv()
		self.read_dns_resolv()	# read dns info. from /usr/etc/ppp/resolv.conf 
			
		if config.update_debug:
			print 'config.primary_dns_server = ', config.primary_dns_server
			print 'config.outbound_proxy_sip=', config.outbound_proxy_sip
			print 'config.outbound_proxy_sip_fqdn =',config.outbound_proxy_sip_fqdn 
			print 'config.outbound_proxy_sip_port=',config.outbound_proxy_sip_port
			print 'config.outbound_proxy_sip_address=',config.outbound_proxy_sip_address
			

	
	def write_identity_record(self, f):

		f.write("identity-record: ")

		if config.user_id:
			f.write("user-id=" + str(config.user_id) + ' ')
		else:
			f.write("user-id= ")


#change by elpis to correct wording mistake
		#if config.device_id:
		#	f.write("device-id=" + config.device_id +'.'+config.vendor_id + ' ')
		#else:
		#	f.write("device-id= ")

		if config.device_id:
			f.write("voip-device-id=" + config.device_id +'.'+config.vendor_id + ' ')
		else:
			f.write("voip-device-id= ")

		if config.iface_mac_address:
			f.write("iface-mac-address="+ config.iface_mac_address + ' ')
		else:
			f.write("iface-mac-address= ")

#chang wording by elpis 061124
#		if config.iface_ip_address:
#			f.write("iface-ip-address="+ config.iface_ip_address + ' ')
#		else:
#			f.write("iface-ip-address= ")

# change wording phrases again by eicho. 06.12.01
#
#		if config.iface_ip_address:
#			f.write("iface-ipaddress="+ config.iface_ip_address + ' ')
#		else:
#			f.write("iface-ipaddress= ")

		if config.iface_ip_address:
			f.write("iface-ip-address="+ config.iface_ip_address + ' ')
		else:
			f.write("iface-ip-address= ")


		if config.iface_gw_ip_address:
			f.write("iface-gw-ip-address="+ config.iface_gw_ip_address + ' ')
		else:
			f.write("iface-gw-ip-address= ")

		if config.firmware_version:

			f.write("firmware-version=" + config.firmware_version + ' ')
		else:
			f.write("firmware-version= ")

		if config.hardware_version:
			f.write("hardware-version=" + config.hardware_version + '\n')
		else:
			f.write("hardware-version= \n")


	def write_autoconfig_protocol_record(self, f):
		f.write("autoconfig-protocol-record: ")

		if config.autoconfig_protocol_version:
			f.write("autoconfig-protocol-version=" + config.autoconfig_protocol_version + ' ')
		else:
			f.write("autoconfig-protocol-version= ")


#change by elpis to correct wording mistake

#		if config.l5_protocol_used :
#			f.write("l5-protocol-used=" + config.l5_protocol_used + '\n')
#		else:
#			f.write("l5-protocol-used= \n")
			
		if config.l5_protocol_used :
#			f.write("protocol-used=" +"\"" +config.l5_protocol_used +"\""+ '\n') //changed by elpis 20061115
			f.write("protocol-used=" +"\'" +config.l5_protocol_used +"\'"+ '\n')
		else:
#			f.write("protocol-used=\"\" \n") //changed by elpis 20061115
			f.write("protocol-used=\'\' \n")



	def write_info_request_record(self, f):
		f.write("info-request-record: ")

		if config.info_request_command:
			f.write("info-request-command=" + config.info_request_command + ' ')
		else:
			f.write("info-request-command= ")

		if config.info_request_arg:
			f.write("info-request-arg=" + config.info_request_arg + '\n')
		else:
			f.write("info-request-arg= \n")


	def write_info_response_record(self, f):
		f.write("info-response-record: ")

		f.write("info-response-code=")
		f.write(str(config.info_response_code))
		f.write(' ')

		if config.info_response_phrase:
			f.write("info-response-phrase=" + config.info_response_phrase + ' ')
		else:
			f.write("info-response-phrase= ")

		if config.firmware_version_available:
			f.write("firmware-version-available=" + config.firmware_version_available + ' ')
		else:
			f.write("firmware-version-available= ")

		if config.firmware_files_path:
			f.write("firmware-files-path=" + config.firmware_files_path + ' ')
		else:
			f.write("firmware-files-path= ")

		if config.firmware_files:
			f.write("firmware-files=")

			for name in config.firmware_files:
				f.write(name + ' ')
		else:
			f.write("firmware-files= ")

		if config.configuration_file:
			f.write("configuration-file=" + config.configuration_file + '\n')
		else:
			f.write("configuration-file= \n")


	def write_firmware_update_request_record(self, f):

		f.write("firmware-update-request-record: ")

#change by elpis to correct wording mistake
#		if config.firmware_update_request_command:
#			f.write("firmware-update-request-command=" + config.firmware_update_request_command + ' ')
#		else:
#			f.write("firmware-update-request-command= ")


		if config.firmware_update_request_command:

#			f.write("firmware-update-request-command=" + "\"" + config.firmware_update_request_command + "\"" + ' ') //changed by elpis 20061115
			f.write("firmware-update-request-command=" + "\'" + config.firmware_update_request_command + "\'" + ' ')
			
		else:
#			f.write("firmware-update-request-command=\"\" ") //changed by elpis 20061115
			f.write("firmware-update-request-command=\'\' ")


		f.write("firmware-update-request-arg=%s/%s/FirmwareUpdateRequest.acfg" % (config.hardware_version, config.firmware_version))

#		if config.firmware_update_request_arg:
#			f.write("firmware-update-request-arg=" + config.firmware_update_request_arg)
#		else:
#			f.write("firmware-update-request-arg= ")
#
		f.write('\n')


	def write_firmware_update_response_record(self, f):

		f.write("firmware-update-response-record: ")

		f.write("firmware-update-response-code=")
		f.write(str(config.firmware_update_response_code))
		f.write(' ')


#change by elpis to correct wording mistake
#		if config.firmware_update_response_phrase:
#			f.write("firmware-update-response-phrase=" + config.firmware_update_response_phrase[0] + ' ')
#		else:
#			f.write("firmware-update-response-phrase= ")


#changed by elpis to correct report format
#		if config.firmware_update_response_phrase:
#			f.write("firmware-update-response-code-phrase=" + config.firmware_update_response_code_phrase + ' ')
#		else:
##			f.write("firmware-update-response-code-phrase= \"\" ") //changed by elpis 20061115
#			f.write("firmware-update-response-code-phrase= \'\' ")
#changed by elpis by SPEC
		if config.firmware_update_response_code_phrase:
			f.write("firmware-update-response-code-phrase=" + config.firmware_update_response_code_phrase + ' ')
		else:
			f.write("firmware-update-response-code-phrase= \'\' ")



		if config.firmware_version_available:
			f.write("firmware-version-available=" + config.firmware_version_available + ' ')
		else:
			f.write("firmware-version-available= ")

		if config.firmware_files_path:
			f.write("firmware-files-path=" + config.firmware_files_path + ' ')
		else:
			f.write("firmware-files-path= ")

		if config.firmware_files:
			f.write("firmware-files=")
			for name in config.firmware_files:
				f.write(name + ' ')
		else:
			f.write("firmware-files= ")

		f.write("\n")


	def write_config_request_record(self, f):
		f.write("config-request-record: ")

#change by elpis to correct wording mistake
#		if config.config_request_command:
#			f.write("config-request-command=" + config.config_request_command + ' ')
#		else:
#			f.write("config-request-command= ")

		if config.config_request_command:
#			f.write("config-request-command=" + "\"" + config.config_request_command  + "\"" + ' ') //changed by elpis 20061115
			f.write("config-request-command=" + "\'" + config.config_request_command  + "\'" + ' ')
		else:
#			f.write("config-request-command=\"\" ") //changed by elpis 20061115
			f.write("config-request-command=\'\' ")

		if config.config_request_arg:
			f.write("config-request-arg=" + config.config_request_arg + '\n')
		else:
		#changed by elpis
			#f.write("config-request-arg= \n")
			f.write("config-request-arg=%s/%s/ConfigurationRequest.acfg \n" % (config.hardware_version, config.firmware_version))


	def write_config_response_record(self, f):
		f.write("config-response-record: ")

		f.write("config-response-code=")
		f.write(str(config.config_response_code))
		f.write(' ')

		if config.config_response_phrase:
			f.write("config-response-phrase=" + config.config_response_phrase + '\n')
		else:
#			f.write("config-response-phrase= \n") //changed by elpis 20061115
			f.write("config-response-phrase= \'\'\n")


	def write_dns_test_record(self, f):
		# eicho add debug : 06.04.26
		if config.update_debug:
			print 'Parser:  write_dns_test_record( ) -- file is ', f.name

			print 'config.primary_dns_server = ', config.primary_dns_server
			print 'config.outbound_proxy_sip=', config.outbound_proxy_sip
			print 'config.outbound_proxy_sip_fqdn =',config.outbound_proxy_sip_fqdn 
			print 'config.outbound_proxy_sip_port=',config.outbound_proxy_sip_port
			print 'config.outbound_proxy_sip_address=',config.outbound_proxy_sip_address
			

			
		f.write("dns-test-record: ")

		if config.primary_dns_server:
			f.write("primary-dns-server=" + config.primary_dns_server + ' ')
		else:
			f.write("primary-dns-server= ")

		if config.secondary_dns_server:
			f.write("secondary-dns-server=" + config.secondary_dns_server + ' ')
		else:
			f.write("secondary-dns-server= ")

		if config.outbound_proxy_sip:
			f.write("outbound-proxy-sip=" + config.outbound_proxy_sip + ' ')
		else:
			f.write("outbound-proxy-sip= ")

#change by elpis to correct wording mistake
#		if config.outbound_proxy_sip_address:
#			f.write("outbound-proxy-sip-address=" + config.outbound_proxy_sip_address + '\n')
#		else:
#			f.write("outbound-proxy-sip-address= \n")

		if config.outbound_proxy_sip_address:
			f.write("outbound-proxy-sip-ipaddress=" + config.outbound_proxy_sip_address + '\n')
		else:
			f.write("outbound-proxy-sip-ipaddress= \n")


	def write_outbound_proxy_sip_record(self, f):

		print config.icmp_packets_sent
		print config.icmp_packets_received
		print config.icmp_packets_lost
		print config.roundtrip_time_min
		print config.roundtrip_time_max
		print config.roundtrip_time_avg
		
		f.write("outbound-proxy-sip-test-record: ")
		f.write("icmp-packets-sent=" + str(config.icmp_packets_sent) + ' ')
		f.write("icmp-packets-received=" + str(config.icmp_packets_received) + ' ')

#change by elpis to correct wording mistake
#		f.write("icmp-packets-lost=" + str(config.icmp_packets_lost) + ' ')
#		f.write("icmp-echo-packets-lost=" + str(config.icmp_packets_lost) + ' ') #changed by elpis by spec
		f.write("icmp-packets-lost=" + str(config.icmp_packets_lost) + ' ')
		
		f.write("roundtrip-time-min=" + str(config.roundtrip_time_min) + ' ')
		f.write("roundtrip-time-max=" + str(config.roundtrip_time_max) + ' ')
		f.write("roundtrip-time-avg=" + str(config.roundtrip_time_avg) + '\n')

	def write_sip_register_record_send_acfg(self, f):
		# eicho add debug : 06.04.26
		if config.update_debug:
			print 'Parser:  write_sip_register_record_send_acfg()'
			
		import status
		if ( status.stat_reg_receive_count !=0):

			f.write("sip-register-test-record: ")
			f.write("sip-register-messages-sent=" + str(status.stat_reg_send_count) + " ")
			f.write("sip-register-messages-received=" + str(status.stat_reg_receive_count) + ' ')
			f.write("sip-register-response-code=" + str(status.stat_reg_last_result) + ' ')
			if status.stat_reg_last_desc:
			    	f.write("sip-register-response-phrase=" +   status.stat_reg_last_desc + '\n')
			else:
#			    	f.write("sip-register-response-phrase= \n")//changed by elpis 20061115
			    	f.write("sip-register-response-phrase=\'\'\n")


	def write_sip_register_record(self, f):
		# eicho add debug : 06.04.26
		if config.update_debug:
			print 'Parser:  write_sip_register_record()'
			
		if (int(config.sip_register_messages_received) !=0):

			f.write("sip-register-test-record: ")
			f.write("sip-register-messages-sent=" + str(config.sip_register_messages_sent) + " ")
			f.write("sip-register-messages-received=" + str(config.sip_register_messages_received) + ' ')
			f.write("sip-register-response-code=" + str(config.sip_register_response_code) + ' ')

			if config.sip_register_response_phrase:
#			    	f.write("sip-register-response-phrase=" +  "\"" +  config.sip_register_response_phrase +  "\"" + '\n') //changed by elpis 20061115
			    	f.write("sip-register-response-phrase=" +  "\'" +  config.sip_register_response_phrase +  "\'" + '\n')

			else:
#			    	f.write("sip-register-response-phrase= \n") //changed by elpis 20061115
			    	f.write("sip-register-response-phrase=\'\'\n") 

		else:

			f.write("sip-register-test-record: ")
			f.write("sip-register-messages-sent=" + str(config.sip_register_messages_sent) + " ")
			f.write("sip-register-messages-received=0 ")
			f.write("sip-register-response-code=0 ")
#		    	f.write("sip-register-response-phrase=\"\"\n") //changed by elpis 20061115
		    	f.write("sip-register-response-phrase=\'\'\n") 
		    	

	def write_firmware_file_request_record(self, f, index):

#change by elpis to correct wording mistake
#		if config.firmware_file_request_command:
#			f.write("firmware-file-request-record: ")
#			f.write("firmware-file-request-command=" +  config.firmware_file_request_command + ' ')
#		else:
#			f.write("firmware-file-request-command= ")

		if config.firmware_file_request_command:
			f.write("firmware-file-request-record: ")
#			f.write("firmware-file-request-command=" +  "\"" +  config.firmware_file_request_command +  "\"" + ' ')
			f.write("firmware-file-request-command=" +  "\'" +  config.firmware_file_request_command +  "\'" + ' ')
		else:
#			f.write("firmware-file-request-command=\"\" ")
			f.write("firmware-file-request-command=\'\' ")


		if config.firmware_file_request_arg[index]:
			f.write("firmware-file-request-arg=" + config.firmware_file_request_arg[index] + '\n')
		else:
			f.write("firmware-file-request-arg= \n")


	def write_firmware_file_response_record(self, f, index):


		f.write("firmware-file-response-record: ")
		f.write("firmware-file-response-code=")
		f.write(config.firmware_file_response_code[index])
		f.write(' ')

#change by elpis to correct wording mistake
#		if config.firmware_update_response_phrase[index]:
#			f.write("firmware-update-response-phrase=" +  config.firmware_update_response_phrase[index] + ' ')
#		else:
#			f.write("firmware-update-response-phrase= ")

#		if config.firmware_update_response_phrase[index]:
#			f.write("firmware-update-response-code-phrase=" +  config.firmware_update_response_phrase[index] + ' ')
#		else:
#			f.write("firmware-update-response-code-phrase= ")

#change by elpis, SPEC
		if config.firmware_update_response_phrase[index]:
			f.write("firmware-file-response-phrase=" +  config.firmware_update_response_phrase[index] + ' ')
		else:
			f.write("firmware-file-response-phrase= ")



		if config.firmware_file_response_crc[index]:
			f.write("firmware-file-response-crc=" + config.firmware_file_response_crc[index] + '\n')
		else:
			f.write("firmware-file-response-crc= \n")

	def parser(self, line):

		if config.update_debug:
			print 'parser) line is -------------------------------------'
			print line
			print 'parser) END    -------------------------------------'
		
		if line.startswith("identity-record:"):

			self.parser_identity_record(line)

		elif line.startswith("autoconfig-protocol-record:"):
			self.parser_autoconfig_protocol_record(line)

		elif line.startswith("info-request-record:"):
			self.parser_info_request_record(line)

		elif line.startswith("info-response-record:"):
			self.parser_info_response_record(line)

		elif line.startswith("firmware-update-request-record:"):
			self.parser_firmware_update_request_record(line)

		elif line.startswith("firmware-update-response-record:"):
			self.parser_firmware_update_response_record(line)

		elif line.startswith("config-request-record:"):
			self.parser_config_request_record(line)

		elif line.startswith("config-response-record:"):
			self.parser_config_response_record(line)

		elif line.startswith("dns-test-record:"):
			self.parser_dns_test_record(line)

		elif line.startswith("outbound-proxy-sip-test-record:"):
			self.parser_outbound_proxy_sip_record(line)

		elif line.startswith("sip-register-test-record:"):
			self.parser_sip_register_record(line)

		elif line.startswith("firmware-update:"):
			self.parser_firmware_update(line)

		elif line.startswith("firmware-file-request-record:"):
			self.parser_firmware_file_request_record(line)

		elif line.startswith("firmware-file-response-record:"):
			self.parser_firmware_file_response_record(line)

		elif line.startswith(	"configuration-record:"):
			self.parser_configuration_record(line)
#Roxia Begin smyook 06.06.23
	def outbound_proxy_test(self):
		'''
		pid = os.fork()

		if pid:

			pid,status = os.wait()

			if status == 0:
				infile = file("/tmp/outbound_proxy_test" , "r")
				for line in infile:
					if line.endswith("packet loss\n"):
						temp_packet = line.split(", ")
						config.icmp_packets_sent = temp_packet[0].split(" ")[0]
						config.icmp_packets_received = temp_packet[1].split(" ")[0]
						config.icmp_packets_lost = int(config.icmp_packets_sent) - int(config.icmp_packets_received)
					if line.startswith("round-trip"):
						temp_packet = line[:-4].split(" = ")
						config.roundtrip_time_min = temp_packet[1].split('/')[0]
						config.roundtrip_time_avg = temp_packet[1].split('/')[1]
						config.roundtrip_time_max = temp_packet[1].split('/')[2]
			else:
				print "ping execute error"

		else:
			os.system("ping -c 5 %s > /tmp/outbound_proxy_test" % config.outbound_proxy_sip_fqdn)
		'''
		os.system("ping -c 5 %s > /tmp/outbound_proxy_test" % config.outbound_proxy_sip_fqdn)

		#add the case of no response from server
		config.icmp_packets_sent = 5
		config.icmp_packets_received = 0
		config.icmp_packets_lost = 5
		config.roundtrip_time_min = 0
		config.roundtrip_time_avg = 0
		config.roundtrip_time_max = 0

		
		infile = file("/tmp/outbound_proxy_test" , "r")
		for line in infile:
			if line.endswith("packet loss\n"):
				temp_packet = line.split(", ")
				config.icmp_packets_sent = temp_packet[0].split(" ")[0]
				config.icmp_packets_received = temp_packet[1].split(" ")[0]
				config.icmp_packets_lost = int(config.icmp_packets_sent) - int(config.icmp_packets_received)
			if line.startswith("round-trip"):
				temp_packet = line[:-4].split(" = ")
				config.roundtrip_time_min = temp_packet[1].split('/')[0]
				config.roundtrip_time_avg = temp_packet[1].split('/')[1]
				config.roundtrip_time_max = temp_packet[1].split('/')[2]
#Roxia End smyook