/** Start an async exchange on the loc session. * * @param iface Location service interface to choose * * @return New exchange. * */ async_exch_t *loc_exchange_begin(loc_interface_t iface) { switch (iface) { case LOC_PORT_SUPPLIER: fibril_mutex_lock(&loc_supplier_mutex); if (loc_supplier_sess == NULL) loc_supplier_sess = service_connect(EXCHANGE_SERIALIZE, SERVICE_LOC, LOC_PORT_SUPPLIER, 0); fibril_mutex_unlock(&loc_supplier_mutex); if (loc_supplier_sess == NULL) return NULL; return async_exchange_begin(loc_supplier_sess); case LOC_PORT_CONSUMER: fibril_mutex_lock(&loc_consumer_mutex); if (loc_consumer_sess == NULL) loc_consumer_sess = service_connect(EXCHANGE_SERIALIZE, SERVICE_LOC, LOC_PORT_CONSUMER, 0); fibril_mutex_unlock(&loc_consumer_mutex); if (loc_consumer_sess == NULL) return NULL; return async_exchange_begin(loc_consumer_sess); default: return NULL; } }
papi_status_t papiPrinterListJobs(papi_service_t handle, char *name, char **requested_attrs, int type_mask, int max_num_jobs, papi_job_t **jobs) { papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; void *iter = NULL; if ((svc == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, name)) != PAPI_OK) return (result); ipp_initialize_request(svc, &request, OPID_GET_JOBS); ipp_initialize_operational_attributes(svc, &op, name, -1); if (requested_attrs != NULL) { int i; for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; for (status = papiAttributeListGetCollection(response, &iter, "job-attributes-group", &op); status == PAPI_OK; status = papiAttributeListGetCollection(response, &iter, NULL, &op)) { job_t *j = NULL; if ((j = calloc(1, sizeof (*j))) == NULL) return (PAPI_TEMPORARY_ERROR); copy_attributes(&j->attributes, op); op = NULL; list_append(jobs, j); } papiAttributeListFree(response); return (result); }
papi_status_t papiPrintersList(papi_service_t handle, char **requested_attrs, papi_filter_t *filter, papi_printer_t **printers) { papi_status_t status, result = PAPI_INTERNAL_ERROR; service_t *svc = handle; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; void *iter = NULL; if ((svc == NULL) || (printers == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, DEFAULT_DEST)) != PAPI_OK) return (result); ipp_initialize_request(svc, &request, OPID_CUPS_GET_PRINTERS); ipp_initialize_operational_attributes(svc, &op, NULL, -1); if (requested_attrs != NULL) { int i; for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; for (status = papiAttributeListGetCollection(response, &iter, "printer-attributes-group", &op); status == PAPI_OK; status = papiAttributeListGetCollection(response, &iter, NULL, &op)) { printer_t *p = NULL; if ((p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); copy_attributes(&p->attributes, op); op = NULL; list_append(printers, p); } papiAttributeListFree(response); return (result); }
async_sess_t *loc_service_connect(exch_mgmt_t mgmt, service_id_t handle, unsigned int flags) { async_sess_t *sess; if (flags & IPC_FLAG_BLOCKING) sess = service_connect_blocking(mgmt, SERVICE_LOC, LOC_CONNECT_TO_SERVICE, handle); else sess = service_connect(mgmt, SERVICE_LOC, LOC_CONNECT_TO_SERVICE, handle); return sess; }
papi_status_t papiPrinterQuery(papi_service_t handle, char *name, char **requested_attrs, papi_attribute_t **job_attributes, papi_printer_t *printer) { papi_status_t result = PAPI_INTERNAL_ERROR; service_t *svc = handle; printer_t *p = NULL; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; if ((svc == NULL) || (name == NULL) || (printer == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, name)) != PAPI_OK) return (result); if ((*printer = p = calloc(1, sizeof (*p))) == NULL) return (PAPI_TEMPORARY_ERROR); ipp_initialize_request(svc, &request, OPID_GET_PRINTER_ATTRIBUTES); ipp_initialize_operational_attributes(svc, &op, name, -1); if (requested_attrs != NULL) { int i; for (i = 0; requested_attrs[i] != NULL; i++) papiAttributeListAddString(&op, PAPI_ATTR_APPEND, "requested-attributes", requested_attrs[i]); } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); op = NULL; papiAttributeListGetCollection(response, NULL, "printer-attributes-group", &op); copy_attributes(&p->attributes, op); papiAttributeListFree(response); return (result); }
void init() { if (fd != 0) return; fd = service_connect(ihost, iport); if (fd < 0) { err++; } else if ((ipass != NULL) && (*ipass != '\0')) { /* Passwort senden */ char buf[40]; qprintf(buf, sizeof(buf), "pass %s", ipass); send_command(fd, buf); get_answer(fd); } }
static int session_connect(struct bluetooth_session *session) { int err; if (session->port > 0) { session->io = transport_connect(&session->src, &session->dst, session->port, transport_callback, session); err = (session->io == NULL) ? -EINVAL : 0; } else { session->sdp = service_connect(&session->src, &session->dst, service_callback, session); err = (session->sdp == NULL) ? -ENOMEM : 0; } return err; }
static DBusMessage *serial_connect(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct btd_device *device = user_data; const char *target; char src[18], dst[18]; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &target, DBUS_TYPE_INVALID) == FALSE) return NULL; ba2str(&device->src, src); ba2str(&device->dst, dst); service_connect(conn, msg, src, dst, target); return NULL; }
static papi_status_t _printer_enable_disable_pause_resume_delete(papi_service_t handle, char *name, char *message, uint16_t type) { papi_status_t result = PAPI_INTERNAL_ERROR; service_t *svc = handle; papi_attribute_t **request = NULL, **op = NULL, **response = NULL; if ((svc == NULL) || (name == NULL)) return (PAPI_BAD_ARGUMENT); /* if we are already connected, use that connection. */ if (svc->connection == NULL) if ((result = service_connect(svc, name)) != PAPI_OK) return (result); ipp_initialize_request(svc, &request, type); ipp_initialize_operational_attributes(svc, &op, name, -1); switch (type) { case OPID_DISABLE_PRINTER: papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "printer-message-from-operator", message); break; case OPID_PAUSE_PRINTER: papiAttributeListAddString(&op, PAPI_ATTR_REPLACE, "printer-state-message", message); break; default: /* a message value is of no use */ break; } papiAttributeListAddCollection(&request, PAPI_ATTR_REPLACE, "operational-attributes-group", op); papiAttributeListFree(op); result = ipp_send_request(svc, request, &response); papiAttributeListFree(request); papiAttributeListFree(response); return (result); }
papi_status_t papiServiceCreate(papi_service_t *handle, char *service_name, char *user_name, char *password, int (*authCB)(papi_service_t svc, void *app_data), papi_encryption_t encryption, void *app_data) { papi_status_t result = PAPI_NOT_POSSIBLE; service_t *svc = NULL; char *encoding = getenv("HTTP_TRANSFER_ENCODING"); if (handle == NULL) return (PAPI_BAD_ARGUMENT); if ((*handle = svc = calloc(1, sizeof (*svc))) == NULL) return (PAPI_TEMPORARY_ERROR); if (user_name != NULL) svc->user = strdup(user_name); if (password != NULL) svc->password = strdup(password); svc->encryption = encryption; if (authCB != NULL) svc->authCB = authCB; if (app_data != NULL) svc->app_data = app_data; if ((encoding != NULL) && (strcasecmp(encoding, "content-length") == 0)) svc->transfer_encoding = TRANSFER_ENCODING_LENGTH; else svc->transfer_encoding = TRANSFER_ENCODING_CHUNKED; if (service_name != NULL) { result = service_connect(svc, service_name); } else result = PAPI_OK; return (result); }
static int parse_telmon() { static int telmond_fd = -2; static char oldanswer[128]; int age; /* reread every 1 sec only */ age = hash_age(&TELMON, NULL); if (age > 0 && age <= 1000) return 0; if (telmond_fd != -1) { char telbuf[128]; telmond_fd = service_connect(thost, tport); if (telmond_fd >= 0) { int l = read(telmond_fd, telbuf, 127); if ((l > 0) && (strcmp(telbuf, oldanswer))) { char date[11]; char time[11]; char number[256]; char msn[256]; sscanf(telbuf, "%s %s %s %s", date, time, number, msn); hash_put(&TELMON, "time", time); date[4] = '\0'; date[7] = '\0'; qprintf(time, sizeof(time), "%s.%s.%s", date + 8, date + 5, date); hash_put(&TELMON, "number", number); hash_put(&TELMON, "msn", msn); hash_put(&TELMON, "date", time); phonebook(number); phonebook(msn); hash_put(&TELMON, "name", number); hash_put(&TELMON, "msnname", msn); } close(telmond_fd); strcpy(oldanswer, telbuf); } } return 0; }
static int session_connect(struct obc_session *session, struct callback_data *callback) { int err; if (session->obex) { g_idle_add(connection_complete, callback); err = 0; } else if (session->channel > 0) { session->io = rfcomm_connect(&session->src, &session->dst, session->channel, rfcomm_callback, callback); err = (session->io == NULL) ? -EINVAL : 0; } else { callback->sdp = service_connect(&session->src, &session->dst, service_callback, callback); err = (callback->sdp == NULL) ? -ENOMEM : 0; } return err; }
struct session_data *session_create(const char *source, const char *destination, const char *target, uint8_t channel, session_callback_t function, void *user_data) { struct session_data *session; struct callback_data *callback; int err; if (destination == NULL) return NULL; session = g_try_malloc0(sizeof(*session)); if (session == NULL) return NULL; session->refcount = 1; session->channel = channel; session->conn = dbus_bus_get(DBUS_BUS_SESSION, NULL); if (session->conn == NULL) { session_free(session); return NULL; } if (source == NULL) bacpy(&session->src, BDADDR_ANY); else str2ba(source, &session->src); str2ba(destination, &session->dst); if (!g_ascii_strncasecmp(target, "OPP", 3)) { sdp_uuid16_create(&session->uuid, OBEX_OBJPUSH_SVCLASS_ID); } else if (!g_ascii_strncasecmp(target, "FTP", 3)) { sdp_uuid16_create(&session->uuid, OBEX_FILETRANS_SVCLASS_ID); session->target = OBEX_FTP_UUID; session->target_len = OBEX_FTP_UUID_LEN; } else if (!g_ascii_strncasecmp(target, "PBAP", 4)) { sdp_uuid16_create(&session->uuid, PBAP_PSE_SVCLASS_ID); session->target = OBEX_PBAP_UUID; session->target_len = OBEX_PBAP_UUID_LEN; } else if (!g_ascii_strncasecmp(target, "SYNC", 4)) { sdp_uuid16_create(&session->uuid, IRMC_SYNC_SVCLASS_ID); session->target = OBEX_SYNC_UUID; session->target_len = OBEX_SYNC_UUID_LEN; } else if (!g_ascii_strncasecmp(target, "PCSUITE", 7)) { sdp_uuid128_create(&session->uuid, pcsuite_uuid); } else { return NULL; } callback = g_try_malloc0(sizeof(*callback)); if (callback == NULL) { session_free(session); return NULL; } callback->session = session_ref(session); callback->func = function; callback->data = user_data; if (session->channel > 0) { session->io = rfcomm_connect(&session->src, &session->dst, session->channel, rfcomm_callback, callback); err = (session->io == NULL) ? -EINVAL : 0; } else { callback->sdp = service_connect(&session->src, &session->dst, service_callback, callback); err = (callback->sdp == NULL) ? -ENOMEM : 0; } if (err < 0) { session_free(session); g_free(callback); return NULL; } return session; }