void irq_handler_init(struct irq_handler* irqh, enum irq_status (*func)(unsigned char, struct irq_handler*)) { list_init_item(&irqh->irqh); irqh->func = func; }
int ipc_msg_init(struct ipc_msg *msg, struct tcb *snd, unsigned long flags, unsigned long msg0, unsigned long msg1) { list_init_item(&msg->rcv_q); msg->snd= snd; msg->flags = flags&~IPC_MSG_FLAGS_RESERVED; msg->msg0 = msg0; msg->msg1 = msg1; return 0; }
/** Send raw bytes to the XMPP server. * This function is a convenience function to send raw bytes to the * XMPP server. It is usedly primarly by xmpp_send_raw_string. This * function should be used with care as it does not validate the bytes and * invalid data may result in stream termination by the XMPP server. * * @param conn a Strophe connection object * @param data a buffer of raw bytes * @param len the length of the data in the buffer */ void xmpp_send_raw(xmpp_conn_t * const conn, const char * const data, const size_t len) { xmpp_ctx_t *ctx; xmpp_send_queue_t *sq; list_t *item; if (conn->state != XMPP_STATE_CONNECTED) return; ctx = conn->ctx; /* create send queue item for queue */ sq = xmpp_alloc(ctx, sizeof(xmpp_send_queue_t)); if (!sq) return; sq->data = xmpp_alloc(ctx, len); if (!sq->data) goto out_free_sq; item = list_init_item(ctx); if (!item) goto out_free_data; memcpy(sq->data, data, len); sq->len = len; sq->written = 0; item->data = (void *)sq; /* add item to the send queue */ list_push(conn->send_queue, item); /* unlock send_queue_thread */ xmpp_sem_post(ctx->send_queue_sem); return; out_free_data: xmpp_free(ctx, sq->data); out_free_sq: xmpp_free(ctx, sq); }
/** Create a new Strophe connection object. * * @param ctx a Strophe context object * * @return a Strophe connection object or NULL on an error * * @ingroup Connections */ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx) { xmpp_conn_t *conn; list_t *item; if (!ctx) return NULL; conn = xmpp_alloc(ctx, sizeof(xmpp_conn_t)); if (!conn) return NULL; conn->ctx = ctx; conn->type = XMPP_UNKNOWN; conn->state = XMPP_STATE_DISCONNECTED; conn->sock = -1; conn->tls = NULL; conn->timeout_stamp = 0; conn->error = 0; conn->stream_error = NULL; /* default send parameters */ conn->blocking_send = 0; conn->send_queue_max = DEFAULT_SEND_QUEUE_MAX; conn->send_queue = list_init(ctx); if (!conn->send_queue) goto out_free_conn; /* default timeouts */ conn->connect_timeout = CONNECT_TIMEOUT; conn->lang = xmpp_strdup(ctx, "en"); if (!conn->lang) goto out_free_send_queue; conn->domain = NULL; conn->jid = NULL; conn->pass = NULL; conn->stream_id = NULL; conn->bound_jid = NULL; conn->tls_support = 0; conn->tls_disabled = 0; conn->tls_failed = 0; conn->sasl_support = 0; conn->secured = 0; conn->bind_required = 0; conn->session_required = 0; conn->parser = parser_new(ctx, _handle_stream_start, _handle_stream_end, _handle_stream_stanza, conn); if (!conn->parser) goto out_free_lang; conn->reset_parser = 0; conn_prepare_reset(conn, auth_handle_open); conn->authenticated = 0; conn->conn_handler = NULL; conn->userdata = NULL; /* we own (and will free) the hash values */ conn->id_handlers = hash_new(ctx, 32, NULL); conn->timed_handlers = list_init(ctx); if (!conn->timed_handlers) goto out_free_parser; conn->handlers = list_init(ctx); if (!conn->handlers) goto out_free_timed_handlers; /* give the caller a reference to connection */ conn->ref = 1; /* add connection to ctx->connlist */ item = list_init_item(ctx); if (!item) goto out_free_handlers; else { item->data = (void *)conn; list_push(ctx->connlist, item); } return conn; out_free_handlers: list_destroy(conn->handlers); out_free_timed_handlers: list_destroy(conn->timed_handlers); out_free_parser: parser_free(conn->parser); out_free_lang: xmpp_free(ctx, conn->lang); out_free_send_queue: list_destroy(conn->send_queue); out_free_conn: xmpp_free(ctx, conn); return NULL; }