NSS_STATUS winbindd_get_response(struct winbindd_response *response) { struct winbindd_response lresponse; if (!response) { ZERO_STRUCT(lresponse); response = &lresponse; } init_response(response); /* Wait for reply */ if (winbindd_read_reply(response) == -1) { /* Set ENOENT for consistency. Required by some apps */ errno = ENOENT; return NSS_STATUS_UNAVAIL; } /* Throw away extra data if client didn't request it */ if (response == &lresponse) { winbindd_free_response(response); } /* Copy reply data from socket */ if (response->result != WINBINDD_OK) { return NSS_STATUS_NOTFOUND; } return NSS_STATUS_SUCCESS; }
/** * Initializes the connection state by clearing out the data structures */ static void init_connection(connection_state_t* conn_state) { conn_state->state = STATE_WAITING; init_request(&conn_state->request); init_response(&conn_state->response); }
void in_received_handler(DictionaryIterator *received, void *context) { Tuple *message_type = dict_find(received, 0); switch(message_type->value->uint8){ case MESSAGE_TYPE_RESPONSE_TOPE : init_response(); Tuple *text_name = dict_find(received, 1); add_contact_valid(text_name->value->cstring); break; } }
int main(int argc, char *argv[]) { int cmdfd = -1; bdaddr_t local_addr, remote_addr; struct avc_frame frame; int size; char *addrstr; if(argc != 2) { fprintf(stderr, "use: avsnd <dest>\n"); exit(1); } addrstr = argv[1]; fprintf(stderr, "Using address: %s\n", addrstr); str2ba(addrstr, &remote_addr); bacpy(&local_addr, BDADDR_ANY); cmdfd = do_connect(&local_addr, &remote_addr, L2CAP_PSM_AVCTP, NULL); if(cmdfd < 0) { fprintf(stderr, "can't connect to %s\n", addrstr); exit(1); } while(!terminate) { //printf("command? [u]p [d]own [q]uit > "); sleep(1); printf("sending volume-up\n"); frame.operand0 = VOLUP_OP; size = sizeof(frame); init_command(&frame.header); frame.ctype = CMD_PASSTHROUGH; frame.opcode = OP_PASS; frame.operand1 = 0; frame.zeroes = 0; frame.subunit_id = 0; frame.subunit_type = SUBUNIT_PANEL; printf("sending command\n"); dump_packet(&frame, size); write(cmdfd, &frame, size); printf("waiting for reply...\n"); size = read(cmdfd, &frame, sizeof(frame)); if(size > 0) { if(frame.ctype == CMD_ACCEPTED) { printf("(ack)\n"); } else if(frame.ctype == CMD_PASSTHROUGH) { switch (frame.operand0) { case PLAY_OP: printf("[play]\n"); break; case PAUSE_OP: printf("[pause]\n"); break; case NEXT_OP: printf("[next]\n"); break; case PREV_OP: printf("[previous]\n"); break; default: printf("received passthrough %d bytes:\n", size); dump_packet(&frame, size); } init_response(&frame.header); frame.ctype = CMD_ACCEPTED; write(cmdfd, &frame, size); } else { printf("unrecognized frame\n"); dump_packet(&frame, size); } } else { printf("no response\n"); terminate = 1; } } close(cmdfd); return 0; }