bool TUserList::isinlist(string word) { for (map<string,string>::iterator it=entry.begin(); it!=entry.end(); it++) if (ucase(it->first)==ucase(word)) return true; return false; }
void TUserList::edit(string word, string add) { for (map<string,string>::iterator it=entry.begin(); it!=entry.end(); it++) if (ucase(it->first)==ucase(word)) { it->second=add; break; } }
void TUserList::removefromlist(string word) { for (map<string,string>::iterator it=entry.begin(); it!=entry.end(); it++) if (ucase(it->first)==ucase(word)) { entry.erase(it); break; } }
/* * Create a degenerate DAG (linear sequence of nodes) for the given hyp line. * The DAG contains a terminal sentinel silwid node. */ static dag_t *hypline2dag (char *ref_uttid, char *line) { char junk1[4096], junk2[4096], uttid[4096]; s3wid_t wid[MAX_UTT_LEN]; int32 i, n; dag_t *dag; dagnode_t *d; if ((n = line2wid (dict, line, wid, MAX_UTT_LEN-1, 0, uttid)) < 0) E_FATAL("Error in parsing hyp line: %s\n", line); /* Verify uttid with ref_uttid */ if (strcmp (uttid, ref_uttid) != 0) { strcpy (junk1, uttid); ucase (junk1); strcpy (junk2, ref_uttid); ucase (junk2); if (strcmp (junk1, junk2) != 0) E_FATAL("Uttid mismatch: %s(ref), %s(hyp)\n", ref_uttid, uttid); } /* Build DAG from word sequence */ dag = ckd_calloc (1, sizeof(dag_t)); dag->node_sf = (dagnode_t **) ckd_calloc (S3_MAX_FRAMES, sizeof(dagnode_t *)); dag->nnode = 0; dag->nfrm = 0; dag->nlink = 0; for (i = 0; i < n; i++) { if ((NOT_WID(wid[i])) || (wid[i] >= oovbegin)) E_FATAL("%s: Unknown word in line: %s\n", uttid, line); /* Create DAG node for word */ d = (dagnode_t *) listelem_alloc (sizeof(dagnode_t)); wid2dagnode (d, i, wid[i]); dag->node_sf[i] = d; if (i > 0) { dag_link (dag->node_sf[i-1], d); dag->nlink++; } dag->nnode++; } dag->nfrm = dag->nnode; dag->entry.src = NULL; dag->entry.dst = dag->node_sf[0]; dag->entry.next = NULL; dag->exit.src = NULL; dag->exit.dst = dag->node_sf[dag->nnode - 1]; dag->exit.next = NULL; return dag; }
void mm_notify (MAILSTREAM *stream,char *string,long errflg) { char tmp[MAILTMPLEN]; tmp[11] = '\0'; /* see if TRYCREATE */ if (!strcmp (ucase (strncpy (tmp,string,11)),"[TRYCREATE]")) trycreate = T; mm_log (string,errflg); /* just do mm_log action */ }
static void append_byrule(char *byrule, struct buf *vals, struct buf *rrule) { /* append BY* rule to RRULE buffer */ buf_printf(rrule, ";%s=%s", ucase(byrule), buf_cstring(vals)); /* free the vals buffer */ buf_free(vals); free(vals); }
static int32 phone_str2id (char *str) { int32 i; ucase (str); for (i = 0; phonestr[i] && (strcmp (phonestr[i], str) != 0); i++); return (phonestr[i] ? i : -1); }
int ngram_model_casefold(ngram_model_t * model, int kase) { int writable, i; hash_table_t *new_wid; /* Were word strings already allocated? */ writable = model->writable; /* Either way, we are going to allocate some word strings. */ model->writable = TRUE; /* And, don't forget, we need to rebuild the word to unigram ID * mapping. */ new_wid = hash_table_new(model->n_words, FALSE); for (i = 0; i < model->n_words; ++i) { char *outstr; if (writable) { outstr = model->word_str[i]; } else { outstr = ckd_salloc(model->word_str[i]); } /* Don't case-fold <tags> or [classes] */ if (outstr[0] == '<' || outstr[0] == '[') { } else { switch (kase) { case NGRAM_UPPER: ucase(outstr); break; case NGRAM_LOWER: lcase(outstr); break; default: ; } } model->word_str[i] = outstr; /* Now update the hash table. We might have terrible * collisions here, so warn about them. */ if (hash_table_enter_int32(new_wid, model->word_str[i], i) != i) { E_WARN("Duplicate word in dictionary after conversion: %s\n", model->word_str[i]); } } /* Swap out the hash table. */ hash_table_free(model->wid); model->wid = new_wid; return 0; }
/* * Read a single log item from a sync log file. The item will be * returned as three constant strings. The first string is the type of * the item (e.g. "MAILBOX") and is always capitalised. The second and * third strings are arguments. * * Returns 0 on success, EOF when the end of the file is reached, or an * IMAP error code on failure. */ EXPORTED int sync_log_reader_getitem(sync_log_reader_t *slr, const char *args[3]) { int c; const char *arg1s = NULL; const char *arg2s = NULL; if (!slr->input) return EOF; for (;;) { if ((c = getword(slr->input, &slr->type)) == EOF) return EOF; /* Ignore blank lines */ if (c == '\r') c = prot_getc(slr->input); if (c == '\n') continue; if (c != ' ') { syslog(LOG_ERR, "Invalid input"); eatline(slr->input, c); continue; } if ((c = getastring(slr->input, 0, &slr->arg1)) == EOF) return EOF; arg1s = slr->arg1.s; arg2s = NULL; if (c == ' ') { if ((c = getastring(slr->input, 0, &slr->arg2)) == EOF) return EOF; arg2s = slr->arg2.s; } if (c == '\r') c = prot_getc(slr->input); if (c != '\n') { syslog(LOG_ERR, "Garbage at end of input line"); eatline(slr->input, c); continue; } break; } ucase(slr->type.s); args[0] = slr->type.s; args[1] = arg1s; args[2] = arg2s; return 0; }
char *mailboxfile (char *dst,char *name) { char *s; char *ext = (char *) mail_parameters (NIL,GET_EXTENSION,NIL); /* forbid extraneous extensions */ if ((s = strchr ((s = strrchr (name,'\\')) ? s : name,'.')) && ((ext = (char *) mail_parameters (NIL,GET_EXTENSION,NIL)) || strchr (s+1,'.'))) return NIL; /* absolute path name? */ if ((*name == '\\') || (name[1] == ':')) strcpy (dst,name); else sprintf (dst,"%s\\%s",myhomedir (),name); if (ext) sprintf (dst + strlen (dst),".%s",ext); return ucase (dst); }
local UCase * new_node(const Match *matches, UCase *failure, UCase *subtree) { LCase *limbs; if (IsCharCase(matches)) { limbs = char_case(failure); ca_assign(limbs->lc_c_limbs, matches->index, subtree); } else { limbs = IsNumCase(matches) ? num_case(failure) : alg_case(matches->ncases, failure); limbs->lc_limbs[matches->index] = subtree; } return ucase(matches->level, p_stash(matches->where), limbs); }
static void pronerr_output (char *id, s3wid_t *ref, int32 nref, wseg_t *wseg, s3cipid_t *ap, int8 *ap_err, int32 ws, int32 we, int32 ps, int32 pe) { int32 j; s3wid_t rcwid, lcwid; char str[4096]; /* Word sequence for region in error */ sprintf (str, "%s", dict_wordstr (dict, dict_basewid(dict, ref[ws]))); for (j = ws+1; j <= we; j++) { strcat (str, " "); strcat (str, dict_wordstr (dict, dict_basewid(dict, ref[j]))); } printf ("%-22s\t=>\t", str); /* Print left context phone */ /*lcwid = ((wseg[ws].s < 0) && (ws > 0) && IS_WID(ref[ws-1])) ? ref[ws-1] : BAD_WID;*/ lcwid = (ws > 0) ? ref[ws-1] : BAD_WID; if (IS_WID(lcwid)) { j = dict->word[lcwid].pronlen - 1; sprintf (str, "(%s)", mdef_ciphone_str (mdef, dict->word[lcwid].ciphone[j])); } else strcpy (str, "()"); printf ("%-5s", str); /* Phone sequence for region in error */ for (j = ps; j <= pe; j++) { strcpy (str, mdef_ciphone_str (mdef, ap[j])); if (ap_err[j]) ucase (str); else lcase (str); printf (" %s", str); } /* Right context if ending in error */ /* rcwid = ((wseg[we].e < 0) && IS_WID(ref[we+1])) ? ref[we+1] : BAD_WID; */ rcwid = ref[we+1]; if (IS_WID(rcwid)) printf ("\t(%s)", mdef_ciphone_str (mdef, dict->word[rcwid].ciphone[0])); else printf ("\t()"); printf (" ( %s )\n", id); }
long dummy_canonicalize (char *tmp,char *ref,char *pat) { unsigned long i; char *s,dev[4]; /* initially no device */ dev[0] = dev[1] = dev[2] = dev[3] = '\0'; if (ref) switch (*ref) { /* preliminary reference check */ case '{': /* remote names not allowed */ return NIL; /* disallowed */ case '\0': /* empty reference string */ break; default: /* all other names */ if (ref[1] == ':') { /* start with device name? */ dev[0] = *ref++; dev[1] = *ref++; } break; } if (pat[1] == ':') { /* device name in pattern? */ dev[0] = *pat++; dev[1] = *pat++; ref = NIL; /* ignore reference */ } switch (*pat) { case '#': /* namespace names */ if (mailboxfile (tmp,pat)) strcpy (tmp,pat); else return NIL; /* unknown namespace */ break; case '{': /* remote names not allowed */ return NIL; case '\\': /* rooted name */ ref = NIL; /* ignore reference */ break; } /* make sure device names are rooted */ if (dev[0] && (*(ref ? ref : pat) != '\\')) dev[2] = '\\'; /* build name */ sprintf (tmp,"%s%s%s",dev,ref ? ref : "",pat); ucase (tmp); /* force upper case */ /* count wildcards */ for (i = 0, s = tmp; *s; *s++) if ((*s == '*') || (*s == '%')) ++i; if (i > MAXWILDCARDS) { /* ridiculous wildcarding? */ MM_LOG ("Excessive wildcards in LIST/LSUB",ERROR); return NIL; } return T; }
program() { var filename=COMMAND.a(2); var itemids=erase(COMMAND,1,0,0); eraser(itemids,1,0,0); var silent=index(ucase(OPTIONS),"S"); if (not filename or not itemids) abort("Syntax is 'delete filename itemid ... (S=Silent)'"); var file; if (not open(filename,file)) abort(filename^" file does not exist."); var sep=0; var posn=1; var ndeleted=0; do { var itemid=remove(itemids,posn,sep); if (itemid=="*") { clearfile(file); if (not silent) printl("All records deleted"); stop(); } if (deleterecord(file,itemid)) ++ndeleted; else if (not silent) printl(quote(itemid)^" does not exist."); } while (sep); if (not silent) printl(ndeleted^" record(s) deleted."); }
program() { //hard coded editor at the moment //http://www.nano-editor.org/docs.php var editor="nano"; //restrict to editing records for now //#define ALLOW_EDIC #ifdef ALLOW_EDIC if (dcount(COMMAND,FM)<3) { #else if (dcount(COMMAND,FM)<2) { #endif //quit if arguments if (dcount(COMMAND,FM)<2) abort( "Syntax is:" "\nedit databasefilename key ..." #ifdef ALLOW_EDIC "\nor" "\nedit osfilename" #endif ); //switch to edic if only one argument osshell(COMMAND.replace(1,0,0,"edic").convert(FM," ")); stop(); } var filename=COMMAND.a(2); var key=COMMAND.a(3); //connect to the database if (not connect()) stop("Please login"); //check the file exists var file; if (not open(filename,file)) stop("Cannot open file " ^ filename); //get the record from the database var record; if (not read(record,file,key)) { //check if exists in upper or lower case var key2=key.ucase(); if (key2 eq key) key2.lcaser(); if (read(record,file,key2)) key=key2; else record=""; } //convert to text format record.swapper("\\","\\\\"); record.swapper("\n","\\n"); record.swapper(FM,"\n"); //put the record on a temp file in order to edit it var temposfilename=filename^ "~" ^ key; var invalidfilechars=L"\"\'\u00A3$%^&*(){}[]:;#<>?,./\\|"; temposfilename.converter(invalidfilechars,str("-",len(invalidfilechars))); temposfilename^=".tmp"; oswrite(record,temposfilename); //record file update timedate var fileinfo=osfile(temposfilename); if (not fileinfo) abort("Couldnt write local copy for editing "^temposfilename); //fire up the editor var editcmd=editor ^ " " ^ temposfilename.quote(); printl(editcmd); osshell(editor ^ " " ^ temposfilename); //if the file has been updated var fileinfo2=osfile(temposfilename); if (fileinfo2 eq fileinfo) { //file has not been edited osdelete(temposfilename); } else { //file has been edited var record2; osread(record2,temposfilename); //remove trailing lf or cr or crlf trimmerb(record2,"\r\n"); //convert to record format record2.swapper("\n",FM); record2.swapper("\\n","\n"); record2.swapper("\\\\","\\"); if (record2 ne record) { //print("Ok to update? "); //var reply=inputl(); var reply="Y"; //keep trying to update - perhaps futilely //at least temp file will be left in the directory while (ucase(reply)[1] eq "Y" and true) { if (write(record2,file,key)) { printl(filename^" written "^key); osdelete(temposfilename); break; } var temp; temp.input(); } } } }
/* * Construct an iCalendar property value from a JSON object. */ static icalvalue *json_object_to_icalvalue(json_t *jvalue, icalvalue_kind kind) { icalvalue *value = NULL; int len, i; switch (kind) { case ICAL_BOOLEAN_VALUE: if (json_is_boolean(jvalue)) value = icalvalue_new_integer(json_is_true(jvalue)); else syslog(LOG_WARNING, "jCal boolean object expected"); break; case ICAL_FLOAT_VALUE: if (json_is_real(jvalue)) value = icalvalue_new_float((float) json_real_value(jvalue)); else syslog(LOG_WARNING, "jCal double object expected"); break; case ICAL_GEO_VALUE: /* MUST be an array of 2 doubles */ if (json_is_array(jvalue) && (len = json_array_size(jvalue)) != 2) { for (i = 0; i < len && json_is_real(json_array_get(jvalue, i)); i++); if (i == len) { struct icalgeotype geo; geo.lat = json_real_value(json_array_get(jvalue, 0)); geo.lon = json_real_value(json_array_get(jvalue, 1)); value = icalvalue_new_geo(geo); } } if (!value) syslog(LOG_WARNING, "jCal array object of 2 doubles expected"); break; case ICAL_INTEGER_VALUE: if (json_is_integer(jvalue)) value = icalvalue_new_integer((int) json_integer_value(jvalue)); else if (json_is_string(jvalue)) value = icalvalue_new_integer(atoi(json_string_value(jvalue))); else syslog(LOG_WARNING, "jCal integer object expected"); break; case ICAL_RECUR_VALUE: if (json_is_object(jvalue)) { struct buf rrule = BUF_INITIALIZER; struct icalrecurrencetype rt; const char *key, *sep = ""; json_t *val; /* create an iCal RRULE string from jCal 'recur' object */ json_object_foreach(jvalue, key, val) { char *mykey = xstrdup(key); buf_printf(&rrule, "%s%s=", sep, ucase(mykey)); buf_appendjson(&rrule, val); sep = ";"; free(mykey); } /* parse our iCal RRULE string */ rt = icalrecurrencetype_from_string(buf_cstring(&rrule)); buf_free(&rrule); if (rt.freq != ICAL_NO_RECURRENCE) value = icalvalue_new_recur(rt); } else
int main(int argc, char **argv) { int cmp; char *n1 = NULL; char *n2 = NULL; char s1[MAX_STR_LEN]; char s2[MAX_STR_LEN]; char strs[NUM_STRS][MAX_STR_LEN] = { STR0, STR1, STR2, STR3, STR4, STR5 }; if (argc < 2 || 3 == argc || argc > 4 || (strcmp(argv[1], "lcase") && strcmp(argv[1], "ucase") && strcmp(argv[1], "strcmp_nocase") )) { /*printf("INVALID PARAMETERS to chgCase\n"); */ exit(1); } if (2 == argc) { if (0 == strcmp(argv[1], "ucase")) { ucase(n1); } else if (0 == strcmp(argv[1], "lcase")) { lcase(n1); } else { strcmp_nocase(n1, n2); } /* if we're still alive we obviously didn't segfault */ exit(0); } if (4 == argc) { if (0 >= atoi(argv[2]) || atoi(argv[2]) >= NUM_STRS || 0 >= atoi(argv[3]) || atoi(argv[3]) >= NUM_STRS) { E_INFO("INVALID PARAMS TO chkCase\n"); exit(1); } strcpy(s1, strs[atoi(argv[2])]); strcpy(s2, strs[atoi(argv[3])]); if (0 == strcmp(argv[1], "ucase")) { ucase(s1); cmp = strcmp(s1, s2); } else if (0 == strcmp(argv[1], "lcase")) { lcase(s1); cmp = strcmp(s1, s2); } else { cmp = strcmp_nocase(s1, s2); } /* E_INFO("Value of cmp %d\n", cmp); */ if (0 != cmp) { E_FATAL("test failed\nstr1:|%s|\nstr2:|%s|\n", s1, s2); } return (cmp != 0); } /*somehow we got here and we shouldn't have */ exit(1); }
int deliver (FILE *f,unsigned long msglen,char *user) { MAILSTREAM *ds = NIL; char *s,*mailbox,tmp[MAILTMPLEN],path[MAILTMPLEN]; STRING st; struct stat sbuf; /* have a mailbox specifier? */ if (mailbox = strchr (user,'+')) { *mailbox++ = '\0'; /* yes, tie off user name */ if (!*mailbox || !strcmp ("INBOX",ucase (strcpy (tmp,mailbox)))) mailbox = NIL; /* user+ and user+INBOX same as user */ } if (!*user) user = myusername (); else if (strcmp (user,myusername ())) return fail ("can't deliver to other user",EX_CANTCREAT); sprintf (tmp,"delivering to %.80s+%.80s",user,mailbox ? mailbox : "INBOX"); mm_dlog (tmp); /* prepare stringstruct */ INIT (&st,file_string,(void *) f,msglen); if (mailbox) { /* non-INBOX name */ switch (mailbox[0]) { /* make sure a valid name */ default: /* other names, try to deliver if not INBOX */ if (!strstr (mailbox,"..") && !strstr (mailbox,"//") && !strstr (mailbox,"/~") && mailboxfile (path,mailbox) && path[0] && !deliver_safely (NIL,&st,mailbox,path,tmp)) return NIL; case '%': case '*': /* wildcards not valid */ case '/': /* absolute path names not valid */ case '~': /* user names not valid */ sprintf (tmp,"invalid mailbox name %.80s+%.80s",user,mailbox); mm_log (tmp,WARN); break; } mm_dlog ("retrying delivery to INBOX"); SETPOS (&st,0); /* rewind stringstruct just in case */ } /* no -I, resolve "INBOX" into path */ if (mailboxfile (path,mailbox = "INBOX") && !path[0]) { /* clear box, get generic INBOX prototype */ if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE))) fatal ("no INBOX prototype"); /* standard system driver? */ if (!strcmp (ds->dtb->name,"unix") || !strcmp (ds->dtb->name,"mmdf")) { strcpy (path,sysinbox ());/* use system INBOX */ if (!lstat (path,&sbuf)) /* deliver to existing system INBOX */ return deliver_safely (ds,&st,mailbox,path,tmp); } else { /* other driver, try ~/INBOX */ if ((mailboxfile (path,"&&&&&") == path) && (s = strstr (path,"&&&&&")) && strcpy (s,"INBOX") && !lstat (path,&sbuf)){ /* deliver to existing ~/INBOX */ sprintf (tmp,"#driver.%s/INBOX",ds->dtb->name); return deliver_safely (ds,&st,cpystr (tmp),path,tmp); } } /* not dummy, deliver to driver imputed path */ if (strcmp (ds->dtb->name,"dummy")) return (ibxpath (ds,&mailbox,path) && !lstat (path,&sbuf)) ? deliver_safely (ds,&st,mailbox,path,tmp) : fail ("unable to resolve INBOX path",EX_CANTCREAT); /* dummy, empty imputed append path exist? */ if (ibxpath (ds = default_proto (T),&mailbox,path) && !lstat (path,&sbuf) && !sbuf.st_size) return deliver_safely (ds,&st,mailbox,path,tmp); /* impute path that we will create */ if (!ibxpath (ds = default_proto (NIL),&mailbox,path)) return fail ("unable to resolve INBOX",EX_CANTCREAT); } /* black box, must create, get create proto */ else if (lstat (path,&sbuf)) ds = default_proto (NIL); else { /* black box, existing file */ /* empty file, get append prototype */ if (!sbuf.st_size) ds = default_proto (T); /* non-empty, get prototype from its data */ else if (!(ds = mail_open (NIL,"INBOX",OP_PROTOTYPE))) fatal ("no INBOX prototype"); /* error if unknown format */ if (!strcmp (ds->dtb->name,"phile")) return fail ("unknown format INBOX",EX_UNAVAILABLE); /* otherwise can deliver to it */ return deliver_safely (ds,&st,mailbox,path,tmp); } sprintf (tmp,"attempting to create mailbox %.80s path %.80s",mailbox,path); mm_dlog (tmp); /* supplicate to the Evil One */ if (!path_create (ds,path)) return fail ("can't create INBOX",EX_CANTCREAT); sprintf (tmp,"created %.80s",path); mm_dlog (tmp); /* deliver the message */ return deliver_safely (ds,&st,mailbox,path,tmp); }
/* * Construct an iCalendar component from a XML element. */ static icalcomponent *xml_element_to_icalcomponent(xmlNodePtr xcomp) { icalcomponent_kind kind; icalcomponent *comp = NULL; xmlNodePtr node, xprop, xsub; if (!xcomp) return NULL; /* Get component type */ kind = icalenum_string_to_component_kind( ucase(icalmemory_tmp_copy((const char *) xcomp->name))); if (kind == ICAL_NO_COMPONENT) { syslog(LOG_WARNING, "Unknown xCal component type: %s", xcomp->name); return NULL; } /* Create new component */ comp = icalcomponent_new(kind); if (!comp) { syslog(LOG_ERR, "Creation of new %s component failed", xcomp->name); return NULL; } /* Add properties */ node = xmlFirstElementChild(xcomp); if (!node || xmlStrcmp(node->name, BAD_CAST "properties")) { syslog(LOG_WARNING, "Expected <properties> XML element, received %s", node->name); goto error; } for (xprop = xmlFirstElementChild(node); xprop; xprop = xmlNextElementSibling(xprop)) { icalproperty *prop = xml_element_to_icalproperty(xprop); if (!prop) goto error; icalcomponent_add_property(comp, prop); } /* Add sub-components */ if (!(node = xmlNextElementSibling(node))) return comp; if (xmlStrcmp(node->name, BAD_CAST "components")) { syslog(LOG_WARNING, "Expected <components> XML element, received %s", node->name); goto error; } for (xsub = xmlFirstElementChild(node); xsub; xsub = xmlNextElementSibling(xsub)) { icalcomponent *sub = xml_element_to_icalcomponent(xsub); if (!sub) goto error; icalcomponent_add_component(comp, sub); } /* Sanity check */ if ((node = xmlNextElementSibling(node))) { syslog(LOG_WARNING, "Unexpected XML element in component: %s", node->name); goto error; } return comp; error: icalcomponent_free(comp); return NULL; }
/* * Construct an iCalendar property value from XML content. */ static icalvalue *xml_element_to_icalvalue(xmlNodePtr xtype, icalvalue_kind kind) { icalvalue *value = NULL; xmlNodePtr node; xmlChar *content = NULL; switch (kind) { case ICAL_GEO_VALUE: { struct icalgeotype geo; node = xmlFirstElementChild(xtype); if (!node) { syslog(LOG_WARNING, "Missing <latitude> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "latitude")) { syslog(LOG_WARNING, "Expected <latitude> XML element, received %s", node->name); break; } content = xmlNodeGetContent(node); geo.lat = atof((const char *) content); node = xmlNextElementSibling(node); if (!node) { syslog(LOG_WARNING, "Missing <longitude> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "longitude")) { syslog(LOG_WARNING, "Expected <longitude> XML element, received %s", node->name); break; } xmlFree(content); content = xmlNodeGetContent(node); geo.lon = atof((const char *) content); value = icalvalue_new_geo(geo); break; } case ICAL_PERIOD_VALUE: { struct icalperiodtype p; p.start = p.end = icaltime_null_time(); p.duration = icaldurationtype_from_int(0); node = xmlFirstElementChild(xtype); if (!node) { syslog(LOG_WARNING, "Missing <start> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "start")) { syslog(LOG_WARNING, "Expected <start> XML element, received %s", node->name); break; } content = xmlNodeGetContent(node); p.start = icaltime_from_string((const char *) content); if (icaltime_is_null_time(p.start)) break; node = xmlNextElementSibling(node); if (!node) { syslog(LOG_WARNING, "Missing <end> / <duration> XML element"); break; } else if (!xmlStrcmp(node->name, BAD_CAST "end")) { xmlFree(content); content = xmlNodeGetContent(node); p.end = icaltime_from_string((const char *) content); if (icaltime_is_null_time(p.end)) break; } else if (!xmlStrcmp(node->name, BAD_CAST "duration")) { xmlFree(content); content = xmlNodeGetContent(node); p.duration = icaldurationtype_from_string((const char *) content); if (icaldurationtype_as_int(p.duration) == 0) break; } else { syslog(LOG_WARNING, "Expected <end> / <duration> XML element, received %s", node->name); break; } value = icalvalue_new_period(p); break; } case ICAL_RECUR_VALUE: { struct buf rrule = BUF_INITIALIZER; struct hash_table byrules; struct icalrecurrencetype rt; char *sep = ""; construct_hash_table(&byrules, 10, 1); /* create an iCal RRULE string from xCal <recur> sub-elements */ for (node = xmlFirstElementChild(xtype); node; node = xmlNextElementSibling(node)) { content = xmlNodeGetContent(node); if (!xmlStrncmp(node->name, BAD_CAST "by", 2)) { /* BY* rules can have a list of values - assemble them using a hash table */ struct buf *vals = hash_lookup((const char *) node->name, &byrules); if (vals) { /* append this value to existing list */ buf_printf(vals, ",%s", (char *) content); } else { /* create new list with this valiue */ vals = xzmalloc(sizeof(struct buf)); buf_setcstr(vals, (char *) content); hash_insert((char *) node->name, vals, &byrules); } } else { /* single value rpart */ buf_printf(&rrule, "%s%s=%s", sep, ucase((char *) node->name), (char *) content); sep = ";"; } xmlFree(content); content = NULL; } /* append the BY* rules to RRULE buffer */ hash_enumerate(&byrules, (void (*)(const char*, void*, void*)) &append_byrule, &rrule); free_hash_table(&byrules, NULL); /* parse our iCal RRULE string */ rt = icalrecurrencetype_from_string(buf_cstring(&rrule)); buf_free(&rrule); if (rt.freq != ICAL_NO_RECURRENCE) value = icalvalue_new_recur(rt); break; } case ICAL_REQUESTSTATUS_VALUE: { struct icalreqstattype rst = { ICAL_UNKNOWN_STATUS, NULL, NULL }; short maj, min; node = xmlFirstElementChild(xtype); if (!node) { syslog(LOG_WARNING, "Missing <code> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "code")) { syslog(LOG_WARNING, "Expected <code> XML element, received %s", node->name); break; } content = xmlNodeGetContent(node); if (sscanf((const char *) content, "%hd.%hd", &maj, &min) == 2) { rst.code = icalenum_num_to_reqstat(maj, min); } if (rst.code == ICAL_UNKNOWN_STATUS) { syslog(LOG_WARNING, "Unknown request-status code"); break; } node = xmlNextElementSibling(node); if (!node) { syslog(LOG_WARNING, "Missing <description> XML element"); break; } else if (xmlStrcmp(node->name, BAD_CAST "description")) { syslog(LOG_WARNING, "Expected <description> XML element, received %s", node->name); break; } xmlFree(content); content = xmlNodeGetContent(node); rst.desc = (const char *) content; node = xmlNextElementSibling(node); if (node) { if (xmlStrcmp(node->name, BAD_CAST "data")) { syslog(LOG_WARNING, "Expected <data> XML element, received %s", node->name); break; } xmlFree(content); content = xmlNodeGetContent(node); rst.debug = (const char *) content; } value = icalvalue_new_requeststatus(rst); break; } case ICAL_UTCOFFSET_VALUE: { int n, utcoffset, hours, minutes, seconds = 0; char sign; content = xmlNodeGetContent(xtype); n = sscanf((const char *) content, "%c%02d:%02d:%02d", &sign, &hours, &minutes, &seconds); if (n < 3) { syslog(LOG_WARNING, "Unexpected utc-offset format"); break; } utcoffset = hours*3600 + minutes*60 + seconds; if (sign == '-') utcoffset = -utcoffset; value = icalvalue_new_utcoffset(utcoffset); break; } default: content = xmlNodeGetContent(xtype); value = icalvalue_new_from_string(kind, (const char *) content); break; } if (content) xmlFree(content); return value; }
char* PreProcessText(char *txt) { ub4 c; char t[MAXM]; strcpy(t,txt); //Signal CAPS strcpy(t,CapsEncode(t)); //Kludge - sometimes replace_str doubles letters strcpy(t,replace_str(t,"KKQQ","KQ")); //P U N C T U A T I O N strcpy(t,replace_str(t,".","ZSTX")); strcpy(t,replace_str(t,",","ZCOX")); strcpy(t,replace_str(t,"'","ZQTX")); strcpy(t,replace_str(t,"\"","ZDQX")); strcpy(t,replace_str(t,"-","DXDX")); strcpy(t,replace_str(t,":","ZCLX")); strcpy(t,replace_str(t,";","ZSCX")); strcpy(t,replace_str(t,"/","ZSLX")); strcpy(t,replace_str(t,"?","ZQQX")); strcpy(t,replace_str(t,"!","ZLCX")); strcpy(t,replace_str(t,"(","ZBOX")); strcpy(t,replace_str(t,")","ZBCX")); strcpy(t,replace_str(t,"{","OBRACE")); strcpy(t,replace_str(t,"}","CBRACE")); strcpy(t,replace_str(t,"_","ZULX")); strcpy(t,replace_str(t,"*","ZASX")); strcpy(t,replace_str(t,"#","ZHSX")); strcpy(t,replace_str(t,"&","ZAMX")); strcpy(t,replace_str(t,"@","ZMPX")); strcpy(t,replace_str(t,"$","ZDLX")); strcpy(t,replace_str(t,"%","ZPCX")); strcpy(t,replace_str(t,"\\","ZBSX")); strcpy(t,replace_str(t,"=","ZEQX")); strcpy(t,replace_str(t,"+","ZPLX")); strcpy(t,replace_str(t,"[","OSQBRACE")); strcpy(t,replace_str(t,"]","CSQUBRACE")); strcpy(t,replace_str(t,"<","OABRACKET")); strcpy(t,replace_str(t,">","CABRACKET")); //N U M B E R S // Morse-encoded - B = dit, H = dah strcpy(t,replace_str(t,"0","JHHHHHJ")); strcpy(t,replace_str(t,"1","JBHHHHJ")); strcpy(t,replace_str(t,"2","JBBHHHJ")); strcpy(t,replace_str(t,"3","JBBBHHJ")); strcpy(t,replace_str(t,"4","JBBBBHJ")); strcpy(t,replace_str(t,"5","JBBBBBJ")); strcpy(t,replace_str(t,"6","JHBBBBJ")); strcpy(t,replace_str(t,"7","JHHBBBJ")); strcpy(t,replace_str(t,"8","JHHHBBJ")); strcpy(t,replace_str(t,"9","JHHHHBJ")); // ACCENTED CHARACTERS & DIACRITICS //Replace spaces strcpy(t,replace_str(t," ","ZX")); //Convert entire string to uppercase strcpy(t,ucase(t)); //Finally, replace any other extraneous chars with "X" for (c = 0; c<strlen(t); c++) if (!((t[c]>='A') && (t[c]<='Z'))) t[c]='X'; return t; }
static int do_referral(isieve_t *obj, char *refer_to) { int ret; struct servent *serv; isieve_t *obj_new; char *mechlist; int port; char *errstr = NULL; const char *mtried; const char *scheme = "sieve://"; char *host, *p; sasl_callback_t *callbacks; sasl_ssf_t ssf; /* check scheme */ if (strncasecmp(refer_to, scheme, strlen(scheme))) return STAT_NO; /* get host */ if ((host = strrchr(refer_to, '@'))) { char *authid, *userid; int n; *host++ = '\0'; /* get authid - make a copy so it persists for the callbacks */ authid = obj->refer_authinfo = xstrdup(refer_to + strlen(scheme)); /* get userid */ if ((userid = strrchr(authid, ';'))) *userid++ = '\0'; /* count the callbacks */ for (n = 0; obj->callbacks[n++].id != SASL_CB_LIST_END;); /* copy the callbacks, substituting some of our own */ callbacks = obj->refer_callbacks = xmalloc(n*sizeof(sasl_callback_t)); while (--n >= 0) { callbacks[n].id = obj->callbacks[n].id; switch (callbacks[n].id) { case SASL_CB_USER: callbacks[n].proc = (int (*)(void))&refer_simple_cb; callbacks[n].context = userid ? userid : authid; break; case SASL_CB_AUTHNAME: callbacks[n].proc = (int (*)(void))&refer_simple_cb; callbacks[n].context = authid; break; default: callbacks[n].proc = obj->callbacks[n].proc; callbacks[n].context = obj->callbacks[n].context; break; } } } else { host = refer_to + strlen(scheme); callbacks = obj->callbacks; } /* get port */ p = host; if (*host == '[') { if ((p = strrchr(host + 1, ']')) != NULL) { *p++ = '\0'; host++; /* skip first bracket */ } else p = host; } if ((p = strchr(p, ':'))) { *p++ = '\0'; port = atoi(p); } else { serv = getservbyname("sieve", "tcp"); if (serv == NULL) { port = 4190; } else { port = ntohs(serv->s_port); } } ret = init_net(host, port, &obj_new); if(ret) return STAT_NO; /* Start up SASL */ ret = init_sasl(obj_new, 128, callbacks); if(ret) return STAT_NO; /* Authenticate */ mechlist = read_capability(obj_new); do { mtried = NULL; ret = auth_sasl(mechlist, obj_new, &mtried, &ssf, &errstr); if (errstr) { free(errstr); errstr = NULL; } if(ret) init_sasl(obj_new, 128, callbacks); if(mtried) { char *newlist = (char*) xmalloc(strlen(mechlist)+1); char *mtr = xstrdup(mtried); char *tmp; ucase(mtr); tmp = strstr(mechlist,mtr); if (tmp) { strcpy(newlist, mechlist); tmp++; tmp = strchr(tmp, ' '); if (tmp) { strcat(newlist,tmp); } } free(mtr); free(mechlist); mechlist = newlist; } } while(ret && mtried); /* xxx leak? */ if(ret) return STAT_NO; if (ssf) { /* SASL security layer negotiated -- check if SASL mech list changed */ if (detect_mitm(obj_new, mechlist)) { free(mechlist); return STAT_NO; } } free(mechlist); /* free old isieve_t */ sieve_dispose(obj); /* Copy new isieve_t into memory used by old object */ memcpy(obj,obj_new,sizeof(isieve_t)); free(obj_new); /* Destroy the string that was allocated to save the destination server */ free(refer_to); return STAT_OK; }
/* * Construct an iCalendar property from a XML element. */ static icalproperty *xml_element_to_icalproperty(xmlNodePtr xprop) { const char *propname, *typestr; icalproperty_kind kind; icalproperty *prop = NULL; icalvalue_kind valkind; icalvalue *value; xmlNodePtr node; /* Get the property type */ propname = ucase(icalmemory_tmp_copy((const char *) xprop->name)); kind = icalenum_string_to_property_kind(propname); if (kind == ICAL_NO_PROPERTY) { syslog(LOG_WARNING, "Unknown xCal property type: %s", propname); return NULL; } /* Create new property */ prop = icalproperty_new(kind); if (!prop) { syslog(LOG_ERR, "Creation of new %s property failed", propname); return NULL; } if (kind == ICAL_X_PROPERTY) icalproperty_set_x_name(prop, propname); /* Add parameters */ node = xmlFirstElementChild(xprop); if (node && !xmlStrcmp(node->name, BAD_CAST "parameters")) { xmlNodePtr xparam; for (xparam = xmlFirstElementChild(node); xparam; xparam = xmlNextElementSibling(xparam)) { char *paramname = ucase(icalmemory_tmp_copy((const char *) xparam->name)); xmlChar *paramval = xmlNodeGetContent(xmlFirstElementChild(xparam)); /* XXX Need to handle multi-valued parameters */ icalproperty_set_parameter_from_string(prop, paramname, (const char *) paramval); xmlFree(paramval); } node = xmlNextElementSibling(node); } /* Get the value type */ if (!node) { syslog(LOG_WARNING, "Missing xCal value for %s property", propname); return NULL; } typestr = ucase(icalmemory_tmp_copy((const char *) node->name)); valkind = !strcmp(typestr, "UNKNOWN") ? ICAL_X_VALUE : icalenum_string_to_value_kind(typestr); if (valkind == ICAL_NO_VALUE) { syslog(LOG_WARNING, "Unknown xCal value type for %s property: %s", propname, typestr); return NULL; } else if (valkind == ICAL_TEXT_VALUE) { /* "text" also includes enumerated types - grab type from property */ valkind = icalproperty_kind_to_value_kind(kind); } /* Add value */ switch (kind) { case ICAL_CATEGORIES_PROPERTY: case ICAL_RESOURCES_PROPERTY: case ICAL_POLLPROPERTIES_PROPERTY: if (valkind == ICAL_TEXT_VALUE) { /* Handle multi-valued properties */ struct buf buf = BUF_INITIALIZER; xmlChar *content = NULL; content = xmlNodeGetContent(node); buf_setcstr(&buf, (const char *) content); free(content); while ((node = xmlNextElementSibling(node))) { buf_putc(&buf, ','); content = xmlNodeGetContent(node); buf_appendcstr(&buf, (const char *) content); free(content); } value = icalvalue_new_from_string(valkind, buf_cstring(&buf)); buf_free(&buf); break; } default: value = xml_element_to_icalvalue(node, valkind); if (!value) { syslog(LOG_ERR, "Parsing %s property value failed", propname); goto error; } } icalproperty_set_value(prop, value); /* Sanity check */ if ((node = xmlNextElementSibling(node))) { syslog(LOG_WARNING, "Unexpected XML element in property: %s", node->name); goto error; } return prop; error: icalproperty_free(prop); return NULL; }
SEARCHPGM *prune_criteria (char *criteria) { SEARCHPGM *pgm = NIL; char *criterion,*r,tmp[MAILTMPLEN]; int f; if (criteria) { /* only if criteria defined */ /* make writeable copy of criteria */ criteria = cpystr (criteria); /* for each criterion */ for (pgm = mail_newsearchpgm (), criterion = strtok_r (criteria," ",&r); criterion; (criterion = strtok_r (NIL," ",&r))) { f = NIL; /* init then scan the criterion */ switch (*ucase (criterion)) { case 'A': /* possible ALL, ANSWERED */ if (!strcmp (criterion+1,"LL")) f = T; else if (!strcmp (criterion+1,"NSWERED")) f = pgm->answered = T; break; case 'B': /* possible BCC, BEFORE, BODY */ if (!strcmp (criterion+1,"CC")) f = mail_criteria_string (&pgm->bcc,&r); else if (!strcmp (criterion+1,"EFORE")) f = mail_criteria_date (&pgm->before,&r); else if (!strcmp (criterion+1,"ODY")) f = mail_criteria_string (&pgm->body,&r); break; case 'C': /* possible CC */ if (!strcmp (criterion+1,"C")) f = mail_criteria_string (&pgm->cc,&r); break; case 'D': /* possible DELETED, DRAFT */ if (!strcmp (criterion+1,"ELETED")) f = pgm->deleted = T; else if (!strcmp (criterion+1,"RAFT")) f = pgm->draft = T; break; case 'F': /* possible FLAGGED, FROM */ if (!strcmp (criterion+1,"LAGGED")) f = pgm->flagged = T; else if (!strcmp (criterion+1,"ROM")) f = mail_criteria_string (&pgm->from,&r); break; case 'K': /* possible KEYWORD */ if (!strcmp (criterion+1,"EYWORD")) f = mail_criteria_string (&pgm->keyword,&r); break; case 'L': /* possible LARGER */ if (!strcmp (criterion+1,"ARGER")) f = prune_criteria_number (&pgm->larger,&r); case 'N': /* possible NEW */ if (!strcmp (criterion+1,"EW")) f = pgm->recent = pgm->unseen = T; break; case 'O': /* possible OLD, ON */ if (!strcmp (criterion+1,"LD")) f = pgm->old = T; else if (!strcmp (criterion+1,"N")) f = mail_criteria_date (&pgm->on,&r); break; case 'R': /* possible RECENT */ if (!strcmp (criterion+1,"ECENT")) f = pgm->recent = T; break; case 'S': /* possible SEEN, SENT*, SINCE, SMALLER, SUBJECT */ if (!strcmp (criterion+1,"EEN")) f = pgm->seen = T; else if (!strncmp (criterion+1,"ENT",3)) { if (!strcmp (criterion+4,"BEFORE")) f = mail_criteria_date (&pgm->sentbefore,&r); else if (!strcmp (criterion+4,"ON")) f = mail_criteria_date (&pgm->senton,&r); else if (!strcmp (criterion+4,"SINCE")) f = mail_criteria_date (&pgm->sentsince,&r); } else if (!strcmp (criterion+1,"INCE")) f = mail_criteria_date (&pgm->since,&r); else if (!strcmp (criterion+1,"MALLER")) f = prune_criteria_number (&pgm->smaller,&r); else if (!strcmp (criterion+1,"UBJECT")) f = mail_criteria_string (&pgm->subject,&r); break; case 'T': /* possible TEXT, TO */ if (!strcmp (criterion+1,"EXT")) f = mail_criteria_string (&pgm->text,&r); else if (!strcmp (criterion+1,"O")) f = mail_criteria_string (&pgm->to,&r); break; case 'U': /* possible UN* */ if (criterion[1] == 'N') { if (!strcmp (criterion+2,"ANSWERED")) f = pgm->unanswered = T; else if (!strcmp (criterion+2,"DELETED")) f = pgm->undeleted = T; else if (!strcmp (criterion+2,"DRAFT")) f = pgm->undraft = T; else if (!strcmp (criterion+2,"FLAGGED")) f = pgm->unflagged = T; else if (!strcmp (criterion+2,"KEYWORD")) f = mail_criteria_string (&pgm->unkeyword,&r); else if (!strcmp (criterion+2,"SEEN")) f = pgm->unseen = T; } break; default: /* we will barf below */ break; } if (!f) { /* if can't identify criterion */ sprintf (tmp,"Unknown search criterion: %.30s",criterion); MM_LOG (tmp,ERROR); mail_free_searchpgm (&pgm); break; } } /* no longer need copy of criteria */ fs_give ((void **) &criteria); } return pgm; }
const char * zstring::upper(){ucase();return mem_data.mem_string;}
static int macrovalue(int nargs, char *args, char *output) { char *argv[MAXARGS]; Dsarg(macname); int i; for (i = 0; i < MAXARGS; i++) { argv[i] = (char *)""; } for (i = 0; i < nargs; i++) { argv[i] = args; args += strlen(args) + 1; } /* Look up the argument function in the function table. */ Sarg(macname, 0); #ifdef CASEINS ucase(macname); #endif #ifdef DIESEL_TRACE if (tracing) { V printf("Eval: @(%s", macname); for (i = 1; i < nargs; i++) { V printf(", %s", argv[i]); } V printf(")\n"); } #endif for (i = 0; i < ELEMENTS(mftab); i++) { if (strcmp(macname, mftab[i].fname) == 0) { int mstat = (*mftab[i].ffunc)(nargs - 1, argv + 1, output); /* If the macro bailed out without supplying a diagnostic message, make up a general-purpose message here. */ if (mstat == FALSE) { V snprintf(output, MAXSTR, " @(%s,%c%c) ", macname, '?', '?'); } if (mstat != TRUE) { #ifdef DIESEL_TRACE if (tracing) { V printf("Err: %s\n", output); } #endif return DIAGNOSTIC; } #ifdef DIESEL_TRACE if (tracing) { V printf("===> %s\n", output); } #endif return TRUE; } } V snprintf(output, MAXSTR, " @(%s)?? ", macname); #ifdef DIESEL_TRACE if (tracing) { V printf("Err: %s\n", output); } #endif return DIAGNOSTIC; }