Shit *get_shituser(char *userhost, char *channel) { ChanUser *cu; Chan *chan; Shit *shit; char *p; #ifdef DEBUG debug("(get_shituser) userhost = '%s', channel = '%s'\n", nullstr(userhost),nullstr(channel)); #endif /* DEBUG */ /* * save us a few million function calls if the shitlist is empty */ if (!current->shitlist) return(NULL); if (!nickcmp(current->nick,userhost)) return(NULL); for(chan=current->chanlist;chan;chan=chan->next) { for(cu=chan->users;cu;cu=cu->next) { p = get_nuh(cu); if (matches(userhost,p)) continue; if ((shit = find_shit(p,channel)) != NULL) return(shit); } } return(NULL); }
int tcl_parse_jump(char *from, char *rest, Hook *hook) { Tcl_Obj *tcl_result; int i; #ifdef DEBUG debug("(tcl_parse_jump) %s %s %s\n", nullstr(hook->self),nullstr(from),nullstr(rest)); #endif /* DEBUG */ if (from) nickcpy(CurrentNick,from); else *CurrentNick = 0; Tcl_SetVar(energymech_tcl,"_from",from,0); Tcl_SetVar(energymech_tcl,"_rest",rest,0); i = 0; if (Tcl_VarEval(energymech_tcl,hook->self," $_from $_rest",NULL) == TCL_OK) { tcl_result = Tcl_GetObjResult(energymech_tcl); Tcl_GetIntFromObj(energymech_tcl,tcl_result,&i); } #ifdef DEBUG if (energymech_tcl->result && *energymech_tcl->result) debug("(tcl_parse_jump) result = %s\n",nullstr(energymech_tcl->result)); #endif /* DEBUG */ return(i); }
static int interrupt_command(ClipMachine * ClipMachineMemory, int argc, char **argv) { fprintf(_clip_dbg_out, "interrupt at "); fprintf(_clip_dbg_out, "file:%s", nullstr(ClipMachineMemory->fp->filename_of_ClipFrame)); fprintf(_clip_dbg_out, " line:%d", ClipMachineMemory->fp->line_of_ClipFrame); fprintf(_clip_dbg_out, " func:%s\n", nullstr(ClipMachineMemory->fp->procname_of_ClipFrame)); in_breakpoint = 1; return 0; }
void print_metrics(){ int i=0; ofstream unset; string nullstr(""); mse one(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<one.get_metric_name()<<"\n"; rmse two(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<two.get_metric_name()<<"\n"; scc three(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<three.get_metric_name()<<"\n"; difmap four(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<four.get_metric_name()<<"\n"; difmap_wkey five(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<five.get_metric_name()<<"\n"; colmap six(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<six.get_metric_name()<<"\n"; scorco seven(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<seven.get_metric_name()<<"\n"; modef eight(NULL, NULL, -1, -1, unset, nullstr); cout<<"\t"<<++i<<": "<<eight.get_metric_name()<<"\n"; }
static int bt_command(ClipMachine * ClipMachineMemory, int argc, char **argv) { ClipFrame *fp; int i; for (i = 0, fp = ClipMachineMemory->fp; fp; fp = fp->ClipFrame_up_of_ClipFrame) { if (!fp->line_of_ClipFrame) continue; fprintf(_clip_dbg_out, "%d: file:%s", i, nullstr(fp->filename_of_ClipFrame)); fprintf(_clip_dbg_out, " line:%d", fp->line_of_ClipFrame); fprintf(_clip_dbg_out, " func:%s\n", nullstr(fp->procname_of_ClipFrame)); i++; } return 0; }
void _clip_sigint(int sig) { ClipMachine *ClipMachineMemory; if (!debugging) { _clip_signal(sig); return; } ClipMachineMemory = cur_ClipMachine(); fprintf(_clip_dbg_out, "\nsigint: file %s line %d proc %s", nullstr(ClipMachineMemory->fp->filename_of_ClipFrame), ClipMachineMemory->fp->line_of_ClipFrame, nullstr(ClipMachineMemory->fp->procname_of_ClipFrame)); fprintf(_clip_dbg_out, "\n.\n"); fflush(_clip_dbg_out); _clip_logg(1, "sigint: file %s line %d proc %s", nullstr(ClipMachineMemory->fp->filename_of_ClipFrame), ClipMachineMemory->fp->line_of_ClipFrame, nullstr(ClipMachineMemory->fp->procname_of_ClipFrame)); _clip_in_breakpoint(); }
int main(int argc,char **argv) { HASHTABLE ht; char * s; int i; ht = htMake(-1); for (i = 0; i < argc; i++) htAdd(ht,argv[i],(void*)argv[i]); printf("\nContents of hash table: %d items, %d slots\n", htItems( ht ), htSize( ht ) ); htWalk(ht,1,pfunc); printf("\n===============\n"); while (1) { printf("Conflicts in table: %d\n",htConflicts(ht)); htWalk(ht,0,pfunc); printf("\n"); printf("Enter key to remove: (\"quit\" to stop): "); s = get_string(); if (!strcmp(s,"quit")) break; printf("Removing element with key \"%s\"... = %s\n",s, nullstr((char*)htRemove(ht,s))); } printf("Closing hash table\n" ); htCloseWithFunction( ht, close_func ); return 0; }
void tcl_dcc_complete(Client *client, int cps) { Tcl_Obj *obj; Tcl_Obj *vname; Hook *hook; vname = Tcl_NewStringObj("_cps",3); for(hook=hooklist;hook;hook=hook->next) { if (hook->flags == HOOK_DCC_COMPLETE && hook->guid && current && hook->guid == current->guid) { Tcl_SetVar(energymech_tcl,"_filetarget",client->whom,0); Tcl_SetVar(energymech_tcl,"_filename",client->filename,0); obj = Tcl_NewIntObj(cps); Tcl_ObjSetVar2(energymech_tcl,vname,NULL,obj,TCL_GLOBAL_ONLY); Tcl_VarEval(energymech_tcl,hook->self," $_filetarget $_filename $_cps",NULL); #ifdef DEBUG if (energymech_tcl->result && *energymech_tcl->result) debug("(tcl_dcc_complete) result = %s\n",nullstr(energymech_tcl->result)); #endif /* DEBUG */ } } }
static CLIENT *access_check (int rc, struct sockaddr_in ssin) { struct stat _stat; ulong ipaddr; ACL *acl; CLIENT *retval; int curconcur; if (master->connections > cfg.MaxConnections) { write (rc, MSG_SERVERFULL, strlen (MSG_SERVERFULL)); info ("Too many global connections, increase cfg.MaxConnections"); return NULL; } if (stat (cfg.DisableFile, &_stat) == 0) { write (rc, cfg.DisableText, strlen (cfg.DisableText)); write (rc, "\r\n", 2); return NULL; } errno = 0; ipaddr = ntohl (ssin.sin_addr.s_addr); if ( cfg.JSONACL ) { if ( (acl = gethttpacl(inet_ntoa(ssin.sin_addr), curl)) == NULL ) { syslog(LOG_ERR, "Cant get JSON ACL."); write(rc, MSG_NOACL, strlen(MSG_NOACL)); return NULL; } } else { if ( (acl = getacl(ipaddr)) == NULL ) { syslog(LOG_ERR, "Cant get default ACL, define \"acl 0/0\" in access.conf"); write(rc, MSG_NOACL, strlen(MSG_NOACL)); return NULL; } } if ( ! nullstr(acl->profile->Disabled) ) { write(rc, "400 ", 4); write(rc, acl->profile->Disabled, strlen(acl->profile->Disabled)); return NULL; } if (acl->deny) { write(rc, MSG_NOPERM, strlen(MSG_NOPERM)); info("denied connection from %s", inet_ntoa(ssin.sin_addr)); return NULL; } if (acl->profile->connections > acl->profile->MaxConnections) { write(rc, MSG_TOOMANYCONNSPRF, strlen(MSG_TOOMANYCONNSPRF)); return NULL; } semlock_lock (master->semid); retval = find_slot (ipaddr, &curconcur, acl->unlimit ? 0 : acl->profile->MaxHostConcurrent); semlock_unlock (master->semid); if (retval == NULL) { char buf[128]; sprintf (buf, MSG_TOOMANY_CONCURRENT, acl->profile->MaxHostConcurrent); write (rc, buf, strlen (buf)); syslog(LOG_DEBUG, "Too many concurrent connections from %s" , inet_ntoa (ssin.sin_addr)); return NULL; } retval->acl = acl; memcpy (&retval->addr, &ssin, sizeof (ssin)); retval->socket = rc; return retval; }
PROTO int cmdauthinfo(char *args) { char subcmd[17], subcmdargs[65]; USER *newuser; PROFILE *oldprf; PROFILE *newprf; int change_profile; AUTHRESULT *authres; sscanf (args, "%16[^\r\n\t ] %64[^\r\n]", subcmd, subcmdargs); if ( client->authenticated ) return swriteclient(client, MSG_AUTH_TWICE); if (!strcasecmp(subcmd,"user")) { if (client->authenticated && strncmp(client->username, subcmdargs, 64)) return swriteclient (client, MSG_AUTH_TWICE); if ( client->vhost->AddSuffix[0] != '\0' ) { snprintf(client->username, MAX_USERPASS-1, "%s@%s", subcmdargs, client->vhost->AddSuffix); } else { strncpy(client->username, subcmdargs, MAX_USERPASS-1); } } else if ( !strcasecmp(subcmd, "pass") ) { strncpy(client->password, subcmdargs, MAX_USERPASS-1); } else { return swriteclient(client, MSG_AUTH_UNKNOWN); } if ( client->username[0] == 0 || client->password[0] == 0 ) return swriteclient(client, MSG_MOREAUTHREQ); client->auth = getauth(client->username); if ( (authres=new_authresult(client)) == NULL ) return swriteclient(client, MSG_AUTH_NOMEM); void (*authmod)() = find_auth_mod(client->auth->auth->lib); if (!authmod) { CLEARPASS syslog(LOG_ERR, "Can't find authmap: %s", client->auth->auth->lib); swriteclient(client, MSG_AUTH_ERR); return 0; } client->authenticated = 0; (*authmod)(authres, &cfg, client->auth->auth->args); CLEARPASS if ( authres->authenticated == true ) { semlock_lock(master->semid); client->authenticated++; if ( authres->logname != NULL ) strcpy(client->logname, authres->logname); /* auth module specified profile */ if ( authres->profile != NULL ) { if ( (newprf = find_user_profile(client->username)) == NULL ) if ( (newprf=getprofile(authres->profile)) == NULL ) { client->authenticated--; semlock_unlock(master->semid); syslog(LOG_ERR, "Missing profile information from authenticator, rejecting user %s", authres->username); swriteclient(client, MSG_AUTH_ERR); free_authresult(authres); return 0; } } else { newprf = client->auth->profile; } PROFILE *p; if ( (p = prof_iplookup(newprf, client->addr.sin_addr)) != NULL ) newprf = p; if ( ! nullstr(newprf->Disabled) ) { client->authenticated--; semlock_unlock(master->semid); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: 480 %s", client->hostname, authres->username, newprf->Disabled); return writeclient(client, "482 %s", newprf->Disabled); } /* Check and verify we are allowed in our new profile */ change_profile = 0; oldprf = client->profile; if ( client->profile != newprf ) { if ( newprf->connections > newprf->MaxConnections ) { client->authenticated--; semlock_unlock(master->semid); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, MSG_AUTH_TOOMANYCON); return swriteclient(client, MSG_AUTH_TOOMANYCON); } else if ( newprf->numusers > newprf->MaxUsers ) { client->authenticated--; semlock_unlock(master->semid); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, MSG_AUTH_TOOMANYUSR); return swriteclient(client, MSG_AUTH_TOOMANYUSR); } else { change_profile = 1; } } /* Find our other connections from this user to see if we are allowed */ newuser = find_user(client->username, newprf); if ( newuser != client->user && newuser != NULL ) { if ( newuser->connections > newprf->MaxUserConcurrent ) { client->authenticated--; drop_user(newuser->id, newprf); semlock_unlock(master->semid); sleep(cfg.RetryDelay); if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, MSG_AUTH_USERFULL); free_authresult(authres); return swriteclient(client, MSG_AUTH_USERFULL); } } if ( newuser == NULL ) syslog(LOG_ERR, "newuser == NULL"); /* check number of different connected hosts from new user */ int maxhosts = newprf->ASMaxHosts; int maxconns = newprf->ASMaxConns; if ( maxconns > 0 || maxhosts > 0 ) { char httpresult[2048]; semlock_unlock(master->semid); if ( ! check_http_accountsharing(client->username, client->hostname, maxhosts, maxconns, newprf->Name, httpresult) ) { syslog(LOG_DEBUG, "HTTP account sharing returned false. maxhosts=%d, maxconns=%d, user=%s, host=%s, newprf=%s, result=%s", maxhosts, maxconns, client->username, client->hostname, newprf->Name, httpresult); semlock_lock(master->semid); client->authenticated--; drop_user(newuser->id, newprf); semlock_unlock(master->semid); sleep(cfg.RetryDelay); free_authresult(authres); return writeclient(client, "482 %s", httpresult); } semlock_lock(master->semid); } if ( change_profile == 1 ) { if ( client->profile->connections == 0 ) syslog(LOG_ERR, "Trying to drop 0 connections profile from auth: %s", client->profile->Name); else client->profile->connections--; client->profile = newprf; client->profile->connections++; } drop_user(client->user->id, oldprf); client->user = newuser; client->user->bytesleft = authres->bytes; // client->initbytes; client->posting = authres->posting; if ( authres->userkbit > 0 ) client->user->MaxUserBPS = authres->userkbit * 1000 / 8; else client->user->MaxUserBPS = client->profile->MaxUserBPS; if ( authres->timeleft > 0 ) { client->user->timeleft = authres->timeleft; } if ( authres->readpat ) { strcpy(client->user->readpat, authres->readpat); } if ( authres->postpat ) { strcpy(client->user->postpat, authres->postpat); } // syslog(LOG_DEBUG, "%s: assigning-change %s userkey %s", client->hostname, client->profile->Name, client->user->key); /* init ratelimiter */ init_ratelimiter(client); semlock_unlock(master->semid); } if ( cfg.LogAuthInfo ) syslog(LOG_NOTICE, "%s: authinfo login: %s result: %s", client->hostname, authres->username, authres->message ? authres->message : "UNKNOWN"); swriteclient(client, authres->message ? authres->message : MSG_AUTH_ERR); free_authresult(authres); return 0; }
PROTO int group(const char *group, char nogroupecho) { char b[MAX_SERVERRSP]; ACTIVE *newgroup; SERVER *svr; CLEARBUF if ( nullstr(group) ) { swriteclient(client,"500 You must select a group\r\n"); return 1; } /* only change group if it has changed */ if ( client->group == NULL || strcmp(client->group->newsgroup, group) != 0 ) { /* check for read permission */ if ( ! match_expression((unsigned char *)group , (unsigned char *)getwildmat(client->user->readpat) , 0) ) { if ( ! nogroupecho ) swriteclient(client, MSG_NOSUCHGROUP); return 1; } /* find and load our new group */ if ( (newgroup = getgroup(group)) == NULL ) { if ( ! nogroupecho ) swriteclient(client, MSG_NOSUCHGROUP); return 1; } if ( (svr=getserver(newgroup->server)) == NULL ) return swriteclient(client, "500 Cant find server for group\r\n"); /* disconnect first if we have to change server */ if ( client->groupserver != NULL && client->connected == 1 && strcmp(svr->Groups, client->groupserver->Groups) != 0 ) { disconnect_server(client); } /* close group and reconnect */ closegroup(); client->group = newgroup; switch ( connect_groupserver(client, svr->Name) ) { case CONNECT_ERR: return swriteclient(client, "500 Error selecting server\r\n"); case CONNECT_DOWN: sleep(cfg.DownDelay); return writeclient(client, MSG_SERVER_DOWN); default: break; } /* reset by connect_groupserver (via disconnect_server FIXME) */ client->group = newgroup; client->groups++; } if ( ! writeserver(client, "GROUP %s\r\n", group) ) return -1; if ( ! readserver(client, b, MAX_SERVERRSP-1) ) return -1; syslog(LOG_NOTICE, "%s: group %s", client->hostname, group); if ( ! nogroupecho ) return swriteclient(client,b); return 0; }
void skill_editor(Client *conn, const char *argument) { char arg[100]; argument = one_argument(argument, arg); if (!str_cmp(arg, "Q")) { finish_editing(conn); return; } if (!str_prefix(arg, "show")) { conn->editing->show(conn); return; } Skill *skill = (Skill *) conn->editing->data; if (!str_cmp(arg, "save")) { save_skill(skill); xwriteln(conn, "~CSkill saved.~x"); return; } if (!str_cmp(arg, "list")) { skill_edit_list(conn); return; } if (!str_cmp(arg, "A") || !str_cmp(arg, "name")) { if (nullstr(argument)) { xwriteln(conn, "~CChange skill name to what?~x"); return; } free_str(skill->name); skill->name = str_dup(argument); conn->editing->show(conn); return; } if (!str_cmp(arg, "B") || !str_cmp(arg, "damage")) { if (nullstr(argument)) { free_str(skill->damage); skill->damage = str_empty; } else { free_str(skill->name); skill->damage = str_dup(argument); } conn->editing->show(conn); return; } if (!str_cmp(arg, "C") || !str_cmp(arg, "msgOff")) { if (nullstr(argument)) { free_str(skill->msgOff); skill->msgOff = str_empty; } else { free_str(skill->msgOff); skill->msgOff = str_dup(argument); } conn->editing->show(conn); return; } if (!str_cmp(arg, "D") || !str_cmp(arg, "msgObj")) { if (nullstr(argument)) { free_str(skill->msgObj); skill->msgObj = str_empty; } else { free_str(skill->msgObj); skill->msgObj = str_dup(argument); } conn->editing->show(conn); return; } if (!str_cmp(arg, "F") || !str_cmp(arg, "mana")) { if (!is_number(argument)) { xwriteln(conn, "~CThat is not a number.~x"); return; } skill->mana = atoi(argument); conn->editing->show(conn); } if (!str_cmp(arg, "E") || !str_cmp(arg, "wait")) { if (!is_number(argument)) { xwriteln(conn, "~CThat is not a number.~x"); return; } skill->mana = atoi(argument); conn->editing->show(conn); return; } if (!str_cmp(arg, "G") || !str_cmp(arg, "cost")) { if (!is_number(argument)) { xwriteln(conn, "~CThat is not a number.~x"); return; } skill->mana = (float) atof(argument); conn->editing->show(conn); return; } if (!str_cmp(arg, "H") || !str_cmp(arg, "spell")) { if (nullstr(argument)) { skill->spellfun = 0; } else { skill->spellfun = spellfun_lookup(argument); if (skill->spellfun == 0) { xwriteln(conn, "~CValid spells are:~x"); int i; for (i = 0; spellfun_table[i].name != 0; i++) { xwritef(conn, "%-10s ", spellfun_table[i].name); if (i % 4 == 0) { xwriteln(conn, ""); } } if (i % 4 != 0) { xwriteln(conn, ""); } return; } } conn->editing->show(conn); return; } if (!str_cmp(arg, "I") || !str_cmp(arg, "gsn")) { if (nullstr(argument)) { skill->pgsn = 0; conn->editing->show(conn); return; } skill->pgsn = gsn_lookup(argument); if (skill->pgsn == 0) { xwriteln(conn, "~CValid gsns are:~x"); int i; for (i = 0; gsn_table[i].name != 0; i++) { xwritef(conn, "%-10s ", gsn_table[i].name); if (i % 4 == 0) { xwriteln(conn, ""); } } if (i % 4 != 0) { xwriteln(conn, ""); } return; } conn->editing->show(conn); return; } if (!str_cmp(arg, "J") || !str_cmp(arg, "minpos")) { long pos = value_lookup(position_table, argument); if (pos == -1) { xwritelnf(conn, "~CValid positions are: ~W%s~x", lookup_names(position_table)); return; } skill->minPos = (position_t) pos; conn->editing->show(conn); return; } if (!str_cmp(arg, "K") || !str_cmp(arg, "flags")) { if (edit_flag ("flags", conn, &skill->flags, argument, skill_flags)) { conn->editing->show(conn); } return; } if (!str_cmp(arg, "L") || !str_cmp(arg, "levels")) { char name[BUF_SIZ]; argument = one_argument(argument, name); int c = class_lookup(name); if (c == -1) { xwriteln(conn, "~CValid classes are:~W"); for (int i = 0; i < max_class; i++) { xwritef(conn, "%s ", class_table[i].name); } xwriteln(conn, "~x"); return; } if (!is_number(argument)) { xwriteln(conn, "~CThat is not a valid level.~x"); return; } skill->levels[c] = atoi(argument); conn->editing->show(conn); return; } }
void ec_set(char *from, char *to) { Chan *chan; UniVar *varval; char num[20]; char *src; int which,uaccess; src = ec_src; while(*src && *src != ')') src++; if (*src != ')') return; *(src++) = 0; if ((which = find_setting(ec_src)) >= 0) { if (which >= CHANSET_SIZE) { uaccess = get_useraccess(from,ANY_CHANNEL); varval = ¤t->setting[which]; } else if ((chan = find_channel_ny(to))) { uaccess = get_useraccess(from,to); varval = &chan->setting[which]; } else { nobo_strcpy("(unknown channel)"); return; } if (uaccess < VarName[which].uaccess) return; if (IsProc(which)) varval = varval->proc_var; if (IsChar(which)) { num[0] = varval->char_var; num[1] = 0; nobo_strcpy(num); } else if (IsInt(which)) { sprintf(num,"%i",varval->int_var); nobo_strcpy(num); } else if (IsTog(which)) { nobo_strcpy((varval->int_var) ? "on" : "off"); } else if (IsStr(which)) { nobo_strcpy(nullstr(varval->str_var)); } } else { nobo_strcpy("(unknown setting)"); } ec_src = src; }