Set a unique default resource

The default resource is "xmppipe". A subsequent xmppipe using the default
resource connects to the groupchat will be disconnected.

* reduce the amount of configuration needed for scripts
* make the resource unique on the same host by appending the PID
master
Michael Santos 2 years ago
parent 20b987ce21
commit 2df5896df2

@ -92,7 +92,7 @@ int main(int argc, char **argv) {
state->sm_fc = 15;
state->sm_unacked = 5;
state->room = xmppipe_roomname("stdout");
state->resource = xmppipe_strdup(XMPPIPE_RESOURCE);
state->resource = xmppipe_resource();
state->opt |= XMPPIPE_OPT_GROUPCHAT;
jid = xmppipe_getenv("XMPPIPE_USERNAME");

@ -137,6 +137,7 @@ char *xmppipe_fmt_decode(const char *);
char *xmppipe_nfmt_decode(const char *, size_t);
int xmppipe_set_nonblock(int fd);
char *xmppipe_resource(void);
char *xmppipe_servername(char *);
char *xmppipe_roomname(char *);
char *xmppipe_conference(char *, char *);
@ -170,7 +171,3 @@ void xmppipe_stanza_add_child(xmpp_stanza_t *, xmpp_stanza_t *);
int restrict_process_init(xmppipe_state_t *state);
int restrict_process_stdin(xmppipe_state_t *state);
int xmppipe_conn_fd(xmppipe_state_t *state);
int b64_ntop(u_char const *src, size_t srclength, char *target,
size_t targsize);
int b64_pton(char const *src, u_char *target, size_t targsize);

@ -216,6 +216,15 @@ char *xmppipe_servername(char *jid) {
return q;
}
char *xmppipe_resource() {
size_t len = sizeof(XMPPIPE_RESOURCE) + 1 + 10 + 1;
char *buf = xmppipe_malloc(len);
(void)snprintf(buf, len, "%s.%d", XMPPIPE_RESOURCE, getpid());
return buf;
}
char *xmppipe_conference(char *room, char *mucservice) {
size_t len = strlen(room) + 1 + strlen(mucservice) + 1;
char *buf = xmppipe_malloc(len);

Loading…
Cancel
Save