func TestParseTransferComplete(t *testing.T) {

	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
	    <SOAP-ENV:Header>
	        <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.TransferComplete1439547139.1439547139028717609</cwmp:ID>
	    </SOAP-ENV:Header>
	    <SOAP-ENV:Body>
	        <cwmp:TransferComplete>
	            <CommandKey>abc</CommandKey>
	            <StartTime>2015-02-12T13:40:07</StartTime>
	            <CompleteTime>2015-02-12T13:40:07</CompleteTime>
	            <FaultStruct>
	                <FaultCode>1</FaultCode>
	                <FaultString>error</FaultString>
	            </FaultStruct>
	        </cwmp:TransferComplete>
	    </SOAP-ENV:Body>
	</SOAP-ENV:Envelope>`

	msg, _ := messages.ParseXML([]byte(data))
	resp := msg.(*messages.TransferComplete)
	fmt.Println(resp.CommandKey)
	fmt.Println(resp.StartTime)
	fmt.Println(resp.CompleteTime)
	fmt.Println(resp.FaultCode)
	fmt.Println(resp.FaultString)
}
func TestParseGetParameterValuesResponse(t *testing.T) {
	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
	      <SOAP-ENV:Header>
	          <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.GetParameterValuesResponse1439545078.1439545078160785199</cwmp:ID>
	      </SOAP-ENV:Header>
	      <SOAP-ENV:Body>
	          <cwmp:GetParameterValuesResponse>
	              <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[2]">
	                  <ParameterValueStruct>
	                      <Name xsi:type="xsd:string">InternetGatewayDevice.DeviceInfo.Manufacturer</Name>
	                      <Value xsi:type="xsd:string">ACS</Value>
	                  </ParameterValueStruct>
	                  <ParameterValueStruct>
	                      <Name xsi:type="xsd:string">InternetGatewayDevice.DeviceInfo.OUI</Name>
	                      <Value xsi:type="xsd:string">0011AB</Value>
	                  </ParameterValueStruct>
	              </ParameterList>
	          </cwmp:GetParameterValuesResponse>
	      </SOAP-ENV:Body>
	  </SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	resp := msg.(*messages.GetParameterValuesResponse)
	for k, v := range resp.Values {
		fmt.Println(k, v)
	}
}
Example #3
0
func TestParseRebootResponse(t *testing.T) {
	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
<SOAP-ENV:Header>
<cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.Reboot1439974339781.14572016</cwmp:ID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<cwmp:RebootResponse></cwmp:RebootResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	fmt.Println(msg)
	//resp := msg.(*messages.RebootResponse)
}
func TestParseDownloadResponse(t *testing.T) {
	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
	      <SOAP-ENV:Header>
	          <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.DownloadResponse1439551393.1439551393594569717</cwmp:ID>
	      </SOAP-ENV:Header>
	      <SOAP-ENV:Body>
	          <cwmp:DownloadResponse>
	              <StartTime>2015-02-12T13:40:07</StartTime>
	              <CompleteTime>2015-02-12T13:40:07</CompleteTime>
	              <Status>1</Status>
	          </cwmp:DownloadResponse>
	      </SOAP-ENV:Body>
	  </SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	resp := msg.(*messages.DownloadResponse)
	fmt.Println(resp.Status)
	fmt.Println(resp.StartTime)
	fmt.Println(resp.CompleteTime)
}
func TestParseSetParameterValuesResponse(t *testing.T) {

	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
	      <SOAP-ENV:Header>
	          <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.SetParameterValuesResponse1439546279.1439546279630058749</cwmp:ID>
	      </SOAP-ENV:Header>
	      <SOAP-ENV:Body>
	          <cwmp:SetParameterValuesResponse>
	              <Status>1</Status>
	              <ParameterKey>test</ParameterKey>
	          </cwmp:SetParameterValuesResponse>
	      </SOAP-ENV:Body>
	  </SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	resp := msg.(*messages.SetParameterValuesResponse)
	fmt.Println(resp.Status)
	fmt.Println(resp.ParameterKey)

}
func TestParseGetRPCMethodsResponse(t *testing.T) {
	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
	      <SOAP-ENV:Header>
	          <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.GetRPCMethodsResponse1439556667.1439556667543994313</cwmp:ID>
	      </SOAP-ENV:Header>
	      <SOAP-ENV:Body>
	          <cwmp:GetRPCMethodsResponse>
	              <cwmp:MethodList xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[2]">
	                  <string>GetRPCMethods</string>
	                  <string>GetParameterNames</string>
	              </cwmp:MethodList>
	          </cwmp:GetRPCMethodsResponse>
	      </SOAP-ENV:Body>
	  </SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	resp := msg.(*messages.GetRPCMethodsResponse)
	for _, v := range resp.Methods {
		fmt.Println(v)
	}
}
Example #7
0
func TestParseFault(t *testing.T) {
	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
	       xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
	       xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
	       xmlns:xsd="http://www.w3.org/1999/XMLSchema"
	       xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
	       <SOAP-ENV:Header>
	       <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.SetParameterValues1458897112421.1852997967</cwmp:ID>
	       </SOAP-ENV:Header>
	       <SOAP-ENV:Body>
	       <SOAP-ENV:Fault>
	       <faultcode>Client</faultcode>
	       <faultstring>Client fault</faultstring>
	       <detail>
	       <cwmp:Fault>
	       <FaultCode>9003</FaultCode>
	       <FaultString>Invalid arguments</FaultString>
	       <SetParameterValuesFault>
	       <ParameterName>InternetGatewayDevice.config.webauthglobal.successUrl</ParameterName>
	       <FaultCode>9008</FaultCode>
	       <FaultString>Attempt to set a non-writable parameter</FaultString>
	       <ParameterKey>006aecb92b10459b91321e32c9b4502f</ParameterKey>
	       </SetParameterValuesFault>
	       </cwmp:Fault>
	       </detail>
	       </SOAP-ENV:Fault>
	       </SOAP-ENV:Body>
	       </SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	fault := msg.(*messages.Fault)
	fmt.Println(fault.FaultCode)
	fmt.Println(fault.FaultString)
	fmt.Println(fault.CwmpFaultCode)
	fmt.Println(fault.CwmpFaultString)
	fmt.Println(fault.SetParameterValuesFault.FaultCode)
	fmt.Println(fault.SetParameterValuesFault.FaultString)
	fmt.Println(fault.SetParameterValuesFault.ParameterName)
	fmt.Println(fault.SetParameterValuesFault.ParameterKey)
}
Example #8
0
func TestParseInform(t *testing.T) {
	/*
			data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">
		      <SOAP-ENV:Header>
		          <cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.Inform958064891.1658176487</cwmp:ID>
		          <cwmp:NoMoreRequests>0</cwmp:NoMoreRequests>
		      </SOAP-ENV:Header>
		      <SOAP-ENV:Body>
		          <cwmp:Inform>
		              <DeviceId xsi:type="cwmp:DeviceIdStruct">
		                  <Manufacturer xsi:type="xsd:string">ACS</Manufacturer>
		                  <OUI xsi:type="xsd:string">OO11AB</OUI>
		                  <ProductClass xsi:type="xsd:string">it-man</ProductClass>
		                  <SerialNumber xsi:type="xsd:string">1456789</SerialNumber>
		              </DeviceId>
		              <Event SOAP-ENC:arrayType="cwmp:EventStruct[1]">
		                  <EventStruct>
		                      <EventCode xsi:type="xsd:string">2 PERIODIC</EventCode>
		                      <CommandKey></CommandKey>
		                  </EventStruct>
		              </Event>
		              <MaxEnvelopes xsi:type="xsd:unsignedInt">0</MaxEnvelopes>
		              <CurrentTime xsi:type="xsd:string">2015-01-21T14:46:07</CurrentTime>
		              <RetryCount xsi:type="xsd:unsignedInt">0</RetryCount>
		              <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[11]">
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>
		                      <Value xsi:type="string">it-man</Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.ManagementServer.URL</Name>
		                      <Value xsi:type="string"></Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.ManagementServer.Password</Name>
		                      <Value xsi:type="string"></Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>
		                      <Value xsi:type="string">http://192.168.16.68:5400</Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.DeviceSummary</Name>
		                      <Value xsi:type="string"></Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.DeviceInfo.SpecVersion</Name>
		                      <Value xsi:type="string">V1.0</Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.ManagementServer.UDPConnectionRequestAddress</Name>
		                      <Value xsi:type="string">200.200.202.68:1036</Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.ManagementServer.ConnectionRequestPassword</Name>
		                      <Value xsi:type="string"></Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>
		                      <Value xsi:type="string">it-man.bin-150120</Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name>
		                      <Value xsi:type="string">192.168.16.68</Value>
		                  </ParameterValueStruct>
		                  <ParameterValueStruct>
		                      <Name xsi:type="string">InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>
		                      <Value xsi:type="string">V1.0</Value>
		                  </ParameterValueStruct>
		              </ParameterList>
		          </cwmp:Inform>
		      </SOAP-ENV:Body>
		  </SOAP-ENV:Envelope>`
	*/
	data := `<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"><SOAP-ENV:Header><cwmp:ID SOAP-ENV:mustUnderstand="1">ID:intrnl.unset.id.Inform958064891.1658176487</cwmp:ID><cwmp:NoMoreRequests>0</cwmp:NoMoreRequests></SOAP-ENV:Header><SOAP-ENV:Body><cwmp:Inform><DeviceId xsi:type="cwmp:DeviceIdStruct"><Manufacturer xsi:type="xsd:string">ACS</Manufacturer><OUI xsi:type="xsd:string">OO11AB</OUI><ProductClass xsi:type="xsd:string">it-man</ProductClass><SerialNumber xsi:type="xsd:string">1450330</SerialNumber></DeviceId><Event SOAP-ENC:arrayType="cwmp:EventStruct[1]"><EventStruct><EventCode xsi:type="xsd:string">2 PERIODIC</EventCode><CommandKey></CommandKey></EventStruct></Event><MaxEnvelopes xsi:type="xsd:unsignedInt">0</MaxEnvelopes><CurrentTime xsi:type="xsd:string">2015-01-21T14:46:07</CurrentTime><RetryCount xsi:type="xsd:unsignedInt">0</RetryCount><ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[11]"><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name><Value xsi:type="string">it-man</Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.ManagementServer.URL</Name><Value xsi:type="string"></Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.ManagementServer.Password</Name><Value xsi:type="string"></Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name><Value xsi:type="string">http://192.168.16.68:5400</Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.DeviceSummary</Name><Value xsi:type="string"></Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.DeviceInfo.SpecVersion</Name><Value xsi:type="string">V1.0</Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.ManagementServer.UDPConnectionRequestAddress</Name><Value xsi:type="string">200.200.202.68:1036</Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.ManagementServer.ConnectionRequestPassword</Name><Value xsi:type="string"></Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name><Value xsi:type="string">it-man.bin-150120</Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress</Name><Value xsi:type="string">192.168.16.68</Value></ParameterValueStruct><ParameterValueStruct><Name xsi:type="string">InternetGatewayDevice.DeviceInfo.HardwareVersion</Name><Value xsi:type="string">V1.0</Value></ParameterValueStruct></ParameterList></cwmp:Inform></SOAP-ENV:Body></SOAP-ENV:Envelope>`
	msg, _ := messages.ParseXML([]byte(data))
	inform := msg.(*messages.Inform)
	fmt.Println(inform.Manufacturer)
	fmt.Println(inform.OUI)
	fmt.Println(inform.Sn)
	fmt.Println(inform.ProductClass)
	fmt.Println(inform.ID)
	fmt.Println(inform.Name)
	fmt.Println("curTime", inform.CurrentTime)

	for k, v := range inform.Events {
		fmt.Println(k, v)
	}

	for k, v := range inform.Params {
		fmt.Println(k, v)
	}

}
Example #9
0
func tr069(w http.ResponseWriter, r *http.Request) {
	var requestBody []byte
	var err error
	if r.Method == "POST" {
		// receive posted data
		requestBody, err = ioutil.ReadAll(r.Body)
		if err != nil {
			log.Warn("tr069 read body error(%v)", err)
		}
	}

	var response []byte
	cpeSentEmptyReq := true
	var sn string
	if len(requestBody) > 0 {
		cpeSentEmptyReq = false
		msg, err := messages.ParseXML(requestBody)
		if err == nil {
			switch msg.GetName() {
			case "Inform":
				curInform := msg.(*messages.Inform)
				sn = curInform.Sn
				globalSessions.Put(w, r, sn)
				//response
				resp := new(messages.InformResponse)
				resp.MaxEnvelopes = maxEnvelopes
				response = resp.CreateXML()
				if curInform.IsEvent(messages.EventPeriodic) {
					//TODO
					//sync device info
				} else if curInform.IsEvent(messages.EventValueChange) {
					//TODO
					//sync config
				}
			case "TransferComplete":
				tc := msg.(*messages.TransferComplete)
				resp := new(messages.TransferCompleteResponse)
				resp.ID = tc.ID
				//TODO
				//rpc reply
				response = resp.CreateXML()
			case "GetRPCMethods":
				gm := msg.(*messages.GetRPCMethods)
				resp := new(messages.GetRPCMethodsResponse)
				resp.ID = gm.ID
				response = resp.CreateXML()
			default:
				//rpc reply
				//read replyto and send reponse msg to mq
				//TODO
				//根据sessionid读取replytTo,corrID,session需要保证replyTo的一致性,不是每条消息都有replyTo
				session := globalSessions.Get(w, r)
				if session != nil {
					//sn := session.SN
					if len(session.ReplyTo) > 0 {
						//send rpc reply
						sendRPCResponse(msg, session.ReplyTo, session.CorrelationID)
					}
					//has msg anymore
					var channel *Channel
					if channel = DefaultBucket.Channel(session.SN); channel != nil {
						//read msg
						var msg *Message
						var err error
						if msg, err = channel.SvrProto.Get(); err != nil {
							// must be empty error
							err = nil
							session.ReplyTo = ""
							session.CorrelationID = ""
						} else {
							// just forward the message
							if Debug {
								log.Debug("channel msg:", string(msg.Body))
							}
							m := FromMessage(*msg)
							session.ReplyTo = msg.ReplyTo
							session.CorrelationID = msg.CorrelationID
							response = m.CreateXML()
							channel.SvrProto.GetAdv() //读计算器累加
						}
					} else {
						session.ReplyTo = ""
						session.CorrelationID = ""
					}
				}

			}
		}
	}

	if cpeSentEmptyReq {
		session := globalSessions.Get(w, r)
		if session != nil {
			//根据sn取消息
			var channel *Channel
			if channel = DefaultBucket.Channel(session.SN); channel != nil {
				//read msg
				var msg *Message
				var err error
				if msg, err = channel.SvrProto.Get(); err != nil {
					// must be empty error
					err = nil
					session.ReplyTo = ""
					session.CorrelationID = ""
				} else {
					// just forward the message
					if Debug {
						log.Debug("channel msg:", string(msg.Body))
					}
					m := FromMessage(*msg)
					session.ReplyTo = msg.ReplyTo
					session.CorrelationID = msg.CorrelationID
					response = m.CreateXML()
					channel.SvrProto.GetAdv() //读计算器累加
				}
			} else {
				session.ReplyTo = ""
				session.CorrelationID = ""
			}
		}
	}
	//write response
	w.Header().Add("Content-Type", "application/xml; charset=utf-8")
	w.Header().Set("Content-Length", strconv.Itoa(len(response)))
	w.Write(response)
}