void fileproc(char *fname, FILE *f) { int i; FILE *fo; fprintf(stderr, "unpacking: %s\n", fname); if ((fo = fopen(fname, "wb")) == NULL) { fprintf(stderr, "error in opening file %s", fname); perror(""); for (;;) { if ((i = fgetc(f)) == EOF) { break; } if ((char)i == keystr[0]) { if (rmatch(f, keystr + 1) == TRUE) { break; } } } return; } for (;;) { if ((i = fgetc(f)) == EOF) { break; } if ((char)i == keystr[0]) { if (rmatch(f, keystr + 1) == TRUE) { break; } } fputc(i, fo); } }
void close_reg() { if(regs->rtype) { // Find matching type, otherwise add new type. struct rtype *r; for(r=rtypes;r;r=r->next) if(rmatch(r->fields,regs->rtype->fields)) { regs->rtype=r; break; } if(!r) { regs->rtype->next=rtypes; rtypes=regs->rtype; } } }
void dirproc(char *dname, FILE *f) { char _dname[MAXPATH]; int i; strcpy(_dname, dname); if (_dname[strlen(_dname) - 1] == '\\') { _dname[strlen(_dname) - 1] = '\0'; } fprintf(stderr, "creating directory/ %s ", _dname); mkdir(_dname); for (;;) { if ((i = fgetc(f)) == EOF) { break; } if ((char)i == keystr[0]) { if (rmatch(f, keystr + 1) == TRUE) { break; } } fputc(i, stderr); } fputc('\n', stderr); }
int CheckANSI() { if (rmatch("unsigned") || rmatch("signed") || rmatch("int") || rmatch("char") || rmatch("double") || rmatch("long") || rmatch("struct") || rmatch("union") || rmatch("void") || rmatch("far") || rmatch("near") || rmatch("const") || rmatch("volatile") || rmatch("__TD__") || rmatch("float") || rmatch("register") || rmatch("short") || CheckTypDef() ) return (YES); return (NO); }
/* private plugin code */ static int plugin_regex_redirect(sip_ticket_t *ticket) { osip_uri_t *to_url=ticket->sipmsg->to->url; char *url_string=NULL; osip_uri_t *new_to_url; int i, sts; osip_contact_t *contact = NULL; /* character workspaces for regex */ #define WORKSPACE_SIZE 128 static char in[WORKSPACE_SIZE+1], rp[WORKSPACE_SIZE+1]; /* do apply to full To URI... */ sts = osip_uri_to_str(to_url, &url_string); if (sts != 0) { ERROR("osip_uri_to_str() failed"); return STS_FAILURE; } DEBUGC(DBCLASS_BABBLE, "To URI string: [%s]", url_string); /* perform search and replace of the regexes, first match hits */ for (i = 0; i < plugin_cfg.regex_pattern.used; i++) { regmatch_t *pmatch = NULL; pmatch = rmatch(url_string, WORKSPACE_SIZE, &re[i]); if (pmatch == NULL) continue; /* no match, next */ /* have a match, do the replacement */ INFO("Matched rexec rule: %s",plugin_cfg.regex_desc.string[i] ); strncpy (in, url_string, WORKSPACE_SIZE); in[WORKSPACE_SIZE]='\0'; strncpy (rp, plugin_cfg.regex_replace.string[i], WORKSPACE_SIZE); rp[WORKSPACE_SIZE]='\0'; sts = rreplace(in, WORKSPACE_SIZE, &re[i], pmatch, rp); if (sts != STS_SUCCESS) { ERROR("regex replace failed: pattern:[%s] replace:[%s]", plugin_cfg.regex_pattern.string[i], plugin_cfg.regex_replace.string[i]); osip_free(url_string); return STS_FAILURE; } /* only do first match */ break; } if (i >= plugin_cfg.regex_pattern.used) { /* no match */ osip_free(url_string); return STS_SUCCESS; } /* in: contains the new string */ sts = osip_uri_init(&new_to_url); if (sts != 0) { ERROR("Unable to initialize URI"); osip_free(url_string); return STS_FAILURE; } sts = osip_uri_parse(new_to_url, in); if (sts != 0) { ERROR("Unable to parse To URI: %s", in); osip_uri_free(new_to_url); osip_free(url_string); return STS_FAILURE; } /* use a "302 Moved temporarily" response back to the client */ /* new target is within the Contact Header */ /* remove all Contact headers in message */ for (i=0; (contact != NULL) || (i == 0); i++) { osip_message_get_contact(ticket->sipmsg, 0, &contact); if (contact) { osip_list_remove(&(ticket->sipmsg->contacts),0); osip_contact_free(contact); } } /* for i */ /* insert one new Contact header containing the new target address */ osip_contact_init(&contact); osip_list_add(&(ticket->sipmsg->contacts),contact,0); /* link the new_to_url into the Contact list */ contact->url = new_to_url; new_to_url = NULL; /* * Add the 'REDIRECTED_TAG=REDIRECTED_VAL' parameter to URI. Required to figure out * if this INVITE has already been processed (redirected) and * does not need further attention by this plugin. * THIS IS REQUIRED TO AVOID A LOOP */ osip_uri_param_add(&(contact->url->url_params), osip_strdup(REDIRECTED_TAG), osip_strdup(REDIRECTED_VAL)); INFO("redirecting %s -> %s", url_string, in); /* sent redirect message back to local client */ add_to_redirected_cache(&redirected_cache, ticket); sip_gen_response(ticket, 302 /*Moved temporarily*/); /* release resources and return */ osip_free(url_string); return STS_SIP_SENT; }
int main(int argc, char **argv) { int i, count = 0, self = FALSE; FILE *f, *fo; if (argc >= 2) { if ((argv[1][0] == '-') || (argv[1][0] == '/')) { if (strchr(argv[1], '?') != NULL) { about(); return 0; } if (strchr(argv[1], 's') != NULL) { silent = TRUE; } if (strchr(argv[1], 'i') != NULL) { ignorecase = TRUE; } if (strchr(argv[1], 'm') != NULL) { self = TRUE; } argv[1] = argv[0]; argv++; argc--; } } if (argc < 4) { fprintf(stderr, "frepl [-?sim] <src> <dest> <infile> [<outfile>]\n"); return 1; } else { if ((self == TRUE) || (argc >= 5)) { if ((fo = openx(0)) == NULL) { perror("error in opening temp file FREPLTMP.$$$"); return 10; } } else { fo = stdout; } } makestr(argv[1], s); makestr(argv[2], d); if (silent == FALSE) { fprintf(stderr, "Source string = \"%s\"\nDest string = \"%s\"\n", s, d); } if ((f = fopenx(argv[3], "rb")) == NULL) { if (silent == FALSE) { perror("error in opening source file"); } return 2; } for (;;) { if ((i = fgetc(f)) == EOF) { break; } if (charequal((char)i, s[0]) == TRUE) { /* 1st matched */ if (rmatch(f, s + 1) == TRUE) { if (silent == FALSE) { fprintf(stderr, "\rCount = %04d ", ++count); } fputs(d, fo); } else { fputc(i, fo); } } else { fputc(i, fo); } } fclose(f); fclose(fo); if (silent == FALSE) { fprintf(stderr, "\n"); } if ((self == TRUE) || (argc >= 5)) { if ((f = openx(1)) == NULL) { if (silent == FALSE) { perror("error in preparing to read temp file FREPLTMP.$$$"); } return 21; } if (silent == FALSE) { fprintf(stderr, "rewrite file...\n"); } if (self == TRUE) { copyto(f, argv[3], TRUE, "error in preparing to write infile"); } if (argc >= 5) { copyto(f, argv[4], FALSE, "error in preparing to write outfile"); } fclose(f); if (silent == FALSE) { fprintf(stderr, "deleting temp file...\n"); } remove("FREPLTMP.$$$"); } return 0; }