//indexinset - same as findinset, but abbreviations are allowed. long indexinset(char *haystack, char *needle, char delim) { char **arguments = make_real_arguments(haystack,delim); long x; for (x = 0; arguments[x]; x++) { if (!strindex(arguments[x], needle)) { free_arguments(arguments); return 0; } } free_arguments(arguments); return 1; }
// same as above but abbreviations are allowed long strargindex(char *haystack, char *needle) { char **arguments = make_arguments(haystack); long x; for(x = 0; arguments[x]; x++) { if(!strindex(arguments[x], needle)) { free_arguments(arguments); return 0; } } free_arguments(arguments); return 1; }
// compare one list to another, ie: "1 2 3" to "4 5 2" would return the matching // word, or 0 if not found char *strlistcmp(char *str1, char *str2) { static char buf[MAX_BUFFER]; char **arguments1 = make_arguments(str1); char **arguments2 = make_arguments(str2); long x, y; buf[0] = '\0'; for(x = 0; arguments1[x]; x++) for(y = 0; arguments2[y]; y++) if(!strcasecmp(arguments1[x], arguments2[y])) { strcpy(buf,arguments1[x]); break; } free_arguments(arguments1); free_arguments(arguments2); return buf[0] == '\0' ? 0 : buf; }
// count the number of words in a list. long countlist(char *haystack, char *needle) { char **arguments = make_arguments(haystack); long x, y = 0; for( x = 0; arguments[x]; x++) { if (!strcasecmp(arguments[x], needle)) y++; } free_arguments(arguments); return y; }
static int pcre_eval_header(void *_data, void *content, char *params, const char *flags){//, int parserType){ //HAY QUE PASAR UN HASHMAP EN VEZ DE UN CHAR* EN MSG. //PARAMS VA A TENER 2 PARAMETROS: // subcampo del header sobre el que se opera // expresion regular char *target_content; pcre *pcre_regex; function_arguments *arguments=parse_args(params,2); pcre_regex_data *data=(pcre_regex_data *)_data; char *header, *expr, *tmp; //printf("params: %s\n",params); if(get_argument_type(arguments,0)!=TYPE_STRING || get_argument_type(arguments,1)!=TYPE_STRING ){ wblprintf(LOG_WARNING,"PCRE REGEX PLUGIN(eval_header)","Incorrect arguments %s\n", params); return 0; } header=get_argument_content(arguments,0); expr=get_argument_content(arguments,1); if(data==NULL || hashmap_get(data->pcre_regex_cache,expr,(any_t *)&pcre_regex)==MAP_MISSING){ pcre_regex=pcregex_compile(expr); //Compile the expression if (pcre_regex==NULL) { wblprintf(LOG_WARNING,"PCRE REGEX PLUGIN(eval_header)","Incorrect regular expression %s\n", expr); return 0; } if (data!=NULL) { tmp=malloc(sizeof(char)*(strlen(expr)+1)); //Make a copy of the uncompiled regex for cache strcpy(tmp,expr); //printf("KEY INSERTADA%s\n",tmp); hashmap_put(data->pcre_regex_cache,tmp,(any_t)pcre_regex); //store the compiled regex in cache } } //Return the content to test in the raw entry generated by eml_structure_parser parser if ((target_content=getHeaderContent(content, header))==NULL){ wblprintf(LOG_WARNING, "PCRE REGEX PLUGIN (eval_header)","Unable to found raw entry on contents.\n"); return 0; } free_arguments(arguments); return pcregex_match(pcre_regex,target_content); }
static int pcre_eval(void *_data, void *content, char *params, const char *flags){//, int parserType){ //el msq es un char * ya que recibe el mail en modo raw. //Recibe un solo parametro que es el pattern char *target_content; pcre *pcre_regex; char *expr, *tmp; pcre_regex_data *data=(pcre_regex_data *)_data; function_arguments *arguments=parse_args(params,1); if(get_argument_type(arguments,0)!=TYPE_STRING){ wblprintf(LOG_WARNING,"PCRE REGEX PLUGIN(pcre_eval)","Incorrect arguments %s\n", params); return 0; } expr=get_argument_content(arguments,0); if(data==NULL || hashmap_get(data->pcre_regex_cache,expr,(any_t *)&pcre_regex)==MAP_MISSING){ pcre_regex=pcregex_compile(expr); if (pcre_regex==NULL) { wblprintf(LOG_WARNING,"PCRE REGEX PLUGIN(pcre_eval)","Incorrect regular expression %s\n", params); return 0; } if (data!=NULL){ tmp=malloc(sizeof(char)*(strlen(expr)+1)); //Make a copy of the uncompiled regex for cache //printf("KEY INSERTADA%s\n",tmp); strcpy(tmp,expr); hashmap_put(data->pcre_regex_cache,tmp,(any_t)pcre_regex); } } //Return the content to test in the raw entry generated by eml_structure_parser parser if (hashmap_get((map_t)content,"raw",(any_t *)&target_content)!=MAP_OK){ wblprintf(LOG_WARNING, "PCRE REGEX PLUGIN","Unable to found raw entry on contents"); return 0; } free_arguments(arguments); return pcregex_match(pcre_regex,target_content); }
int main(int argc, char** argv) { struct arguments* pargs; struct logfanoutd_state* plf_state; struct vpath_pair** aliases; size_t aliases_size; int ret = 1; signal(SIGINT, &handle_signal); signal(SIGTERM, &handle_signal); pargs = init_arguments(); if (pargs == NULL) { goto fail_init_args; } if (parse_args(argc, argv, pargs)) { goto fail_parse_args; } aliases = init_aliases(pargs->alias_list, &aliases_size); if (aliases == NULL) { goto fail_alloc_aliases; } plf_state = logfanoutd_start(&(pargs->listen), pargs->verbose, pargs->log, aliases, aliases_size); if (plf_state == NULL) { goto fail_logfanoutd_start; } pause(); logfanoutd_stop(plf_state); ret = 0; fail_logfanoutd_start: free(aliases); fail_alloc_aliases: fail_parse_args: free_arguments(pargs); fail_init_args: return ret; }
// str_minus("borlak pip durf","pip") returns "borlak durf"; char *str_minus(char *str, char *subtraction, char delimeter) { static char buf[MAX_BUFFER]; char **arguments = make_arguments_deli(str, delimeter); long x, i, found=0; buf[0] = '\0'; for(x = 0; arguments[x]; x++) { if(!found && !strcasecmp(arguments[x],subtraction)) { found = 1; continue; } strcat(buf,arguments[x]); i = strlen(buf); buf[i] = delimeter; buf[i+1] = '\0'; } buf[strlen(buf)-1] = '\0'; // chop off last delimeter free_arguments(arguments); return buf; }
/////////////// // FUNCTIONS // /////////////// void interpret(CREATURE *crit, char *buf) { CREATURE *xcrit=0; OBJECT *obj=0; SOCIAL *social=0; EXIT *exit=0; ROOM *room=0; char command[MAX_BUFFER]; char temp[MAX_BUFFER]; char *pbuf = command; char **arguments; char **editargs; long i = 0, x = 0; long string = 0; bool found = 0; bool command_ok = 0; bool social_ok = 0; strcpy(temp,buf); while( isspace(*buf) ) buf++; // check for one character commands without spaces to // seperate arguments. - i.e. chat yo = .yo | pip if(ispunct(*buf)) *pbuf++ = *buf++; else { while( !isspace(*buf) && *buf != '\0' ) *pbuf++ = *buf++; } *pbuf = '\0'; while( isspace(*buf) ) buf++; // moved exits before other commands - pip. // insert full exit name for abbreviated one. for( i = 0; directions[i].abbr; i++) { if (directions[i].abbr[0] != '\0' && !strcasecmp(command,directions[i].abbr)) { sprintf(command,"%s",directions[i].name); break; } } if(!IsDisabled(crit)) { for(exit = crit->in_room->exits; exit; exit = exit->next ) { if( !strindex(exit->name, command) ) { if((room = hashfind_room(exit->to_vnum)) == 0) { sendcrit(crit,"That exit enters into a domain far too powerful for you to handle."); mudlog("exit(%s) in room(%s:%d) has bad to_vnum(%d)!", exit->name, crit->in_room->name, crit->in_room->vnum, exit->to_vnum); continue; } if (exit->door >= DOOR_CLOSED && !IsImmortal(crit)) { sendcritf(crit,"The %s door is closed.",exit->name); return; } if (crit->rider) { sendcritf(crit,"You can't move on your own until %s dismounts you.",crit->rider->name); return; } // adding mounts! if (crit->mount) message("$n ride$x $p on $N.",crit,crit->mount,exit->name); else message("$n leave$x $p.",crit,0,exit->name); trans(crit,room); if (crit->mount) { trans(crit->mount,crit); message("$n arrive$x riding $N.",crit,crit->mount,crit->in_room); } message("$n $v arrived.",crit,crit->in_room,0); interpret(crit,"look"); return; } } } // check if they in editor and get a successful return (edited something) // otherwise let them use normal commands if(IsEditing(crit)) { if(crit->socket->string) { if(!(string = string_editor(crit,temp))) return; str_dup(&(*crit->socket->variable), crit->socket->string); DeleteObject(crit->socket->string) return; } else temp[0] = '\0'; if(!ValidString(command)) strcat(temp,""); else sprintf(temp,"%s %s",command,buf); editargs = make_arguments(temp); if(editor(crit,editargs)) { free_arguments(editargs); return; } free_arguments(editargs); }