<commit_before>package gojabber

import (
	"net"
	"io"
	"os"
	"crypto/tls"
	"crypto/sha1"
	"encoding/base64"
)

/**************************************************************
 * CONSTANTS
 **************************************************************/
const (
	State_Auth1 = iota
	State_Auth2
	State_Auth3
	State_Connected
)

/**************************************************************
 * TYPES
 **************************************************************/
type JabberCon struct {
	//public
	JID          string
	JidToContact map[string]*Contact
	NameToJid    map[string]string
	Host         string
	//private
	user_cmd  chan string
	user_resp chan string
	net_in    chan string
	net_out   chan string
	cleanup   func()
	//callbacks
	callBackVCard  func(host string, avatar AvatarUpdate)
	callBackMsg    func(host string, msg MessageUpdate)
	callBackTyping func(host string, JID string)
	callBackStatus func(host string, JID string, status string)
}

/**************************************************************
 * EXPORTED - CLIENT CALLBACK REGISTRATION 
 **************************************************************/
func (jcon *JabberCon) ConnectHook_AvatarUpdate(onVCardUpdate func(host string, avatar AvatarUpdate)) {
	jcon.callBackVCard = onVCardUpdate
}

func (jcon *JabberCon) ConnectHook_Msg(onMsg func(host string, msg MessageUpdate)) {
	jcon.callBackMsg = onMsg
}

func (jcon *JabberCon) ConnectHook_Typing(onTyping func(host string, JID string)) {
	jcon.callBackTyping = onTyping
}

func (jcon *JabberCon) ConnectHook_Status(onStatus func(host string, JID string, status string)) {
	jcon.callBackStatus = onStatus
}

/**************************************************************
 * EXPORTED - CLIENT COMMANDS
 **************************************************************/
func (jcon *JabberCon) Disconnect() {
	jcon.cleanup()
}

func (jcon *JabberCon) SendMessage(msg string, contact *Contact, fromJID string) {
	sendMessage(jcon.net_out, msg, contact, fromJID)
}

/**
 * Create a network connection to XMPP server, authenticate, request roster, and broadcast initial presence
 */
func SpawnConnection(host string, domain string, username string, password string, port string, useTLS bool) (*JabberCon, os.Error) {
	var jcon JabberCon
	var err os.Error
	var state int = State_Auth1
	//requiring cleanup
	var con net.Conn

	//open socket

	switch useTLS {
	case true:
		con, err = tls.Dial("tcp", "", host+":"+port)
	case false:
		con, err = net.Dial("tcp", "", host+":"+port)
	}

	if err != nil {
		logVerbose("Connection to %s Failed", host+":"+port)
		return nil, err
	} else {
		logVerbose("Connection to %s Created", host+":"+port)
	}

	//kick off read/write threads
	jcon.net_out = startNetWriter(con)
	jcon.net_in = startNetReader(con)
	jcon.user_cmd = make(chan string, 10)
	jcon.user_resp = make(chan string)
	jcon.NameToJid = make(map[string]string)
	jcon.JidToContact = make(map[string]*Contact)
	jcon.Host = host<commit_msg>fix for go release 12/08/10<commit_after>package gojabber

import (
	"net"
	"io"
	"os"
	"crypto/tls"
	"crypto/sha1"
	"encoding/base64"
)

/**************************************************************
 * CONSTANTS
 **************************************************************/
const (
	State_Auth1 = iota
	State_Auth2
	State_Auth3
	State_Connected
)

/**************************************************************
 * TYPES
 **************************************************************/
type JabberCon struct {
	//public
	JID          string
	JidToContact map[string]*Contact
	NameToJid    map[string]string
	Host         string
	//private
	user_cmd  chan string
	user_resp chan string
	net_in    chan string
	net_out   chan string
	cleanup   func()
	//callbacks
	callBackVCard  func(host string, avatar AvatarUpdate)
	callBackMsg    func(host string, msg MessageUpdate)
	callBackTyping func(host string, JID string)
	callBackStatus func(host string, JID string, status string)
}

/**************************************************************
 * EXPORTED - CLIENT CALLBACK REGISTRATION 
 **************************************************************/
func (jcon *JabberCon) ConnectHook_AvatarUpdate(onVCardUpdate func(host string, avatar AvatarUpdate)) {
	jcon.callBackVCard = onVCardUpdate
}

func (jcon *JabberCon) ConnectHook_Msg(onMsg func(host string, msg MessageUpdate)) {
	jcon.callBackMsg = onMsg
}

func (jcon *JabberCon) ConnectHook_Typing(onTyping func(host string, JID string)) {
	jcon.callBackTyping = onTyping
}

func (jcon *JabberCon) ConnectHook_Status(onStatus func(host string, JID string, status string)) {
	jcon.callBackStatus = onStatus
}

/**************************************************************
 * EXPORTED - CLIENT COMMANDS
 **************************************************************/
func (jcon *JabberCon) Disconnect() {
	jcon.cleanup()
}

func (jcon *JabberCon) SendMessage(msg string, contact *Contact, fromJID string) {
	sendMessage(jcon.net_out, msg, contact, fromJID)
}

/**
 * Create a network connection to XMPP server, authenticate, request roster, and broadcast initial presence
 */
func SpawnConnection(host string, domain string, username string, password string, port string, useTLS bool) (*JabberCon, os.Error) {
	var jcon JabberCon
	var err os.Error
	var state int = State_Auth1
	//requiring cleanup
	var con net.Conn

	//open socket

	switch useTLS {
	case true:
		con, err = tls.Dial("tcp", "", host+":"+port, nil)
	case false:
		con, err = net.Dial("tcp", "", host+":"+port)
	}

	if err != nil {
		logVerbose("Connection to %s Failed", host+":"+port)
		return nil, err
	} else {
		logVerbose("Connection to %s Created", host+":"+port)
	}

	//kick off read/write threads
	jcon.net_out = startNetWriter(con)
	jcon.net_in = startNetReader(con)
	jcon.user_cmd = make(chan string, 10)
	jcon.user_resp = make(chan string)
	jcon.NameToJid = make(map[string]string)
	jcon.JidToContact = make(map[string]*Contact)
	jcon.Host = host
{'fraction_non_alphanumeric': 0.25769036812909735, 'fraction_numerical': 0.004034291477559254, 'mean_word_length': 5.453362255965293, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6502218', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1858, 'n_words': 468}