void get_market_orders_all( ConnectionPool &conn_pool, int region_id, std::function<void(const MarketOrderSlim &order)> cb) { auto url = market_orders_all_url(region_id); unsigned page_count; //Get first page { http::AsyncRequest first_page_req; send_page_request(first_page_req, conn_pool, url, 1); process_response(first_page_req.wait(), &page_count, cb); } if (page_count > 1) { //Send all requests std::unique_ptr<http::AsyncRequest[]> page_reqs(new http::AsyncRequest[page_count - 1]); for (unsigned i = 0; i < page_count - 1; ++i) { send_page_request(page_reqs[i], conn_pool, url, i + 2); } //Process responses for (unsigned i = 0; i < page_count - 1; ++i) { unsigned ignore; process_response(page_reqs[i].wait(), &ignore, cb); } } log_info() << "Completed get_market_orders_all for " << region_id << std::endl; }
int iface_get_initial_state(State *state) { struct nlmsghdr *n; struct ifinfomsg *ifi; struct ifaddrmsg *ifa; uint8_t req[1024]; int seq = 0; assert(fd >= 0); assert(state); memset(&req, 0, sizeof(req)); n = (struct nlmsghdr*) req; n->nlmsg_len = NLMSG_LENGTH(sizeof(*ifi)); n->nlmsg_type = RTM_GETLINK; n->nlmsg_seq = seq; n->nlmsg_flags = NLM_F_MATCH|NLM_F_REQUEST|NLM_F_ACK; n->nlmsg_pid = 0; ifi = NLMSG_DATA(n); ifi->ifi_family = AF_UNSPEC; ifi->ifi_change = -1; if (send(fd, n, n->nlmsg_len, 0) < 0) { daemon_log(LOG_ERR, "send(): %s", strerror(errno)); return -1; } if (process_response(1, 0) < 0) return -1; n->nlmsg_type = RTM_GETADDR; n->nlmsg_len = NLMSG_LENGTH(sizeof(*ifa)); n->nlmsg_seq = ++seq; ifa = NLMSG_DATA(n); ifa->ifa_family = AF_INET; ifa->ifa_index = ifindex; if (send(fd, n, n->nlmsg_len, 0) < 0) { daemon_log(LOG_ERR, "send(): %s", strerror(errno)); return -1; } if (process_response(1, seq) < 0) return -1; *state = addresses ? STATE_SLEEPING : STATE_START; return 0; }
/* * do_command_response() - set up and send a command to the server, read and process the response. */ static int do_command_response(acs_cli_info_t *ctx) { int len; len = create_server_command(ctx); if (len < 0) { return -1; } /* Send it */ if (swrite(ctx->socket, ctx->cmd_buf, len) < len) { fprintf(stderr, "Failed to send command to server: %s\n", strerror(errno)); return BCME_ERROR; } /* Help server get the data till EOF */ shutdown(ctx->socket, SHUT_WR); /* Read the response */ len = sread(ctx->socket, ctx->cmd_buf, ACSD_BUFSIZE_4K-1); if (len < 0) { fprintf(stderr, "Failed to read response from server: %s\n", strerror(errno)); return BCME_ERROR; } /* Process the response */ return process_response(ctx, len); }
int Reset_get_at_at2_response(char *response) { char buf[128]; int next_state; int status; status = read_comport(buf); // read comport if (status == DATA) // if new data detected in com port buffer { strcat(response, buf); // append contents of buf to response next_state = RESET_GET_AT_AT2_RESPONSE; // come back for more data } else if (status == PROMPT) // if '>' detected { stop_serial_timer(); strcat(response, buf); status = process_response("at@2", response); if (status == STN_MFR_STRING) next_state = RESET_START_ECU_TIMER; else next_state = RESET_HANDLE_CLONE; } else if (serial_time_out) { stop_serial_timer(); alert("Connection with interface lost", NULL, NULL, "OK", NULL, 0, 0); next_state = RESET_CLOSE_DIALOG; // close dialog } else // serial buffer was empty, but we still got time next_state = RESET_GET_AT_AT2_RESPONSE; return next_state; }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *rsp, int last_in_rxq, void *cb_user_context) { struct session_data *session_data = (struct session_data *) cb_user_context; int i = rsp->request->sn % QUEUE_DEPTH; session_data->nrecv++; /* process the incoming message */ process_response(session_data, rsp); /* acknowledge xio that response is no longer needed */ xio_release_response(rsp); if (reconnect_flag || reload_flag) return 0; /* resend the message */ xio_send_request(session_data->conn, &session_data->req[i]); session_data->nsent++; return 0; }
static int st_http_sync_exchange(u1db_sync_target *st, const char *source_replica_uid, int n_docs, u1db_document **docs, int *generations, const char **trans_ids, int *target_gen, char **target_trans_id, void *context, u1db_doc_gen_callback cb) { int status, i; FILE *temp_fd = NULL; struct _http_request req = {0}; char tmpname[1024] = {0}; if (st == NULL || generations == NULL || target_gen == NULL || target_trans_id == NULL || cb == NULL) { return U1DB_INVALID_PARAMETER; } if (n_docs > 0 && (docs == NULL || generations == NULL)) { return U1DB_INVALID_PARAMETER; } status = init_temp_file(tmpname, &temp_fd, *target_gen); if (status != U1DB_OK) { goto finish; } for (i = 0; i < n_docs; ++i) { status = doc_to_tempfile( docs[i], generations[i], trans_ids[i], temp_fd); if (status != U1DB_OK) { goto finish; } } status = finalize_and_send_temp_file(st, temp_fd, source_replica_uid, &req); if (status != U1DB_OK) { goto finish; } status = process_response(st, context, cb, req.body_buffer, target_gen, target_trans_id); finish: cleanup_temp_files(tmpname, temp_fd, &req); return status; }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *rsp, int more_in_batch, void *cb_user_context) { struct session_data *session_data = cb_user_context; int i = rsp->request->sn % QUEUE_DEPTH; session_data->nrecv++; /* process the incoming message */ process_response(session_data, rsp); /* acknowledge xio that response is no longer needed */ xio_release_response(rsp); #if TEST_DISCONNECT if (session_data->nrecv == DISCONNECT_NR) { xio_disconnect(session_data->conn); return 0; } if (session_data->nsent == DISCONNECT_NR) return 0; #endif session_data->req[i].in.header.iov_base = NULL; session_data->req[i].in.header.iov_len = 0; vmsg_sglist_set_nents(&session_data->req[i].in, 0); /* resend the message */ xio_send_request(session_data->conn, &session_data->req[i]); session_data->nsent++; return 0; }
static int dodelete( const char *dn, LDAPControl **pctrls ) { int rc; int msgid; printf( _("%sdeleting entry \"%s\"\n"), dont ? "!" : "", dn ); if ( !dont ) { rc = ldap_delete_ext( ld, dn, pctrls, NULL, &msgid ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn ); tool_perror( "ldap_delete", rc, NULL, NULL, NULL, NULL ); goto done; } rc = process_response( ld, msgid, LDAP_RES_DELETE, dn ); if ( verbose && rc == LDAP_SUCCESS ) { printf( _("delete complete\n") ); } } else { rc = LDAP_SUCCESS; } done: putchar( '\n' ); return( rc ); }
void Tracker::event_sock_ready2read(network::Socket sock) { if (m_state == TRACKER_STATE_RELEASING) return; try { bool closed; size_t received = m_nm->Socket_recv(sock, m_buf + m_buflen, BUFFER_SIZE - m_buflen, closed); m_buflen += received; process_response(); if (closed) { delete_socket(); if (m_status == TRACKER_STATUS_UPDATING) m_status = TRACKER_STATUS_ERROR; return; } } catch (Exception & e) { delete_socket(); m_status = TRACKER_STATUS_ERROR; logger::LOGGER() << "Tracker ready to read event failure"; } }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *msg, int last_in_rxq, void *cb_user_context) { /* struct scatterlist *sgl; */ process_response(msg); /* message is no longer needed */ xio_release_response(msg); nrecv++; msg_pool_put(pool, msg); if (test_config.finite_run) { if (nrecv == disconnect_nr) { xio_disconnect(g_connection); return 0; } if (nrecv > disconnect_nr) return 0; } /* reset message */ msg->in.header.iov_base = NULL; msg->in.header.iov_len = 0; msg->in.data_tbl.nents = 0; /* sgl = msg->in.data_tbl.sgl; xio_tbl_set_nents(&msg->in.data_tbl, test_config.in_iov_len); sg_set_buf(sgl, NULL, ONE_MB); */ msg->sn = 0; /* recycle the message and fill new request */ msg_build_out_sgl(&msg_params, msg, test_config.hdr_len, 1, test_config.data_len); /* try to send it */ if (xio_send_request(g_connection, msg) == -1) { if (xio_errno() != EAGAIN) pr_err("**** [%p] Error - xio_send_msg " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, msg); /* xio_assert(0); */ } return 0; }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *rsp, int more_in_batch, void *cb_user_context) { struct xio_iovec_ex *sglist; process_response(rsp); /* message is no longer needed */ xio_release_response(rsp); nrecv++; if (test_config.finite_run) { if (nrecv == disconnect_nr) { xio_disconnect(conn); return 0; } if (nrecv > disconnect_nr || nsent == disconnect_nr) return 0; } /* reset message */ rsp->in.header.iov_base = NULL; rsp->in.header.iov_len = 0; sglist = vmsg_sglist(&rsp->in); vmsg_sglist_set_nents(&rsp->in, 1); sglist[0].iov_base = NULL; sglist[0].iov_len = ONE_MB; sglist[0].mr = NULL; rsp->sn = 0; rsp->more_in_batch = 0; do { /* recycle the message and fill new request */ msg_write(&msg_params, rsp, test_config.hdr_len, 1, test_config.data_len); /* try to send it */ if (xio_send_request(conn, rsp) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, rsp); xio_assert(0); } nsent++; } while (0); return 0; }
static void process_event(struct bt_hci *hci, const void *data, size_t size) { const struct bt_hci_evt_hdr *hdr = data; const struct bt_hci_evt_cmd_complete *cc; const struct bt_hci_evt_cmd_status *cs; if (size < sizeof(struct bt_hci_evt_hdr)) return; data += sizeof(struct bt_hci_evt_hdr); size -= sizeof(struct bt_hci_evt_hdr); if (hdr->plen != size) return; switch (hdr->evt) { case BT_HCI_EVT_CMD_COMPLETE: if (size < sizeof(*cc)) return; cc = data; hci->num_cmds = cc->ncmd; process_response(hci, le16_to_cpu(cc->opcode), data + sizeof(*cc), size - sizeof(*cc)); break; case BT_HCI_EVT_CMD_STATUS: if (size < sizeof(*cs)) return; cs = data; hci->num_cmds = cs->ncmd; process_response(hci, le16_to_cpu(cs->opcode), &cs->status, 1); break; default: queue_foreach(hci->evt_list, process_notify, (void *) hdr); break; } }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *msg, int more_in_batch, void *cb_user_context) { process_response(msg); if (msg->status) printf("**** message completed with error. [%s]\n", xio_strerror(msg->status)); /* message is no longer needed */ xio_release_response(msg); /* reset message */ msg->in.header.iov_base = NULL; msg->in.header.iov_len = 0; msg->in.data_iovlen = 1; msg->in.data_iov[0].iov_base = NULL; msg->in.data_iov[0].iov_len = ONE_MB; msg->in.data_iov[0].mr = NULL; msg->sn = 0; msg->more_in_batch = 0; do { /* recycle the message and fill new request */ msg_write(msg, "hello world request header", test_config.hdr_len, "hello world request data", test_config.data_len); /* try to send it */ if (xio_send_request(conn, msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, msg); return 0; } } while (0); return 0; }
static void process_response_udp(REMOTE_DNS *rdns) { int size; socklen_t addrlen; struct sockaddr_in source; addrlen = sizeof(struct sockaddr_in); size = recvfrom(rdns->sock, rdns->buffer, PACKAGE_SIZE, 0, (struct sockaddr*)&source, &addrlen); if(size < (int)sizeof(DNS_HDR)) return; if(source.sin_addr.s_addr != rdns->addr.sin_addr.s_addr) return; process_response(rdns->buffer, size); }
static void cb_req(struct libusb_transfer *transfer) { if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { wmlog_msg(1, "async bulk read error %d", transfer->status); if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) { device_disconnected = 1; return; } } else { wmlog_dumphexasc(3, transfer->buffer, transfer->actual_length, "Async read:"); process_response(&wd_status, transfer->buffer, transfer->actual_length); } if (libusb_submit_transfer(req_transfer) < 0) { wmlog_msg(1, "async read transfer sumbit failed"); } }
int iface_process(Event *event) { int b; assert(fd >= 0); b = !!addresses; if (process_response(0, 0) < 0) return -1; if (b && !addresses) *event = EVENT_ROUTABLE_ADDR_UNCONFIGURED; else if (!b && addresses) *event = EVENT_ROUTABLE_ADDR_CONFIGURED; return 0; }
int request_login(int sockfd, char *username) { if (DEBUG) printf("Start login...\n"); char buf[MAXLINE]; char tokens[MAX_TOKEN_NUM][MAXLINE]; sprintf(buf, "%d%c%s", MSG_LOGIN, DELIMITER, username); if (DEBUG) printf("Sent\t %s\n", buf); Writen(sockfd, buf, MAXLINE); Read(sockfd, buf, MAXLINE); if (DEBUG) printf("Received\t %s\n", buf); process_response(buf, tokens); return 1; }
static void process_response_tcp(REMOTE_DNS *rdns) { char *pos; int to_down, size; unsigned int len, buflen; to_down = 0; size = recv(rdns->sock, rdns->buffer + rdns->rear, rdns->capacity - rdns->rear, 0); if(size < 1) to_down = 1; else { rdns->rear += size; while((buflen = rdns->rear - rdns->head) > sizeof(unsigned short)) { pos = rdns->buffer + rdns->head; len = ntohs(*(unsigned short*)pos); if(len > PACKAGE_SIZE) { to_down = 1; break; } if(len + sizeof(unsigned short) > buflen) break; process_response(pos + sizeof(unsigned short), len); rdns->head += len + sizeof(unsigned short); } if(!to_down) { if(rdns->head == rdns->rear) { rdns->head = 0; rdns->rear = 0; } else if(rdns->head > PACKAGE_SIZE) { len = rdns->rear - rdns->head; memmove(rdns->buffer, rdns->buffer + rdns->head, len); rdns->head = 0; rdns->rear = len; } } } if(to_down){ rdns->head = 0; rdns->rear = 0; closesocket(rdns->sock); rdns->sock = INVALID_SOCKET; } }
static void *network_thread(void *context){ //envia mensajes al servidor void *requester = zmq_socket (context, ZMQ_REQ); zmq_connect (requester, "tcp://localhost:5555"); //recibe mensajes del metodo active de ui thread void *bg_pair = zmq_socket (context, ZMQ_PAIR); zmq_bind (bg_pair, "inproc://paired"); //envia mensajes al metodo idle del ui thread void *bg_socket = zmq_socket (context, ZMQ_REQ); zmq_connect(bg_socket, "inproc://threading"); s_send(requester, "/create_new_user"); char *id = s_recv (requester); printf ("Usuario conectado: %s \n", id); char mens[256]; while(1){ char *buffer = s_recv(bg_pair); s_send(bg_pair, "OK"); sprintf(mens, "%s: %s", id, buffer); s_send (requester, mens);// se adjunta el usuario // s_send(requester, buffer); char * resp = s_recv(requester); printf("server resp %s", resp); if(strcmp(resp, "OK")){ process_response(context, id, resp); s_send(bg_socket, buffer); s_recv(bg_socket); s_send(bg_socket, resp); s_recv(bg_socket); } } zmq_close(requester); zmq_close(bg_pair); zmq_close(bg_socket); }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *rsp, int last_in_rxq, void *cb_user_context) { struct session_data *session_data = cb_user_context; struct xio_msg *req = rsp; /* process the incoming message */ process_response(rsp); /* acknowledge xio that response is no longer needed */ xio_release_response(rsp); /* resend the message */ xio_send_request(session_data->connection, req); return 0; }
int main(int argc, char **argv) { srand(time(NULL)); struct command_args args = get_args(argc, argv); atexit(close_queue); key_t key = ftok(args.path, args.id); check_failure((int) key, -1, "failed to execute ftok\n"); ID = msgget(key, IPC_CREAT | 0700); check_failure(ID, -1, "failed to execute msgget\n"); struct q_msg buf; while(1) { int status; status = msgrcv(ID, &buf, size, 1, IPC_NOWAIT); if (status > 0) { start_communication(buf.msg); continue; } int i; for (i = 0; i < client_no; i++) { status = msgrcv(clients[i], &buf, size, 2, IPC_NOWAIT); if (status > 0) { send_random(buf.msg); } status = msgrcv(clients[i], &buf, size, 3, IPC_NOWAIT); if (status > 0) { process_response(buf.msg); } } } return 0; }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *rsp, int more_in_batch, void *cb_user_context) { struct hw_session_data *session_data = cb_user_context; int i = rsp->request->sn % QUEUE_DEPTH; /* process the incoming message */ process_response(rsp); /* acknowledge xio that response is no longer needed */ xio_release_response(rsp); /* resend the message */ xio_send_request(session_data->conn, &session_data->req[i]); return 0; }
static int dorename( const struct berval *dn, const struct berval *newrdn, const struct berval *newsup, int deleteoldrdn, LDAPControl **pctrls ) { int rc; int msgid; assert( dn != NULL ); assert( dn->bv_val != NULL ); assert( newrdn != NULL ); assert( newrdn->bv_val != NULL ); printf( _("%smodifying rdn of entry \"%s\"\n"), dont ? "!" : "", dn->bv_val ); if ( verbose ) { printf( _("\tnew RDN: \"%s\" (%skeep existing values)\n"), newrdn->bv_val, deleteoldrdn ? _("do not ") : "" ); } if ( !dont ) { rc = ldap_rename( ld, dn->bv_val, newrdn->bv_val, ( newsup && newsup->bv_val ) ? newsup->bv_val : NULL, deleteoldrdn, pctrls, NULL, &msgid ); if ( rc != LDAP_SUCCESS ) { fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn->bv_val ); tool_perror( "ldap_rename", rc, NULL, NULL, NULL, NULL ); goto done; } rc = process_response( ld, msgid, LDAP_RES_RENAME, dn ); if ( verbose && rc == LDAP_SUCCESS ) { printf( _("rename complete\n") ); } } else { rc = LDAP_SUCCESS; } done: putchar( '\n' ); return( rc ); }
static int st_http_sync_exchange_doc_ids(u1db_sync_target *st, u1database *source_db, int n_doc_ids, const char **doc_ids, int *generations, const char **trans_ids, int *target_gen, char **target_trans_id, void *context, u1db_doc_gen_callback cb) { int status; FILE *temp_fd = NULL; struct _http_request req = {0}; char tmpname[1024] = {0}; const char *source_replica_uid = NULL; struct _get_doc_to_tempfile_context state = {0}; if (st == NULL || generations == NULL || target_gen == NULL || target_trans_id == NULL || cb == NULL) { return U1DB_INVALID_PARAMETER; } if (n_doc_ids > 0 && (doc_ids == NULL || generations == NULL)) { return U1DB_INVALID_PARAMETER; } status = u1db_get_replica_uid(source_db, &source_replica_uid); if (status != U1DB_OK) { goto finish; } status = init_temp_file(tmpname, &temp_fd, *target_gen); if (status != U1DB_OK) { goto finish; } state.num = n_doc_ids; state.generations = generations; state.trans_ids = trans_ids; state.temp_fd = temp_fd; status = u1db_get_docs(source_db, n_doc_ids, doc_ids, 0, 1, &state, get_docs_to_tempfile); if (status != U1DB_OK) { goto finish; } status = finalize_and_send_temp_file(st, temp_fd, source_replica_uid, &req); if (status != U1DB_OK) { goto finish; } status = process_response(st, context, cb, req.body_buffer, target_gen, target_trans_id); finish: cleanup_temp_files(tmpname, temp_fd, &req); return status; }
void trouble_codes_simulator(int show) { char buf[128]; if (show) { strcpy(buf, SIM_CODES_STRING); process_response(NULL, buf); clear_trouble_codes(); num_of_codes_reported = handle_read_codes(buf, FALSE); populate_trouble_codes_list(); mil_is_on = TRUE; } else { clear_trouble_codes(); num_of_codes_reported = 0; mil_is_on = FALSE; } broadcast_dialog_message(MSG_READY, 0); }
void read_response() { if (process_response()) { error("Failed to read response\n"); disconnect(); return; } if (!client.response->done) { add_resp_socket(client.socket->fd); return; } Response tmp = client.response; client.request = client.response->request; client.socket = client.request->socket; client.response = client.request->response; append_header(client.response->headers,_("data"),from(tmp->contents,tmp->body,len(tmp->contents) - tmp->body)); append_header(client.response->headers,_("status"),from(tmp->contents,9,3)); close_socket(tmp->socket); connection(client.response->headers,"close"); add_write_socket(client.response->socket->fd); }
int Reset_get_reply_to_reset(char *response, int *device) { char buf[128]; int next_state; int status; status = read_comport(buf); // read comport if (status == DATA) // if new data detected in com port buffer { strcat(response, buf); // append contents of buf to response next_state = RESET_GET_REPLY_TO_RESET; // come back for more data } else if (status == PROMPT) // if '>' detected { stop_serial_timer(); strcat(response, buf); *device = process_response("atz", response); if (*device == INTERFACE_ELM323) next_state = RESET_START_ECU_TIMER; else if (*device == INTERFACE_ELM327) next_state = RESET_SEND_AT_AT1_REQUEST; else next_state = RESET_CLOSE_DIALOG; } else if (serial_time_out) // if the timer timed out { stop_serial_timer(); // stop the timer alert("Interface was not found", NULL, NULL, "OK", NULL, 0, 0); next_state = RESET_CLOSE_DIALOG; // close dialog } else // serial buffer was empty, but we still got time next_state = RESET_GET_REPLY_TO_RESET; return next_state; }
int Reset_get_reply_to_detect_protocol(char *response) { char buf[128]; int next_state; int status; status = read_comport(buf); if(status == DATA) // if new data detected in com port buffer { strcat(response, buf); // append contents of buf to response next_state = RESET_GET_REPLY_TO_DETECT_PROTOCOL; // come back for more } else if (status == PROMPT) // if we got the prompt { stop_serial_timer(); strcat(response, buf); status = process_response("0100", response); if (status == ERR_NO_DATA || status == UNABLE_TO_CONNECT) alert("Protocol could not be detected.", "Please check connection to the vehicle,", "and make sure the ignition is ON", "OK", NULL, 0, 0); else if (status != HEX_DATA) alert("Communication error", buf, NULL, "OK", NULL, 0, 0); next_state = RESET_CLOSE_DIALOG; } else if (serial_time_out) { stop_serial_timer(); alert("Connection with interface lost", NULL, NULL, "OK", NULL, 0, 0); next_state = RESET_CLOSE_DIALOG; } else next_state = RESET_GET_REPLY_TO_DETECT_PROTOCOL; return next_state; }
static int domodify( const char *dn, LDAPMod **pmods, LDAPControl **pctrls, int newentry ) { int rc, i, j, k, notascii, op; struct berval *bvp; if ( dn == NULL ) { fprintf( stderr, _("%s: no DN specified\n"), prog ); return( LDAP_PARAM_ERROR ); } if ( pmods == NULL ) { /* implement "touch" (empty sequence) * modify operation (note that there * is no symmetry with the UNIX command, * since \"touch\" on a non-existent entry * will fail)*/ printf( "warning: no attributes to %sadd (entry=\"%s\")\n", newentry ? "" : "change or ", dn ); } else { for ( i = 0; pmods[ i ] != NULL; ++i ) { op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES; if( op == LDAP_MOD_ADD && ( pmods[i]->mod_bvalues == NULL )) { fprintf( stderr, _("%s: attribute \"%s\" has no values (entry=\"%s\")\n"), prog, pmods[i]->mod_type, dn ); return LDAP_PARAM_ERROR; } } if ( verbose ) { for ( i = 0; pmods[ i ] != NULL; ++i ) { op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES; printf( "%s %s:\n", op == LDAP_MOD_REPLACE ? _("replace") : op == LDAP_MOD_ADD ? _("add") : op == LDAP_MOD_INCREMENT ? _("increment") : op == LDAP_MOD_DELETE ? _("delete") : _("unknown"), pmods[ i ]->mod_type ); if ( pmods[ i ]->mod_bvalues != NULL ) { for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) { bvp = pmods[ i ]->mod_bvalues[ j ]; notascii = 0; for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) { if ( !isascii( bvp->bv_val[ k ] )) { notascii = 1; break; } } if ( notascii ) { printf( _("\tNOT ASCII (%ld bytes)\n"), bvp->bv_len ); } else { printf( "\t%s\n", bvp->bv_val ); } } } } } } if ( newentry ) { printf( "%sadding new entry \"%s\"\n", dont ? "!" : "", dn ); } else { printf( "%smodifying entry \"%s\"\n", dont ? "!" : "", dn ); } if ( !dont ) { int msgid; if ( newentry ) { rc = ldap_add_ext( ld, dn, pmods, pctrls, NULL, &msgid ); } else { rc = ldap_modify_ext( ld, dn, pmods, pctrls, NULL, &msgid ); } if ( rc != LDAP_SUCCESS ) { /* print error message about failed update including DN */ fprintf( stderr, _("%s: update failed: %s\n"), prog, dn ); tool_perror( newentry ? "ldap_add" : "ldap_modify", rc, NULL, NULL, NULL, NULL ); goto done; } rc = process_response( ld, msgid, newentry ? LDAP_RES_ADD : LDAP_RES_MODIFY, dn ); if ( verbose && rc == LDAP_SUCCESS ) { printf( _("modify complete\n") ); } } else { rc = LDAP_SUCCESS; } done: putchar( '\n' ); return rc; }
int main(int argc, const char *argv[]) { TALLOC_CTX *mem_ctx = NULL; const struct ndr_interface_table *p = NULL; const struct ndr_interface_call *f; struct SPropTagArray *s; const char *opt_reqfile = NULL; const char *opt_replfile = NULL; poptContext pc; int opt; int index = -1; int ret = -1; uint8_t opnum = 0; enum {OPT_REQ=1000, OPT_REPL}; struct poptOption long_options[] = { POPT_AUTOHELP { "request", 'i', POPT_ARG_STRING, NULL, OPT_REQ, "MAPI Request", NULL }, { "response", 'o', POPT_ARG_STRING, NULL, OPT_REPL, "MAPI Response", NULL }, { NULL } }; pc = poptGetContext("mapipropsdump", argc, argv, long_options, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_REQ: opt_reqfile = poptGetOptArg(pc); break; case OPT_REPL: opt_replfile = poptGetOptArg(pc); break; } } /* Sanity checks on options */ if (!opt_reqfile || !opt_replfile) { DEBUG(0, ("Request and Response files required\n")); exit (1); } p = load_exchange_emsmdb_dso(PLUGIN); if (!p) { exit (1); } f = &p->calls[FUNCTION]; mem_ctx = talloc_init("mapipropsdump"); /* Load the request */ s = process_request(mem_ctx, f, opt_reqfile, &opnum, &index); if (!s) { talloc_free(mem_ctx); exit (1); } /* Load the response */ ret = process_response(mem_ctx, f, opt_replfile, s, opnum, index); if (ret == -1) { talloc_free(mem_ctx); exit (1); } talloc_free(mem_ctx); return (0); }