summaryrefslogtreecommitdiff
path: root/meta-openvuplus/recipes-vuplus/enigma2/enigma2/enigma2_vuplus_transcodingsetup_xinetd.patch
blob: 77044d1b8d5535326cb763c7d736a72f75f20798 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
diff --git a/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py b/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py
index 09ec093..f73da01 100755
--- a/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py
+++ b/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py
@@ -7,7 +7,7 @@ from Components.Sources.StaticText import StaticText
 from Plugins.Plugin import PluginDescriptor
 from Tools.Directories import fileExists
 from enigma import eTimer
-from os import system as os_system
+from os import system as os_system, popen as os_popen
 from __init__ import _
 
 config.plugins.transcodingsetup = ConfigSubsection()
@@ -15,13 +15,17 @@ config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disable
 config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
 
 error_msg ={
-	-1 : "File not exist - /proc/stb/encoder/enable.",
-	-2 : "File not exist - /etc/inetd.conf.",
-	-3 : "File open error - /proc/stb/encoder/enable.",
-	-4 : "File open error - /etc/inetd.conf.",
-	-5 : "Set encoder error.",
-	-6 : "Set port error.",
-	-7 : "Setting value is incorrect."
+	-1 : "File not exist - /proc/stb/encoder/enable",
+	-2 : "File not exist - /etc/inetd.conf",
+	-3 : "File open error - /proc/stb/encoder/enable",
+	-4 : "File open error - /etc/inetd.conf",
+	-5 : "Set encoder error",
+	-6 : "Set port error",
+	-7 : "Setting value is incorrect",
+	-8 : "File not exist - /etc/xinetd.d/streamproxy",
+	-9 : "File not exist - /etc/xinetd.d/transtreamproxy",
+	-10 : "File open error - /etc/xinetd.d/streamproxy",
+	-11 : "File open error - /etc/xinetd.d/transtreamproxy",
 }
 class TranscodingSetupInit:
 	def __init__(self):
@@ -44,8 +48,6 @@ class TranscodingSetupInit:
 			return -7
 		if not fileExists("/proc/stb/encoder/enable"):
 			return -1
-		elif not fileExists("/etc/inetd.conf"):
-			return -2
 		if self.setEncoder(transcoding) < 0:
 			return -5
 		res = self.setPort(port)
@@ -53,11 +55,11 @@ class TranscodingSetupInit:
 			self.setEncoder(self.transcoding_old)
 			return res
 		else:
-			self.inetdRestart()
+			self.restartDaemon()
 		return res
 
 	def setEncoder(self,mode = "disabled"):
-		print "<TranscodingSetup> set encoder : %s" % mode
+#		print "<TranscodingSetup> set encoder : %s" % mode
 		mode = mode.strip(' ').strip('\n')
 		try:
 			fd = open("/proc/stb/encoder/enable",'r')
@@ -78,14 +80,29 @@ class TranscodingSetupInit:
 #			print "setEncoder exception error"
 			return -1
 
+	def isXinetd(self):
+		ps_xinetd = os_popen('ps -ef | grep xinetd | grep -v grep').read()
+		if ps_xinetd.strip() == '':
+			return False
+		else:
+			return True
+
 	def setPort(self, port = "8001"):
-		print "<TranscodingSetup> set port : %s" % port
+#		print "<TranscodingSetup> set port : %s" % port
+		if self.isXinetd():
+			res = self.setPort_xinetd(port)
+		else:
+			res = self.setPort_inetd(port)
+		return res
+
+	def setPort_inetd(self, port = "8001"):
+		if not fileExists("/etc/inetd.conf"):
+			return -2
 		try:
 			fp = file('/etc/inetd.conf', 'r')
 			datas = fp.readlines()
 			fp.close()
 		except:
-#			print "file open error, inetd.conf!"
 			return -4
 		try:
 			newdatas=""
@@ -112,9 +129,65 @@ class TranscodingSetupInit:
 			return -6
 		return 0
 
-	def inetdRestart(self):
-		if fileExists("/etc/init.d/inetd"):
-			os_system("/etc/init.d/inetd restart")
+	def setPort_xinetd(self, port = "8001"):
+		if not fileExists("/etc/xinetd.d/streamproxy") :
+			return -8
+		if  not fileExists("/etc/xinetd.d/transtreamproxy"):
+			return -9
+
+		try:
+			fp_s = file('/etc/xinetd.d/streamproxy')
+			data_s = fp_s.readlines()
+			fp_s.close()
+		except:
+			return -10
+
+		try:
+			fp_t = file('/etc/xinetd.d/transtreamproxy')
+			data_t = fp_t.readlines()
+			fp_t.close()
+		except:
+			return -11
+# fix xinetd port
+		try:
+			if port == "8001":
+				port_s = "8002"
+				port_t = "8001"
+			else:
+				port_s = "8001"
+				port_t = "8002"
+
+			newdata_s=""
+			for line in data_s:
+				if line.find("port") != -1:
+					line = "\tport = %s\n"%port_s
+				newdata_s+=line
+
+			newdata_t=""
+			for line in data_t:
+				if line.find("port") != -1:
+					line = "\tport = %s\n"%port_t
+				newdata_t+=line
+
+			fd = file("/etc/xinetd.d/streamproxy",'w')
+			fd.write(newdata_s)
+			fd.close()
+
+			fd = file("/etc/xinetd.d/transtreamproxy",'w')
+			fd.write(newdata_t)
+			fd.close()
+
+		except:
+			return -6
+		return 0
+
+	def restartDaemon(self):
+		if self.isXinetd():
+			if fileExists("/etc/init.d/xinetd"):
+				os_system("/etc/init.d/xinetd restart")
+		else:		
+			if fileExists("/etc/init.d/inetd"):
+				os_system("/etc/init.d/inetd restart")
 
 	def getModel(self):
 		if fileExists("/proc/stb/info/vumodel"):
@@ -182,12 +255,12 @@ class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
 	def keySave(self):
 		transcoding = config.plugins.transcodingsetup.transcoding.value
 		port = config.plugins.transcodingsetup.port.value
-		print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
+#		print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
 		ret = self.setupTranscoding(transcoding, port)
 		if ret is not None and ret <0 :
 			self.resetConfig()
 			global error_msg
-			self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
+			self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s.\n(%s)")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
 		else:
 			self.saveAll()
 			if transcoding == "enabled" and port == "8001" :