BOOL dscp_lookup(const uschar *dscp_name, int af, int *level, int *optname, int *dscp_value) { uschar *dscp_lookup, *p; int first, last; long rawlong; if (af == AF_INET) { *level = IPPROTO_IP; *optname = IP_TOS; } #if HAVE_IPV6 && defined(IPV6_TCLASS) else if (af == AF_INET6) { *level = IPPROTO_IPV6; *optname = IPV6_TCLASS; } #endif else { DEBUG(D_transport) debug_printf("Unhandled address family %d in dscp_lookup()\n", af); return FALSE; } if (!dscp_name) { DEBUG(D_transport) debug_printf("[empty DSCP]\n"); return FALSE; } dscp_lookup = expand_string(US dscp_name); if (dscp_lookup == NULL || *dscp_lookup == '\0') return FALSE; p = dscp_lookup + Ustrlen(dscp_lookup) - 1; while (isspace(*p)) *p-- = '\0'; while (isspace(*dscp_lookup) && dscp_lookup < p) dscp_lookup++; if (*dscp_lookup == '\0') return FALSE; rawlong = Ustrtol(dscp_lookup, &p, 0); if (p != dscp_lookup && *p == '\0') { /* We have six bits available, which will end up shifted to fit in 0xFC mask. RFC 2597 defines the values unshifted. */ if (rawlong < 0 || rawlong > 0x3F) { DEBUG(D_transport) debug_printf("DSCP value %ld out of range, ignored.\n", rawlong); return FALSE; } *dscp_value = rawlong << 2; return TRUE; } first = 0; last = dscp_table_size; while (last > first) { int middle = (first + last)/2; int c = Ustrcmp(dscp_lookup, dscp_table[middle].name); if (c == 0) { *dscp_value = dscp_table[middle].value; return TRUE; } else if (c > 0) { first = middle + 1; } else { last = middle; } } return FALSE; }
static int set_name(void *data, Char *pathname) { EDITINFO *einf = (EDITINFO *) data; XTextProperty prop_name; Char *name; int namesize; Char *stripname, *nname; if (pathname == NULL) { EDITINFO *tinf; FlexArray istck; int i=0,j; int_init(istck); while (aig(tinf=(EDITINFO*)next_data_with_type(MAINEDITWINDOW, &i))) { if (!Ustrncmp(translate(EMPTYFILE),tinf->filename, Ustrlen(translate(EMPTYFILE)))) { j = Ustrtol(tinf->filename+Ustrlen(translate(EMPTYFILE)), NULL, 10); int_add(istck, j); } i++; } i=1; while (int_contains(istck,i)) i++; int_clear(istck); nname = (Char *) malloc(sizeof(Char)*(Ustrlen(userdir) + Ustrlen(translate("/" EMPTYFILE)) + 5 +Ustrlen(translate(EXTENSION)))); concat_in(nname, userdir, translate("/" EMPTYFILE)); stripname = nname + Ustrlen(nname); { Char sb[40]; Char *s; sb[39]=0; s=Ultostr(i,sb+39); Ustrcat(stripname,s); } Ustrcat(stripname, translate(EXTENSION)); } else nname = pathname; stripname = concat(strip_name(nname),NULL); if (!Ustrcmp(stripname+Ustrlen(stripname)-Ustrlen(translate(EXTENSION)), translate(EXTENSION))) stripname[Ustrlen(stripname)-Ustrlen(translate(EXTENSION))] = 0; namesize = Ustrlen(translate(EDITNAME)) + Ustrlen(stripname) + 1 + (einf->saved ? 0 : Ustrlen(translate(CHANGED))) + (einf->view_mode && !einf->shell ? Ustrlen(translate(VIEWCOM)) : 0) + (einf->shell && !einf->fini ? Ustrlen(translate(RUNCOM)) : 0) + (einf->shell && einf->fini ? Ustrlen(translate(DONECOM)) : 0); name = (Char *) malloc((size_t) namesize*sizeof(Char) ); if (name) { name[0]= '\0'; Ustrcat(name, translate(EDITNAME)); Ustrcat(name, stripname); if (!einf->saved && !einf->shell) Ustrcat(name, translate(CHANGED)); if (einf->view_mode && !einf->shell) Ustrcat(name, translate(VIEWCOM)); if (einf->shell && !einf->fini) Ustrcat(name, translate(RUNCOM)); if (einf->shell && einf->fini) Ustrcat(name, translate(DONECOM)); } { char *n; n= (char*)UstrtoLocale(name); if (!name || !XStringListToTextProperty(&n, 1, &prop_name)) { message(MP_ERROR, translate("No location for editname.")); return 0; } } XSetWMName(display, einf->win_id, &prop_name); free(einf->headername); if (einf->pathname!=nname) free(einf->pathname); free(einf->filename); einf->headername = name; einf->filename = stripname; einf->pathname = nname; { char *icn; icn = (char*)UstrtoLocale(stripname); if (!XStringListToTextProperty(&icn, 1, &prop_name)) { message(MP_ERROR, translate("No location for editicon.")); return 0; } } XSetWMIconName(display, einf->win_id, &prop_name); return 1; }