int bu_free(struct handle this_handle, void *free_bytes){ int length=(int)(power(this_handle.bu_depth)-1); int i, flag=0; /*printf("in buddy free find%p\n",free_bytes);*/ for(i=length-1;i>0;i--){ /*printf("i=%d p=%p\n",i,this_handle.bm_head[i].pointer);*/ if ((this_handle.bm_head[i].pointer==free_bytes)&&(this_handle.bm_head[i].a_used==1)){ this_handle.bm_head[i].used=0; this_handle.bm_head[i].a_used=0; flag=1; break; } } if(flag==1){ modBitmap(this_handle.bu_depth-comp_pow(i)+1, this_handle.bm_head, i, 0); if(find_buddy(i)!=-1){ //printf("%d,%d, %d,%d\n",flag,i,find_buddy(i),this_handle.bm_head[find_buddy(i)].used); while(this_handle.bm_head[find_buddy(i)].used==0){ modBitmap(this_handle.bu_depth-comp_pow(find_parents(i))+1, this_handle.bm_head, find_parents(i), 0); i=find_parents(i); /*printf("%d",i);*/ if(i==-1){ break; } } } } /*printf("flag=%d\n",flag);*/ return flag; }
void input_manual_otr_verify(char *arg) { char *msg, *temp, *sn; if (conn->conn == NULL) return; printf("\n"); sn = arg; struct BuddyList *buddy = find_buddy(sn); if (buddy) { if (buddy->otr_context) { char human_hash[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; otrl_privkey_hash_to_human(human_hash, buddy->otr_context->active_fingerprint-> fingerprint); b_echostr_s(); otrl_context_set_trust( buddy->otr_context->active_fingerprint, "verified"); printf("[OTR] Manually trusting fingerprint %s from %s\n", human_hash, sn); } } b_echostr_s(); printf("[OTR] No OTR context found for %s\n", sn); }
void input_send_smp_request(char *arg) { char *msg, *temp, *sn; if (conn->conn == NULL) return; printf("\n"); temp = strchr(arg, ' '); if (temp == NULL) { b_echostr_s(); printf("No request to send.\n"); return; } if (strlen(temp + 1) == 0) { b_echostr_s(); printf("No request to send.\n"); return; } msg = temp + 1; sn = malloc(temp - arg + 1); sn[temp - arg] = 0; strncpy(sn, arg, temp - arg); struct BuddyList *buddy = find_buddy(sn); if (buddy) { if (buddy->otr_context) { b_echostr_s(); } } b_echostr_s(); printf("[OTR] No OTR context found for %s\n", sn); }
void input_show_otr(char *arg) { if (conn->conn == NULL) return; printf("\n"); if (strlen(arg) <= 0) { check_key_gen_state(); return; } else { b_echostr_s(); struct BuddyList *buddy = find_buddy(arg); if (buddy) { printf("[OTR] status for %s\n", arg); printf(" local otr: "); switch (buddy->otr) { case -1: printf("disabled\n"); break; case 0: printf("inactive\n"); break; case 1: printf("active\n"); break; default: printf("error\n"); break; } if (buddy->otr_context) { if (buddy->otr_context->active_fingerprint) { char human_hash[OTRL_PRIVKEY_FPRINT_HUMAN_LEN]; otrl_privkey_hash_to_human(human_hash, buddy->otr_context->active_fingerprint->fingerprint); int ret = otrl_context_is_fingerprint_trusted(buddy->otr_context->active_fingerprint); printf(" fingerprint: %s (%s)\n", human_hash, ret ? "trusted" : "untrusted"); } printf(" context state: "); switch (buddy->otr_context->msgstate) { case OTRL_MSGSTATE_ENCRYPTED: printf("encrypted\n"); break; case OTRL_MSGSTATE_PLAINTEXT: printf("plaintext\n"); break; case OTRL_MSGSTATE_FINISHED: printf("finished\n"); break; default: printf("error\n"); break; } } } else { printf("[OTR] buddy not found %s\n", arg); } return; } }
bool spell_find_mount( char_data* ch, char_data*, void* vo, int level, int ) { if( null_caster( ch, SPELL_FIND_MOUNT ) ) return FALSE; if( has_mount( ch ) ) { send( ch, "You can only have one mount at a time.\n\r" ); return FALSE; } find_buddy( ch, (obj_data*) vo, level, LIST_FM_SPECIES, LIST_FM_REAGENT ); return TRUE; }
bool spell_conjure_elemental( char_data* ch, char_data*, void* vo, int level, int ) { if( null_caster( ch, SPELL_CONJURE_ELEMENTAL ) ) return FALSE; if( has_elemental( ch ) ) { send( ch, "You can have only one elemental at a time.\n\r" ); return FALSE; } find_buddy( ch, (obj_data*) vo, level, LIST_CE_SPECIES, LIST_CE_REAGENT ); return TRUE; }
block_t* merge_block(block_t* block) { block_t* buddy = find_buddy(block); if(buddy){ remove_from_free_list(buddy); remove_from_free_list(block); if(block > buddy){ ++(buddy->kval); block = buddy; }else{ ++(block->kval); } return merge_block(block); }else{ return block; } }
bool spell_construct_golem( char_data* ch, char_data*, void* vo, int level, int ) { if( null_caster( ch, SPELL_CONSTRUCT_GOLEM ) ) return FALSE; if( has_elemental( ch ) ) { send( ch, "You can have only one golem at a time.\n\r" ); return FALSE; } find_buddy( ch, (obj_data*) vo, level, LIST_CG_SPECIES, LIST_CG_REAGENT ); return TRUE; }
void input_stop_otr(char *arg) { if (conn->conn == NULL) return; printf("\n"); b_echostr_s(); struct BuddyList *buddy = find_buddy(arg); if (buddy) { if (buddy->otr == 1) { otrl_message_disconnect_all_instances(userstate, &ui_ops, NULL, conn->username, otr_proto, buddy->sn); buddy->otr = 0; printf("[OTR] Ending OTR session with %s\n", buddy->sn); } else { printf("[OTR] No OTR session found with %s\n", buddy->sn); } } else { printf("[OTR] Buddy not found: %s\n", arg); } }
void input_send_smp_response(char *arg) { char *msg, *temp, *sn; if (conn->conn == NULL) return; printf("\n"); temp = strchr(arg, ' '); if (temp == NULL) { b_echostr_s(); printf("No message to send.\n"); return; } if (strlen(temp + 1) == 0) { b_echostr_s(); printf("No message to send.\n"); return; } msg = temp + 1; sn = malloc(temp - arg + 1); sn[temp - arg] = 0; strncpy(sn, arg, temp - arg); struct BuddyList *buddy = find_buddy(sn); if (buddy) { if (buddy->otr_context) { b_echostr_s(); printf("[OTR] Responding to %s\n", sn); otrl_message_respond_smp(userstate, &ui_ops, NULL, buddy->otr_context, msg, strlen(msg)); return; } } b_echostr_s(); printf("[OTR] No OTR context found for %s\n", sn); }
/* PROTO */ void getmessage(void *c, const char *who, const int automessage, const char *message) { const char *msgin = message; char *msg = NULL, *tempmsg = NULL; char *sname; struct Waiting *wtemp, *wptr = NULL; int offset, foundWaiting = 0; int otr_message = 0; if (conn->otr) { struct BuddyList *buddy = NULL; buddy = find_buddy(who); if (buddy) { if (buddy->otr != -1) { char *newmsg; int ret = otrl_message_receiving(userstate, &ui_ops, NULL, conn->username, otr_proto, buddy->sn, msgin, &newmsg, NULL, &buddy->otr_context, NULL, NULL); if (ret) { #ifdef DEBUG b_echostr_s(); printf("[OTR] debug: internal msg %s\n", msgin); #endif return; } else { if (newmsg) { msgin = strdup(newmsg); otrl_message_free(newmsg); if (buddy->otr_context->msgstate == OTRL_MSGSTATE_ENCRYPTED) otr_message = 1; } } } } } tempmsg = strip_html(msgin); if (tempmsg == NULL) return; if (strlen(tempmsg) == 0) { free(tempmsg); return; } if (conn->netspeak_filter) { msg = undo_netspeak(tempmsg); free(tempmsg); } else { msg = tempmsg; } if (msg == NULL) return; if (strlen(msg) == 0) { free(msg); return; } if (conn->istyping == 0) { if (conn->lastsn != NULL) free(conn->lastsn); conn->lastsn = simplify_sn(who); } sname = simplify_sn(who); if (waiting == NULL) { waiting = malloc(sizeof(struct Waiting)); wptr = waiting; } else { for (wtemp = waiting; wtemp != NULL; wtemp = wtemp->next) if (imcomm_compare_nicks(c, wtemp->sn, who)) { foundWaiting = 1; wptr = wtemp; break; } if (!foundWaiting) { for (wtemp = waiting; wtemp->next != NULL; wtemp = wtemp->next); wtemp->next = malloc(sizeof(struct Waiting)); wptr = wtemp->next; } } if (!foundWaiting) { wptr->sn = strdup(who); wptr->next = NULL; if (conn->isaway && !automessage) { if ((conn->respond_idle_only && conn->isidle) || (!conn->respond_idle_only)) { imcomm_im_send_message(c, who, conn->awaymsg, 1); eraseline(); b_echostr_s(); if (conn->timestamps) { addts(); putchar(' '); } printf("Sent auto-response to %s.\n", who); show_prompt(); } } } #ifdef MESSAGE_QUEUE if (conn->isaway) wptr->mqueue = addToMQueue(wptr->mqueue, msg, who); #endif /* MESSAGE_QUEUE */ eraseline(); if (conn->bell_on_incoming) putchar('\a'); if (conn->timestamps) { addts(); putchar(' '); offset = 11; } else { offset = 0; } offset += strlen(who) + 2; if (automessage) { set_color(COLOR_AUTORESPONSE); printf("*AUTO RESPONSE* "); set_color(0); offset += 16; } set_color(COLOR_INCOMING_IM); if (!otr_message) printf("%s", who); else { offset += 5; printf("(otr)%s", who); } set_color(0); printf(": "); wordwrap_print(msg, offset); if (automessage) log_event(EVENT_IM_AUTORESPONSE, sname, msg); else log_event(EVENT_IM, sname, msg); free(msg); free(sname); show_prompt(); }