/* * handle.c * * Cutlass handle modification code - These functions run before the * cutlass threads separate. * * Copyright (c) 2004 Todd MacDermid * Jack Lloyd * */ #include #include int cutlass_register_action(cutlass_t *cut_handle, int action, cut_action_handler handle_function) { pthread_mutex_lock(&(cut_handle->handle_mutex)); cut_handle->action_handlers[action] = handle_function; pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } int cutlass_set_nick(cutlass_t *cut_handle, const char *new_nick) { set_str_option(cut_handle->user_opts, "nick", new_nick); return(0); } int cutlass_set_port(cutlass_t *cut_handle, uint16_t port) { pthread_mutex_lock(&(cut_handle->handle_mutex)); if(cut_handle->listen_socket > 0) { cutlass_sysmsg(cut_handle, CUT_ERROR, "cutlass_set_port: Warning - " "listening socket already open and I don't support " "changing on the fly yet\n"); } set_int_option(cut_handle->user_opts, "port", port); pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } int cutlass_set_verbose(cutlass_t *cut_handle, int verbose) { pthread_mutex_lock(&(cut_handle->handle_mutex)); cut_handle->verbose = verbose; pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } /* int cutlass_set_private_key (cutlass_t *cut_handle, cutlass_private_key *private_key) * set the key to be used by libcutlass for connections. * No memory is allocated here. Do not free the *private_key after setting it. (well, until applicaition * cleanup) */ int cutlass_set_private_key (cutlass_t *cut_handle, cutlass_private_key private_key ) { if (NULL == cut_handle) return (-1); if (NULL == private_key.key) return (-1); cut_handle->local_key = private_key; printf ("Set private key\n"); return (0); } int cutlass_set_actionlock(cutlass_t *cut_handle, int actionlock) { pthread_mutex_lock(&(cut_handle->handle_mutex)); cut_handle->action_lock = actionlock; pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } int cutlass_set_save_dir(cutlass_t *cut_handle, const char *save_dir) { pthread_mutex_lock(&(cut_handle->handle_mutex)); strncpy(cut_handle->perms.save_dir, save_dir, CUTLASS_DIRECTORY_LEN - 1); pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } int cutlass_set_browse_dir(cutlass_t *cut_handle, const char *browse_dir) { pthread_mutex_lock(&(cut_handle->handle_mutex)); strncpy(cut_handle->perms.browse_dir, browse_dir, CUTLASS_DIRECTORY_LEN - 1); pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } int cutlass_remove_capability(cutlass_t *cut_handle, cutlass_capability_t cap) { pthread_mutex_lock(&(cut_handle->handle_mutex)); if((cut_handle->local_info.capabilities & cap) != 0) { cut_handle->local_info.capabilities ^= cap; } pthread_mutex_unlock(&(cut_handle->handle_mutex)); return(0); } int cutlass_set_permission(cutlass_t *cut_handle, cutlass_capability_t cap, int permission) { pthread_mutex_lock(&(cut_handle->handle_mutex)); cut_handle->local_info.capabilities |= cap; switch(cap) { case CAN_RECV_FILES: cut_handle->perms.permit_push = permission; break; case CAN_SERVE_FILES: cut_handle->perms.permit_browse = permission; break; case CAN_RECV_AUDIO: cut_handle->perms.permit_audio = permission; break; default: /* Do nothing */ break; } pthread_mutex_unlock(&(cut_handle->handle_mutex)); cutlass_info_update_all(cut_handle); return(0); }