Mercurial > hg
comparison mcabber/src/jabglue.c @ 298:35cda94e570d
Add /connect and /disconnect commands
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 10 Jul 2005 15:38:45 +0100 |
parents | 871e53769084 |
children | 12f919be3da5 |
comparison
equal
deleted
inserted
replaced
297:9bdfef4f4735 | 298:35cda94e570d |
---|---|
38 | 38 |
39 jconn jc; | 39 jconn jc; |
40 time_t LastPingTime; | 40 time_t LastPingTime; |
41 unsigned int KeepaliveDelay; | 41 unsigned int KeepaliveDelay; |
42 static unsigned int prio; | 42 static unsigned int prio; |
43 static int s_id = 1; // FIXME which use?? | 43 static int s_id; |
44 static int regmode, regdone; | 44 static int regmode, regdone; |
45 static enum imstatus mystatus = offline; | 45 static enum imstatus mystatus = offline; |
46 unsigned char online; | 46 unsigned char online; |
47 | 47 |
48 char imstatus2char[imstatus_size] = { | 48 char imstatus2char[imstatus_size] = { |
115 *ptr = 0; | 115 *ptr = 0; |
116 } | 116 } |
117 return alias; | 117 return alias; |
118 } | 118 } |
119 | 119 |
120 char *compose_jid(const char *username, const char *servername, | |
121 const char *resource) | |
122 { | |
123 char *jid = g_new(char, | |
124 strlen(username)+strlen(servername)+strlen(resource)+3); | |
125 strcpy(jid, username); | |
126 strcat(jid, "@"); | |
127 strcat(jid, servername); | |
128 strcat(jid, "/"); | |
129 strcat(jid, resource); | |
130 return jid; | |
131 } | |
132 | |
120 jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass) | 133 jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass) |
121 { | 134 { |
122 if (!port) { | 135 if (!port) { |
123 if (ssl) | 136 if (ssl) |
124 port = JABBERSSLPORT; | 137 port = JABBERSSLPORT; |
125 else | 138 else |
126 port = JABBERPORT; | 139 port = JABBERPORT; |
127 } | 140 } |
128 | 141 |
129 if (jc) | 142 //if (jc) |
130 free(jc); | 143 // free(jc); XXX |
131 | 144 |
145 s_id = 1; | |
132 jc = jab_new((char*)jid, (char*)pass, port, ssl); | 146 jc = jab_new((char*)jid, (char*)pass, port, ssl); |
133 | 147 |
148 /* These 3 functions can deal with a NULL jc, no worry... */ | |
134 jab_logger(jc, file_logger); | 149 jab_logger(jc, file_logger); |
135 jab_packet_handler(jc, &packethandler); | 150 jab_packet_handler(jc, &packethandler); |
136 jab_state_handler(jc, &statehandler); | 151 jab_state_handler(jc, &statehandler); |
137 | 152 |
138 if (jc->user) { | 153 if (jc && jc->user) { |
139 online = TRUE; | 154 online = TRUE; |
140 jstate = STATE_CONNECTING; | 155 jstate = STATE_CONNECTING; |
141 statehandler(0, -1); | 156 statehandler(0, -1); |
142 jab_start(jc); | 157 jab_start(jc); |
143 } | 158 } |
145 return jc; | 160 return jc; |
146 } | 161 } |
147 | 162 |
148 void jb_disconnect(void) | 163 void jb_disconnect(void) |
149 { | 164 { |
165 if (!jc) return; | |
166 | |
150 statehandler(jc, JCONN_STATE_OFF); | 167 statehandler(jc, JCONN_STATE_OFF); |
168 jab_delete(jc); | |
169 //free(jc); XXX | |
170 jc = NULL; | |
151 } | 171 } |
152 | 172 |
153 inline void jb_reset_keepalive() | 173 inline void jb_reset_keepalive() |
154 { | 174 { |
155 time(&LastPingTime); | 175 time(&LastPingTime); |