Esempio n. 1
0
func get_ticket(socket zmq.Socket, login string, credential string) string {
	msg_uuid := uuid.UUID4()

	var msg string
	msg = "{\n\"@\" : \"msg:M" + msg_uuid + "\", \n\"a\" : \"msg:Message\",\n\"msg:sender\" : \"ext_pacahon_test\",\n\"msg:reciever\" : \"pacahon\",\n" + "\"msg:command\" : \"get_ticket\",\n" + "\"msg:args\" :\n" + "{\n" + "  \"auth:login\" : \"" + login + "\",\n  \"auth:credential\" : \"" + credential + "\"\n}\n}"

	//socket.Send([]byte(msg), 0)
	//res, err := socket.Recv(0)
	res, err := send_and_recieve(socket, []byte(msg), "---")
	if res == nil {
		fmt.Println(err)
	}

	out_msg := string(res)

	var auth__ticket string
	auth__ticket = "auth:ticket"

	pos := strings.Index(out_msg, auth__ticket)

	if pos > 0 {
		out_msg = out_msg[pos+len(auth__ticket)+1 : len(out_msg)]
		start_pos := strings.Index(out_msg, "\"")
		out_msg = out_msg[start_pos+1 : len(out_msg)]
		end_pos := strings.Index(out_msg, "\"")
		out_msg = out_msg[0:end_pos]

		println("get ticket: ", out_msg)
		return out_msg
	}

	return "0000"
}
Esempio n. 2
0
func ggg(c chan *IOElement, point string, compare_result string) {

	context, _ := zmq.NewContext()
	socket, _ := context.NewSocket(zmq.REQ)
	sock_uuid := uuid.UUID4()
	socket.SetSockOptString(zmq.IDENTITY, sock_uuid)
	socket.Connect(point)
	println("sock_uuid: ", sock_uuid)

	ticket := get_ticket(socket, "user", "9cXsvbvu8=")

	fmt.Println("ggg is waiting...")
	time.Sleep(5 * 1e9)

	fmt.Println("ggg read chanel")

	for {
		io_el := <-c

		if io_el == nil {
			continue
		}

		msg_in_et := io_el.in_msg
		msg_out_et := io_el.out_msg

		var f interface{}
		err := json.Unmarshal([]byte(msg_in_et), &f)
		if err != nil {
			fmt.Println("err! unmarshal msg_in_et:", err)
			fmt.Println(string(msg_in_et))
			return
		}

		m := f.(map[string]interface{})

		m["msg:ticket"] = ticket

		jsn_msg, err := json.Marshal(f)
		if err != nil {
			fmt.Println(err)
		}

		if jsn_msg != nil {

			msg_out_cmp, err := send_and_recieve(socket, jsn_msg, sock_uuid)

			if compare_result == "Y" {
				if msg_out_cmp == nil {
					fmt.Println(err)
				}

				var msg_out_et_array []byte
				var bb []byte

				if msg_out_cmp[0] != '[' {
					bb = make([]byte, len(msg_out_cmp)+2)
					bb[0] = '['
					copy(bb[1:len(msg_out_cmp)+1], msg_out_cmp)
					bb[len(msg_out_cmp)+1] = ']'
					msg_out_cmp = bb
				}

				if msg_out_et[0] != '[' {
					bb = make([]byte, len(msg_out_et)+2)
					bb[0] = '['
					copy(bb[1:len(msg_out_et)+1], msg_out_et)
					bb[len(msg_out_et)+1] = ']'
					msg_out_et_array = bb
				} else {
					msg_out_et_array = []byte(msg_out_et)
				}

				//fmt.Println("len=", len (msg_out_et_array));

				var jsn_out_et []interface{}
				err = json.Unmarshal(msg_out_et_array, &jsn_out_et)
				if err != nil {
					fmt.Println("err! unmarshal out_et:", err)
					fmt.Println(msg_out_et)
					return
				}

				var jsn_out_cmp []interface{}
				err = json.Unmarshal(msg_out_cmp, &jsn_out_cmp)
				if err != nil {
					fmt.Println("err! unmarshal out_cmp:", err)
					fmt.Println(string(bb))
					return
				}

				res, _ := cmp_msg_out("", jsn_out_et, "", jsn_out_cmp, 0, false)

				if res == false {
					fmt.Println("msg out_et != out ")

					//					cmp_msg_out("", jsn_out_et, "", jsn_out_cmp, 0, true)

					fout_et, err := os.OpenFile("ou_et", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
					if err != nil {
						fmt.Fprintf(os.Stderr, " %s\n", err)
						return
					}
					fout_et.WriteString(msg_out_et)
					fout_et.Close()

					fout_cmp, err := os.OpenFile("ou_cmp", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
					if err != nil {
						fmt.Fprintf(os.Stderr, " %s\n", err)
						return
					}
					fout_cmp.Write(msg_out_cmp)
					fout_cmp.Close()

					fout_in, err := os.OpenFile("in_et", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
					if err != nil {
						fmt.Fprintf(os.Stderr, " %s\n", err)
						return
					}
					fout_in.WriteString("[]\n")
					fout_in.WriteString("INPUT\n")
					fout_in.WriteString(msg_in_et)
					fout_in.WriteString("[]\n")
					fout_in.WriteString("OUTPUT\n")
					fout_in.WriteString(msg_out_et)
					fout_in.Close()

					os.Exit(1)
				}

			}
		}

	}

}
Esempio n. 3
0
/*
	Generate a clientId for use in the communication with the client
*/
func generateClientId() string {
	return uuid.UUID4()
}