Пример #1
0
void			getmalloc_conf()
{
  extern malloc_conf	myconf;
  char			buffer[4096];
  int			len_read;
  register int		i_buffer;
  int			i_conf;

  if ((len_read = getconffile(buffer)) == -1)
    return ;
  for (i_buffer = 0; i_buffer < len_read; ++i_buffer)
    {
      i_conf = 0;
      while (confmalloc[i_conf].name && 
	     !strfind(buffer + i_buffer, confmalloc[i_conf].name))
	++i_conf;
      if (confmalloc[i_conf].name)
	{
	  i_buffer += confmalloc[i_conf].len_name;
	  if (confmalloc[i_conf].nbr)
	    {
	      myconf.info |= confmalloc[i_conf].byte;
	      *(confmalloc[i_conf].nbr) = get_nbr(buffer + i_buffer, '\n');
	    }
	  else if (strfind(buffer + i_buffer, "yes"))
	    myconf.info |= confmalloc[i_conf].byte;
	}
      while (buffer[i_buffer] != '\n' && i_buffer < len_read)
	++i_buffer;
    }
}
Пример #2
0
int main(int argc, char* argv[]) {

    for (int i = 0; i < RSN_ENTRIES; i++) {
        rsnEntries[i] = NULL;
        rsnSize[i] = 0;
    }
    rsnInfo = NULL;

    resetRsnEntries();
    printf("\nUnrar Into Memory Learn 1.0\n\n");

    rarFileData.ArcName = "test.rar";
    rarFileData.OpenMode = RAR_OM_EXTRACT;
    rarHandle = RAROpenArchive(&rarFileData);

    printf("Opening test.rar: %d\n", rarFileData.OpenResult);

    if (rarFileData.OpenResult == ERAR_SUCCESS) {
        printf("-->Success\n");

        int res = RARReadHeader(rarHandle, &rarFileHeader);
        while(res == ERAR_SUCCESS) {
            printf("Header '%s' -> %d -> %d Bytes\n", rarFileHeader.FileName, res, rarFileHeader.UnpSize);
            if (strfind(rarFileHeader.FileName, ".spc") != NULL && rsnCount < RSN_ENTRIES && rarFileHeader.UnpSize > 66000 && rarFileHeader.UnpSize < 67000) {
                printf("--> SPC File, going to extract\n");
                rsnEntries[rsnCount] = (char*)malloc(rarFileHeader.UnpSize);
                if (rsnEntries[rsnCount] != NULL) {
                    printf("--> Pointer to memory: %p\n", rsnEntries[rsnCount]);
                    RARSetCallback(rarHandle, rarExtractSpcBytes, (long)rsnEntries[rsnCount]);
                    RARProcessFile(rarHandle, RAR_EXTRACT, NULL, NULL);
                    rsnSize[rsnCount] = rarFileHeader.UnpSize;
                    rsnCount++;
                }
            } else if (strfind(rarFileHeader.FileName, ".txt") != NULL && rsnInfo == NULL && rarFileHeader.UnpSize < 10000) {
                printf("--> TXT File, going to extract\n");
                rsnInfo = (char*)calloc(rarFileHeader.UnpSize + 1, 1);
                if (rsnInfo != NULL) {
                    RARSetCallback(rarHandle, rarExtractInfoBytes, (long)rsnInfo);
                    RARProcessFile(rarHandle, RAR_EXTRACT, NULL, NULL);
                }
            } else {
                printf("--> Skip\n");
                RARProcessFile(rarHandle, RAR_SKIP, NULL, NULL);
            }
            res = RARReadHeader(rarHandle, &rarFileHeader);
        }
        printf("Result: %d\n", res);
    }
    RARCloseArchive(rarHandle);

    printf("Tracks: %d\n", rsnCount);
    printf("Info: %d\n\n%s\n", rsnInfo == NULL ? 0 : strlen(rsnInfo), rsnInfo == NULL ? "<?>" : rsnInfo);

    return 0;
}
Пример #3
0
/* Remove all instances of substring ss in string s, modifying s in place.
 */
void CleanString(char *s, const char *ss) {
  size_t sslen = strlen(ss);
  char *fs = (char*) strfind(s, ss);

  while (fs != NULL) {
    do {
      fs[0] = fs[sslen];
      fs++;
    } while (*fs != '\0');
    fs = (char*) strfind(s, ss);
  }
}
Пример #4
0
/**
 * takes a string that is a supposed file path, and 
 * checks for certian wildcards ( like ~ for home directory ) 
 * and resolves to an actual absolute path.
**/
dstrbuf *
expandPath(const char *path)
{
	struct passwd *pw = NULL;
	dstrbuf *tmp = DSB_NEW;
	dstrbuf *ret = DSB_NEW;

	dsbCopy(tmp, path);

	if (tmp->len > 0 && tmp->str[0] == '&') {
		dsbCopy(ret, EMAIL_DIR);
	} else if (tmp->len > 0 && tmp->str[0] == '~') {
		if (tmp->str[1] == '/') {
			pw = getpwuid(getuid());
		} else {
			int pos = strfind(tmp->str, '/');
			if (pos >= 0) {
				char *p = substr(tmp->str, 1, pos-1);
				if (p) {
					pw = getpwnam(p);
					xfree(p);
				}
			}
			if (!pw) {
				pw = getpwuid(getuid());
			}
		}
		if (pw) {
			dsbCopy(ret, pw->pw_dir);
		}
	}

	
	if (ret->len > 0) {
		int pos = strfind(tmp->str, '/');
		if (pos > 0) {
			char *p = substr(tmp->str, pos, tmp->len);
			if (p) {
				dsbCat(ret, p);
				xfree(p);
			}
		}
	} else {
		dsbCopy(ret, path);
	}

	dsbDestroy(tmp);
	return ret;
}
Пример #5
0
int mbus_addr_match(const char *a, const char *b)
{
	/* Compare the addresses "a" and "b". These may optionally be */
	/* surrounded by "(" and ")" and may have an arbitrary amount */
	/* of white space between components of the addresses. There  */
	/* is a match if every word of address b is in address a.     */
	const char	*y = NULL; 

	assert(a != NULL);
	assert(b != NULL);

	/* Skip leading whitespace and '('... */
	while (isspace((unsigned char)*a) || (*a == '(')) a++;
	while (isspace((unsigned char)*b) || (*b == '(')) b++;

	while ((*b != '\0') && (*b != ')')) {
		/* Move b along through the string to the start of the next */
		/* word. Move y along from that to the end of the word.     */
		while (isspace((unsigned char)*b)) b++;
		for (y = b; ((*y != ' ') && (*y != ')') && (*y != '\0')); y++) {
			/* do nothing */
		}
		if(y == b)
		      return TRUE;
		y--;
		/* Check if the word between b and y is contained in the    */
		/* string pointed to be a.                                  */
		if (!strfind(a, b, y)) {
			return FALSE;
		}
		b = ++y;
	}		
	return TRUE;
}
Пример #6
0
/* Get To tag */
static str
getToAddress(struct sip_msg *msg)
{
    static char buf[16] = "unknown"; // buf is here for a reason. don't
    static str notfound = {buf, 7};  // use the constant string directly!
    str uri;
    char *ptr;

    if (!msg->to) {
        LOG(L_ERR, "error: mediaproxy/getToAddress(): missing To: field\n");
        return notfound;
    }

    uri = get_to(msg)->uri;

    if (uri.len == 0)
        return notfound;

    if (strncmp(uri.s, "sip:", 4)==0) {
        uri.s += 4;
        uri.len -= 4;
    }

    if ((ptr = strfind(uri.s, uri.len, ";", 1))!=NULL) {
        uri.len = ptr - uri.s;
    }

    return uri;
}
Пример #7
0
int main(int argc, char *argv[]) {
  int debug;
  char *s1, *s2, *s3;

  s1 = readLine();
  s2 = readLine();

  debug = letter_qnt(s1);
  printf("s1 size = %d\n", debug);
  debug = letter_qnt(s2);
  printf("s2 size = %d\n", debug);

  debug = strfind(s1, s2);
  printf("S1 is found? %d\n", debug);

  debug = strcmp(s1, s2);
  printf("Comparison: %d\n", debug);

  s3 = strcat(s1, s2);
  debug = letter_qnt(s3);
  printf("New string: %s\nNew string size: %d\n", s3, debug);
  
  erase(s1);
  erase(s2);
  erase(s3);
  
  return 0;
}
Пример #8
0
static str
getFromAddress(struct sip_msg *msg)
{
    static char buf[16] = "unknown"; // buf is here for a reason. don't
    static str notfound = {buf, 7};  // use the constant string directly!
    str uri;
    char *ptr;

    if (parse_from_header(msg) < 0) {
        LM_ERR("cannot parse the From header\n");
        return notfound;
    }

    uri = get_from(msg)->uri;

    if (uri.len == 0)
        return notfound;

    if (strncmp(uri.s, "sip:", 4)==0) {
        uri.s += 4;
        uri.len -= 4;
    }

    if ((ptr = strfind(uri.s, uri.len, ";", 1))!=NULL) {
        uri.len = ptr - uri.s;
    }

    return uri;
}
Пример #9
0
int tags::Vorbis::readVorbisTagSoup(FILE *fd, char **soup)
{
    *soup = (char*) malloc(1024 * 1024);  // ought to be large enough

    int offset = 0;
    int cnt = 0;
    while (true)
    {
        char block[512];
        if (fread(block, 1, 512, fd) == 0 || cnt > 10)
        {
            break;
        }

        memcpy(*soup + offset, block, 512);
        offset += 512;

        char mark[] = { 5, 'v', 'o', 'r', 'b', 'i', 's' };
        int pos = strfind(*soup, mark, offset + 512, 7);
        if (pos != -1)
        {
            return pos;
        }

        cnt++;
    }

    return 0;
}
Пример #10
0
tags::Vorbis::Vorbis(FILE *fd, QMap<QString, QByteArray> &tags)
    : myTags(tags)
{
    char *soup;
    int size = 0;

    char buf[4];
    fread(buf, 1, 4, fd);

    if (buf[0] == 'f' && buf[1] == 'L' &&
        buf[2] == 'a' && buf[3] == 'C')
    {
        // it's FLAC
        size = readFlacTagSoup(fd, &soup);
    }
    else
    {
        char header[1024];
        char mark[] = { 3, 'v', 'o', 'r', 'b', 'i', 's' };

        fseek(fd, 0, SEEK_SET);
        fread(header, 1, 1024, fd);

        int pos = strfind(header, mark, 1024, 7);
        if (pos != -1)
        {
            // it's Ogg Vorbis
            fseek(fd, pos + 7, SEEK_SET);
            size = readVorbisTagSoup(fd, &soup);
        }
    }

    if (size > 0)
        parseTagSoup(soup, size);
}
Пример #11
0
/* If string ss appears in string s, return a pointer to the first byte
 * after ss. Otherwise return NULL.
 */
const char *strskip(const char *s, const char *ss) {
  const char *tmp = strfind(s, ss);
  if (tmp != NULL) {
    return &tmp[strlen(ss)];
  }
  return NULL;
}
Пример #12
0
jint Java_de_illogical_modo_SpcDecoder_spcLoadRSN(JNIEnv* env, jclass clazz, jstring path)
{
	char cpath[1024];
	memset(cpath, 0, 1024);

	int clen = (*env)->GetStringLength(env, path);
	(*env)->GetStringUTFRegion(env, path, 0, clen, cpath);
	
	rarFileData.ArcName = cpath;
	rarFileData.OpenMode = RAR_OM_EXTRACT;
	rarHandle = RAROpenArchive(&rarFileData);

	if (rarFileData.OpenResult == ERAR_SUCCESS)
	{
		int res = RARReadHeader(rarHandle, &rarFileHeader);
		while(res == ERAR_SUCCESS)
		{
			if (strfind(rarFileHeader.FileName, ".spc") != NULL && rsnCount < RSN_ENTRIES && rarFileHeader.UnpSize > 66000 && rarFileHeader.UnpSize < 67000)
			{
				rsnEntries[rsnCount] = (char*)malloc(rarFileHeader.UnpSize);
				if (rsnEntries[rsnCount] != NULL) {
					rarExtractSpcBytes(0xFFFF, 0, 0, 0);
					RARSetCallback(rarHandle, rarExtractSpcBytes, (long)rsnEntries[rsnCount]);
					RARProcessFile(rarHandle, RAR_EXTRACT, NULL, NULL);
					rsnSize[rsnCount] = rarFileHeader.UnpSize;
					rsnCount++;
				} 
			} else if (strfind(rarFileHeader.FileName, ".txt") != NULL && rsnInfo == NULL && rarFileHeader.UnpSize < 10000)
			{
				rsnInfo = (char*)calloc(rarFileHeader.UnpSize + 1, 1);
				if (rsnInfo != NULL) {
					rarExtractInfoBytes(0xFFFF, 0, 0, 0);
					RARSetCallback(rarHandle, rarExtractInfoBytes, (long)rsnInfo);
					RARProcessFile(rarHandle, RAR_EXTRACT, NULL, NULL);
				}
			} else
			{
				RARProcessFile(rarHandle, RAR_SKIP, NULL, NULL);
			}
			res = RARReadHeader(rarHandle, &rarFileHeader);
		}
	}
	RARCloseArchive(rarHandle);

	return rsnCount;	
}
Пример #13
0
void mix_genericerror(void)
{
  if (streq(statusline, "") || strfind(statusline, "...") ||
      strifind(statusline, "generating"))
    mix_status("Failed!");
  else
    mix_status(NULL);
}
Пример #14
0
int rech_repl(char *ancien,char *nouveau,char *fichier)
{
 FILE *fich;
 FILE *temp;
 char temp_nom[64];
 char ligne[512];
 char result[512];
 int debut,debut_r,depl,nolgn,ctrl,nbr_repl=0;
 int err=0;
 mk_temp_name(temp_nom,fichier);
 if((fich=fopen(fichier,"rt"))!=NULL)
 {
  if((temp=fopen(temp_nom,"wt"))!=NULL)
  {
   while(fgets(ligne,512,fich)!=NULL)
   {
    nolgn++;
    debut=0;
    debut_r=0;
    depl=0;
    while((depl=strfind(ligne+debut,ancien))>=0)
    {
     strncpy(result+debut_r,ligne+debut,depl);
     debut_r+=depl;
     strcpy(result+debut_r,nouveau);
     debut_r+=strlen(nouveau);
     debut+=(depl+strlen(ancien));
     nbr_repl++;
    }
    strcpy(result+debut_r,ligne+debut);
    ctrl=fputs(result,temp);
    if(ctrl==EOF)
    {
     err=-3;
     break;
    }
    if(debut!=0)
    {
     printf("%4d %s    %s",nolgn,ligne,result);
    }
   }
   fclose(temp);
  }
  else err=-1;
  fclose(fich);
  if(!err)
  {
   unlink(fichier);
   rename(fichier,temp_nom);
   err=nbr_repl;
  }
 }
 else err=-2;
 return(err);
}
Пример #15
0
void tags::Vorbis::parseTagSoup(char *soup, int size)
{
    char nullTriple[] = { 0, 0, 0 };
    // iterate over entries

    int offset = 1; // skip the first
    while (soup[offset] == 0) offset++;

    qDebug() << QByteArray(soup, size);

    while (offset < size)
    {
        int entrySize = 0;
        int pos = strfind(soup + offset, nullTriple, size - offset, 3);
        if (pos != -1)
        {
            entrySize = pos - 1; // skip the last
        }
        else
        {
            entrySize = size - offset;
        }

        qDebug() << QByteArray(soup + offset, entrySize);
        int equalsPos = strfind(soup + offset, "=", entrySize, 1);
        if (equalsPos != -1)
        {
            int keySize = equalsPos;
            int valueSize = entrySize - keySize - 1;

            char key[keySize];
            char value[valueSize];
            memcpy(key, soup + offset, keySize);
            memcpy(value, soup + offset + keySize + 1, valueSize);

            myTags[QString(QByteArray(key, keySize)).toUpper()] =
                    QByteArray(value, valueSize);
        }

        offset += entrySize + 4;
    }
}
Пример #16
0
/*
  get a much bigger step for *.
  */
static inline int  patternStep( const char * s, const  char * p)
{
    char temp[8];
    int step=0;
    const char * t=p;
    while(*t!='*' && *t!='^' && *t!='\0')
    {
        step++;
        t++;
    }
    if(!step) //just one character ,such as ^,*
        return 1;
    memset(temp,0,sizeof(temp));
    strncpy_s(temp,p,abpmin(sizeof(temp)-1,step));
    //printf("temp=%s,step=%d\n",temp,step);
    const char * res=strfind(s,temp);
    if(!res) //没有找到
        return strlen(s); //移动整个字符串
    else
        return abpmax(1,res-s); //找到第一个匹配的字符串的位置
}
Пример #17
0
/* Find a line in str `block' that starts with `start'. */
static char*
findLineStartingWith(str *block, char *start, int ignoreCase)
{
    char *ptr, *bend;
    str zone;
    int tlen;

    bend = block->s + block->len;
    tlen = strlen(start);
    ptr = NULL;

    for (zone = *block; zone.len > 0; zone.len = bend - zone.s) {
        if (ignoreCase)
            ptr = strcasefind(zone.s, zone.len, start, tlen);
        else
            ptr = strfind(zone.s, zone.len, start, tlen);
        if (!ptr || ptr==zone.s || ptr[-1]=='\n' || ptr[-1]=='\r')
            break;
        zone.s = ptr + tlen;
    }

    return ptr;
}
Пример #18
0
/* Returns a function pointer for a function name matching the given string. */
void *debug_get_fn_addr(char *fn_name)
{
	const struct stab *stab_end = __STAB_END__;
	const struct stab *stabs = __STAB_BEGIN__;
	const char *stabstr_end = __STABSTR_END__;
	const char *stabstr = __STABSTR_BEGIN__;

	static int first_fn_idx = 0;
	int i = first_fn_idx;
	int len;
	const char *stab_fn_name = 0;
	void *retval = 0;

	if (!stab_table_valid(stabstr, stabstr_end))
		return 0;

	for (/* i set */; &stabs[i] < stab_end; i++) {
		if (stabs[i].n_type != N_FUN)
			continue;
		first_fn_idx = first_fn_idx ? first_fn_idx : i;
		/* broken stab, just keep going */
		if (!(stabs[i].n_strx < stabstr_end - stabstr))
			continue;
		stab_fn_name = stabstr + stabs[i].n_strx;
		len = strfind(stab_fn_name, ':') - stab_fn_name;
		if (!len)
			continue;
		/* we have a match. */
		if (!strncmp(stab_fn_name, fn_name, len)) {
			printd("FN name: %s, Addr: %p\n", stab_fn_name, stabs[i].n_value);
			retval = (void*)stabs[i].n_value;
			break;
		}
	}
	return retval;
}
Пример #19
0
int exec_load_chrp (inode_t *file, void **dest, void **entry, void **end,
                    uint32_t loffset)
{
#define TMPNAME_LEN 512
    unsigned char tmpname[TMPNAME_LEN], *tmpp, *buf, *pos, *endc, c;
    XML_tag_t *tag, *tmp, *first;
    part_t *part;
    inode_t *inode;
    int state;
    int script_type = CHRP_SCRIPT_IGNORE;
    uint32_t crc, offset = 0;
    int ret, rel = 0;

    buf = malloc(16384);
    /* Check the file head */
    file_seek(file, loffset);
    fs_read(file, buf, 11);
    if (memcmp(buf, "<CHRP-BOOT>", 11) != 0) {
        ERROR("Not an Apple CHRP boot file !\n");
        return -2;
    }
    /* Re-seek at start of the file and start parsing it */
    file_seek(file, loffset);
    pos = buf;
    tag = NULL;
    first = NULL;
    ret = -1;
    fs_read(file, &c, 1);
    offset++;
    for (state = XML_STATE_TAG; state != XML_STATE_OUT;) {
        /* Get next char */
        fs_read(file, &c, 1);
        offset++;
        if ((state == XML_STATE_TAG && c != '>') ||
            (state == XML_STATE_DATA && c != '<')) {
            *pos++ = c;
            continue;
        }
        *pos++ = '\0';
        switch (state) {
        case XML_STATE_TAG:
            if (*buf == '/') {
                if (tag == NULL || strcmp(buf + 1, tag->name) != 0) {
                    ERROR("XML error: open name: '%s' close name: '%s'\n",
                          buf + 1, tag->name);
                    goto out;
                }
                DPRINTF("Close tag: '%s'\n", tag->name);
                switch (XML_get_type(tag->name)) {
                case CHRP_TAG_CHRP_BOOT:
                    /* Nothing to do */
                    break;
                case CHRP_TAG_COMPATIBLE:
                    /* Won't check... */
                    pos = tag->data;
                    if (*(char *)tag->data == 0x0d) {
                        pos++;
                    }
                    DPRINTF("Compatible: '%s'\n", pos);
                    break;
                case CHRP_TAG_DESCRIPTION:
                    pos = tag->data;
                    if (*(char *)tag->data == 0x0d) {
                        pos++;
                    }
                    DPRINTF("Description: '%s'\n", pos);
                    break;
                case CHRP_TAG_BOOT_SCRIPT:
                    /* Here is the interresting part... */
                    crc = crc32(0, tag->data, tag->dlen);
#if 0
                    DPRINTF("Forth script: %08x\n%s\n",
                            crc, (char *)tag->data);
#endif
                    switch (crc) {
                    case 0x5464F92C:
                        /* Mandrake 9.1 CD1 boot script */
                    case 0x4BC74ECF:
                        /* Mandrake 10.1 & 10.2 CD1 boot script */
                    case 0x5B265246:
                        /* Gentoo 1.2-r1 */
                        /* Gentoo 2004.1 minimal install CD */
                        /* Gentoo 1.4 live CDROM */
                        /* Knopix PPC beta-pre12 */
                    case 0x75420D8A:
                        /* Debian woody */
                        /* Debian 3.0r1 */
                        script_type = CHRP_SCRIPT_LOAD_BOOT;
                        goto do_script;
                    case 0x633e4c9c:
                        /* Debian Sarge */
                    case 0xbe3abf60:
                        /* Debian Sarge, installed on a hard disk drive */
                        script_type = CHRP_SCRIPT_LOAD_BOOT;
                        goto do_script;
                    case 0x07b86bfe:
                        /* Linux Fedora Core 3 */
                        script_type = CHRP_SCRIPT_LOAD_BOOT;
                        goto do_script;
                    case 0x9ccdf371:
                        script_type = CHRP_SCRIPT_LOAD_BOOT;
                        goto do_script;
                    case 0xEF423926:
                        /* OpenBSD 3.4 */
                    case 0x68e4f265:
                        /* OpenBSD 3.5 */
                    case 0x3b7ea9e1:
                        /* OpenBSD 3.6 */
                        script_type = CHRP_SCRIPT_LOAD_BOOT;
                        goto do_script;
                    case 0xB7981DBC:
                        /* iBook 2 hw test CDROM */
#if 1
                        script_type = CHRP_SCRIPT_LOAD_BOOT;
                        goto do_script;
#endif
                        
                    case 0xEA06C1A7:
                        /* MacOS 9.2 boot script:
                         * the XCOFF loader is embedded in the file...
                         */
                    case 0x53A95958:
                        /* iBook 2 restore CD (MacOS X 10.2) */
                        script_type = CHRP_SCRIPT_EMBEDDED;
                        pos = strfind(tag->data, "elf-offset");
                        if (pos != NULL) {
                            /* Go backward until we get the value */
                            for (--pos; *pos < '0' || *pos > '9'; pos--)
                                continue;
                            for (; *pos >= '0' && *pos <= '9'; pos--)
                                continue;
                            offset = strtol(pos, NULL, 16);
                            goto do_script;
                        }
                        ERROR("Didn't find boot file offset\n");
                        goto out;
                    case 0x8d5acb86:
                        /* Darwin-7.01
                         * The executable file is embedded after the script
                         */
                        script_type = CHRP_SCRIPT_EMBEDDED;
                        DPRINTF("Boot file embedded at the end of boot script\n");
                        break;
                    default:
                        ERROR("XML error: unknown Forth script: %08x\n%s\n",
                              crc, (char *)tag->data);
                        goto out;
                    }
                    break;

                do_script:
                    switch (script_type) {
                    case CHRP_SCRIPT_LOAD_BOOT:
                        pos = strfind(tag->data, "boot");
                        if (pos != NULL) {
                            /* Eat everything until file name */
                            for (pos += 4; *pos != ','; pos++)
                                continue;
                            /* Eat ',' */
                            for (++pos; isspace(*pos) || *pos == '"'; pos++)
                                continue;
                            /* Find file name end */
                        redo:
                            for (endc = pos;
                                 *endc != ' ' && *endc != '"' &&
                                 *endc != '\n' && *endc != '\r';
                                 endc++) {
                                if (*endc == '\\')
                                    *endc = '/';
                            }
                            if (memcmp(pos, "ofwboot", 7) == 0) {
                                for (pos = endc + 1; *pos == ' '; pos++)
                                    continue;
                                goto redo;
                            }
                            *endc = '\0';
                        }
                        DPRINTF("Real boot file is: '%s'\n", pos);
                        part = fs_inode_get_part(file);
                        /* check if it's a path or just a file */
                        tmpp = pos;
                        if ((pos[0] == '/' && pos[1] == '/') ||
                            pos[0] != '/') {
                            unsigned char *bootdir;
                            bootdir = fs_get_boot_dirname(part_fs(part));
                            if (bootdir == NULL) {
                                ERROR("Cannot get boot directory name\n");
                                bug();
                            }
                            snprintf(tmpname, TMPNAME_LEN,
                                     "%s/%s", bootdir, pos);
                            tmpname[TMPNAME_LEN - 1] = '\0';
                            rel++;
                            pos = tmpname;
                            DPRINTF("'%s' => '%s'\n", bootdir, pos);
                        }
                    retry:
                        inode = fs_open(part_fs(part), pos);
                        if (inode == NULL) {
                            ERROR("Real boot inode '%s' not found\n", pos);
                            /* Try in root directory */
                            if (rel == 1) {
                                for (; *tmpp == '/'; tmpp++)
                                    continue;
                                snprintf(tmpname, TMPNAME_LEN, "/%s", tmpp);
                                tmpname[TMPNAME_LEN - 1] = '\0';
                                rel++;
                                goto retry;
                            }
                            
                            bug();
                        }
                        ret = _bootfile_load(inode, dest, entry, end, 0, -1);
                        fs_close(inode);
                        goto out;
                    case CHRP_SCRIPT_EMBEDDED:
                        DPRINTF("Exec offset: %d %08x\n", offset, offset);
                        ret = 0;
                        goto out;
                    case CHRP_SCRIPT_IGNORE:
                        break;
                    }
                    break;
                case CHRP_TAG_OS_BADGE_ICONS:
                case CHRP_TAG_ICON:
                    /* Ignore it */
                    break;
                case CHRP_TAG_BITMAP:
                    /* Ignore it */
                    break;
                case CHRP_TAG_LICENSE:
                    /* Ignore it */
                    pos = tag->data;
                    if (*(char *)tag->data == 0x0d) {
                        pos++;
                    }
                    DPRINTF("License: '%s'\n", pos);
                    break;
                default:
                    ERROR("XML error: unknown tag: '%s'\n", tag->name);
                    goto out;
                }
                tmp = tag->up;
                if (tmp == NULL)
                    state = XML_STATE_OUT;
                else
                    state = XML_STATE_DATA;
                free(tag->name);
                free(tag->data);
                free(tag);
                tag = tmp;
            } else {
                tmp = malloc(sizeof(XML_tag_t));
                if (tmp == NULL) {
                    ERROR("Cannot allocate new tag\n");
                    goto out;
                }
                tmp->up = tag;
                /* Ignore tag attributes */
                pos = strchr(buf, ' ');
                if (pos != NULL)
                    *pos = '\0';
                tmp->name = strdup(buf);
                tag = tmp;
                if (first == NULL)
                    first = tag;
                DPRINTF("Open tag '%s'\n", tag->name);
                state = XML_STATE_DATA;
            }
            break;
        case XML_STATE_DATA:
            if (tag->data == NULL) {
                tag->dlen = pos - buf;
                tag->data = malloc(tag->dlen);
                memcpy(tag->data, buf, tag->dlen);
            }
            state = XML_STATE_TAG;
            break;
        }
        pos = buf;
    }
    ret = 0;
    fs_read(file, &c, 1);
    fs_read(file, &c, 1);
    offset += 2;
 out:
#if 1
    for (; tag != NULL; tag = tmp) {
        tmp = tag->up;
        free(tag->name);
        free(tag->data);
        free(tag);
    }
#endif
    if (ret == 0 && script_type == CHRP_SCRIPT_EMBEDDED) {
        DPRINTF("Load embedded file from offset %d (%d => %d)\n",
                offset, loffset, loffset + offset);
        ret = _bootfile_load(file, dest, entry, end, loffset + offset, -1);
    }
    DPRINTF("Done\n");

    return ret;
}
Пример #20
0
int main ()
{
    char bob [] = "jelly";
    printf("%c", *strfind(bob, 'l'));
    return 0;
}
Пример #21
0
static bool _check_extension(const char* name) {
    static const char* exts = NULL;
    if(exts == NULL)
        exts = (char*)glGetString(GL_EXTENSIONS);
    return strfind(name, exts) != -1;
}
Пример #22
0
int main()
{
    printf("%s\n",strfind("aasdf", "s") );
	printf("%s\n",strfind("aasdf", "as") );
	printf("%s\n",strfind("aasdf", "f") );
}
Пример #23
0
uint32_t calc(int argc, char* argv[]) {
    calcErrFlag = 0;
    int now = 0;
    for(int i = 1; i < argc; ++i) 
        for(int j = 0; argv[i][j]; ++j)
            buf[now++] = argv[i][j];
    buf[now] = 0;
    cprintf("%s : ", buf);
    now = 0;
    for(int i = 0; buf[i]; ++i) {
        int flag = 0;
        for(int j = 0; j < NOPERATORS; ++j) {
            if(buf[i] == operator[j].symbol[0]) {
                flag = 1;
                calcBuf[now++] = buf[i];
                if(buf[i + 1] == '<' || buf[i + 1] == '>' )
                    break;
                calcBuf[now++] = ' ';
                break;
            }
        }
        if(flag)
            continue;
        if('0' <= buf[i] && buf[i] <= '9') {
            while(  buf[i] == 'x' ||
                    '0' <= buf[i] && buf[i] <= '9' || 
                    'a' <= buf[i] && buf[i] <= 'f' || 
                    'A' <= buf[i] && buf[i] <= 'F' ) {
                calcBuf[now++] = buf[i++];
            }
            calcBuf[now++] = ' ';
            i --;
            continue;
        }
        flag = *strfind(reservedChars, buf[i]);
        if(flag) {
            cprintf("Invalid character: %c\n", buf[i]);
            calcErrFlag = -1;
            return -1;
        }
        while(1) {
            flag = *strfind(reservedChars, buf[i]);
            if(!flag && buf[i])
                calcBuf[now++] = buf[i++];
            else {
                calcBuf[now++] = ' ', i--;
                break;
            }
        }
    }
    calcBuf[now] = 0;
    // cprintf("%s\n", calcBuf);
    char** calcComp = split(calcBuf);
    stackn = 0;
    valuen = 0;
    int m = 0;
    for(int i = 0; calcComp[i]; ++i) {
        m = i;
        int j;
        if((j = findOpt(calcComp[i])) != -1) {
            if(operator[j].type == OPT_LBRACE || operator[j].type == OPT_RBRACE)
                calcMark[i] = operator[j].type;
            else if(i == 0 || 
                    calcMark[i-1] == OPT_UNO || 
                    calcMark[i-1] == OPT_BINARY ||
                    calcMark[i-1] == OPT_LBRACE)
                calcMark[i] = OPT_UNO;
            else
                calcMark[i] = OPT_BINARY;
            continue;
        }
        if('0' <= calcComp[i][0] && calcComp[i][0] <= '9') {
            calcMark[i] = OPT_VALUE;
            continue;
        }
        calcMark[i] = OPT_SYMBOL;
    }
    /*
    for(int i = 0; i <= m; ++i) 
        cprintf("%d ", calcMark[i]);
    cprintf("\n");
    */
    for(int i = m; i >= 0; --i) {
        //printCalcStack();
        int j;
        struct DebugInfo* p;    
        switch(calcMark[i]) {
            case OPT_UNO:
                j = findSpecOpt(calcComp[i], OPT_UNO);
                if(j == -1) {
                    cprintf("Invalid expression!\n");
                    calcErrFlag = -1;
                    return -1;
                }
                calcStack[++stackn] = operator[j];
                doCalc();
            break;
            case OPT_BINARY:
                j = findSpecOpt(calcComp[i], OPT_BINARY);
                if(j == -1) {
                    cprintf("Invalid expression!\n");
                    calcErrFlag = -1;
                    return -1;
                }
                while(  stackn > 0 &&
                        calcStack[stackn].type == OPT_BINARY && 
                        calcStack[stackn].priority > operator[j].priority)
                    doCalc();
                calcStack[++stackn] = operator[j];
            break;
            case OPT_LBRACE:
                while(calcStack[stackn].type != OPT_RBRACE)
                    doCalc();
                stackn--;
            break;
            case OPT_RBRACE:
                calcStack[++stackn].type = OPT_RBRACE;
            break;
            case OPT_VALUE:
                calcValue[++valuen] = strToInt(calcComp[i]);
            break;
            case OPT_SYMBOL:
                p = findSymbol(pinfo.pc, calcComp[i]);
                if(p == 0) {
                    cprintf("Cannot find symbol: %s\n", calcComp[i]);
                    calcErrFlag = -1;
                    return -1;
                }
                uint32_t vaddr = p->vaddr;
                int type = 0;
                if(p->type != N_GSYM)
                    type = 1;
                subArgv[0] = vaddr;
                subArgv[1] = buf;
                subArgv[2] = type;
                subArgv[3] = 0;
                int result = doSysDebug(DEBUG_PRINT, subArgv);
                if(result < 0) {
                    cprintf("%s", subArgv[1]);
                    calcErrFlag = -1;
                    return -1;
                }
                calcValue[++valuen] = strToInt(subArgv[1]);
            break;
        }
    }
    while(stackn) {
        //printCalcStack();
        doCalc();
    }
    cprintf("%d\n", calcValue[1]);
    return calcValue[1];
}
Пример #24
0
// Search and Replace
ZString IString_ReplaceIString (
	IStringPtr self,
	IStringPtr what,
	IStringPtr with,
	int IgnoreCase
	)
{
	ZString from, to, find;
	u32 count, oldsize, newsize;

	// Sanity checks. Cannot replace an empty string
	ESIF_ASSERT(self && what && with);
	if (self->data_len <= 1 || what->data_len <= 1) {
		return 0;
	}

	// Count occurances of replacment string in original string
	for (count = 0, find = (ZString)self->buf_ptr; (find = (ZString)strfind(find, (ZString)what->buf_ptr, IgnoreCase)) != NULL; count++)
		find += what->data_len - 1;

	// Compute new string size and Resize if necessary
	oldsize = self->data_len;
	newsize = self->data_len + (count * (int)(esif_ccb_max(with->data_len, 1) - what->data_len));
	if (newsize > self->buf_len) {
#ifdef ISTRING_AUTOGROW
		if (IString_Resize(self, newsize + ISTRING_AUTOGROW) == NULL)
#endif
		return 0;
	}

	// Do an in-string replacement so that another copy of the string does not need to be allocated
	// a) newsize <= oldsize: Do a left-to-right copy replacment
	// b) newsize >  oldsize: Move string to end of newsize buffer, then do a left-to-right copy replacement
	from = to = (ZString)self->buf_ptr;
	self->data_len = newsize;
	if (newsize > oldsize) {
		// Move string to end of reallocated (data_len) buffer
		esif_ccb_memmove(((ZString)self->buf_ptr) + (newsize - oldsize), (ZString)self->buf_ptr, oldsize);
		from += newsize - oldsize;
	}
	// Do a left-to-right copy (from -> to), replacing each occurance of old string (what) with new string (with)
	while ((find = (ZString)strfind(from, (ZString)what->buf_ptr, IgnoreCase)) != NULL) {
		if (from > to) {
			esif_ccb_memcpy(to, from, (size_t)(find - from));
		}
		to += (size_t)(find - from);
		if (with->data_len > 0) {
			esif_ccb_memcpy(to, (ZString)with->buf_ptr, with->data_len - 1);
			to += with->data_len - 1;
		}
		from = find + (what->data_len > 0 ? what->data_len - 1 : 0);
	}
	// Copy remainder of string, if any
	if (to < from) {
		esif_ccb_memcpy(to, from, newsize - (size_t)(to - (ZString)self->buf_ptr));
	}
	to += newsize - (size_t)(to - (ZString)self->buf_ptr);
	// zero out remainder of old string, if any
	if (oldsize > newsize) {
		esif_ccb_memset(to, 0, oldsize - newsize);
	}
	return (ZString)self->buf_ptr;
}
Пример #25
0
static struct http_request * uh_http_header_recv(struct client *cl)
{
	static char buffer[UH_LIMIT_MSGHEAD];
	char *bufptr = &buffer[0];
	char *idxptr = NULL;

	struct timeval timeout;

	fd_set reader;

	ssize_t blen = sizeof(buffer)-1;
	ssize_t rlen = 0;

	memset(buffer, 0, sizeof(buffer));

	while( blen > 0 )
	{
		FD_ZERO(&reader);
		FD_SET(cl->socket, &reader);

		/* fail after 0.1s */
		timeout.tv_sec  = 0;
		timeout.tv_usec = 100000;

		/* check whether fd is readable */
		if( select(cl->socket + 1, &reader, NULL, NULL, &timeout) > 0 )
		{
			/* receive data */
			ensure_out(rlen = uh_tcp_peek(cl, bufptr, blen));

			if( (idxptr = strfind(buffer, sizeof(buffer), "\r\n\r\n", 4)) )
			{
				ensure_out(rlen = uh_tcp_recv(cl, bufptr,
					(int)(idxptr - bufptr) + 4));

				/* header read complete ... */
				blen -= rlen;
				return uh_http_header_parse(cl, buffer,
					sizeof(buffer) - blen - 1);
			}
			else
			{
				ensure_out(rlen = uh_tcp_recv(cl, bufptr, rlen));

				/* unexpected eof - #7904 */
				if( rlen == 0 )
					return NULL;

				blen -= rlen;
				bufptr += rlen;
			}
		}
		else
		{
			/* invalid request (unexpected eof/timeout) */
			return NULL;
		}
	}

	/* request entity too large */
	uh_http_response(cl, 413, "Request Entity Too Large");

out:
	return NULL;
}
Пример #26
0
// debuginfo_eip(addr, info)
//
//	Fill in the 'info' structure with information about the specified
//	instruction address, 'addr'.  Returns 0 if information was found, and
//	negative if not.  But even if it returns negative it has stored some
//	information into '*info'.
//
int
debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info)
{
	const struct Stab *stabs, *stab_end;
	const char *stabstr, *stabstr_end;
	int lfile, rfile, lfun, rfun, lline, rline;

	// Initialize *info
	info->eip_file = "<unknown>";
	info->eip_line = 0;
	info->eip_fn_name = "<unknown>";
	info->eip_fn_namelen = 9;
	info->eip_fn_addr = addr;
	info->eip_fn_narg = 0;

	// Find the relevant set of stabs
	if (addr >= ULIM) {
		stabs = __STAB_BEGIN__;
		stab_end = __STAB_END__;
		stabstr = __STABSTR_BEGIN__;
		stabstr_end = __STABSTR_END__;
	} else {
		// The user-application linker script, user/user.ld,
		// puts information about the application's stabs (equivalent
		// to __STAB_BEGIN__, __STAB_END__, __STABSTR_BEGIN__, and
		// __STABSTR_END__) in a structure located at virtual address
		// USTABDATA.
		const struct UserStabData *usd = (const struct UserStabData *) USTABDATA;

		// Make sure this memory is valid.
		// Return -1 if it is not.  Hint: Call user_mem_check.
		// LAB 3: Your code here.
		if(user_mem_check(curenv, usd, sizeof(struct UserStabData), PTE_U) < 0)
		{
			return -1;
		}

		stabs = usd->stabs;
		stab_end = usd->stab_end;
		stabstr = usd->stabstr;
		stabstr_end = usd->stabstr_end;

		// Make sure the STABS and string table memory is valid.
		// LAB 3: Your code here.
		if(user_mem_check(curenv, stabs, stab_end-stabs, PTE_U) < 0)
		{
			return -1;
		}
		
		if(user_mem_check(curenv, stabstr, stabstr_end-stabstr, PTE_U) < 0)
		{
			return -1;
		}
	}

	// String table validity checks
	if (stabstr_end <= stabstr || stabstr_end[-1] != 0)
		return -1;

	// Now we find the right stabs that define the function containing
	// 'eip'.  First, we find the basic source file containing 'eip'.
	// Then, we look in that source file for the function.  Then we look
	// for the line number.
	
	// Search the entire set of stabs for the source file (type N_SO).
	lfile = 0;
	rfile = (stab_end - stabs) - 1;
	stab_binsearch(stabs, &lfile, &rfile, N_SO, addr);
	if (lfile == 0)
		return -1;

	// Search within that file's stabs for the function definition
	// (N_FUN).
	lfun = lfile;
	rfun = rfile;
	stab_binsearch(stabs, &lfun, &rfun, N_FUN, addr);

	if (lfun <= rfun) {
		// stabs[lfun] points to the function name
		// in the string table, but check bounds just in case.
		if (stabs[lfun].n_strx < stabstr_end - stabstr)
			info->eip_fn_name = stabstr + stabs[lfun].n_strx;
		info->eip_fn_addr = stabs[lfun].n_value;
		addr -= info->eip_fn_addr;
		// Search within the function definition for the line number.
		lline = lfun;
		rline = rfun;
	} else {
		// Couldn't find function stab!  Maybe we're in an assembly
		// file.  Search the whole file for the line number.
		info->eip_fn_addr = addr;
		lline = lfile;
		rline = rfile;
	}
	// Ignore stuff after the colon.
	info->eip_fn_namelen = strfind(info->eip_fn_name, ':') - info->eip_fn_name;

	
	// Search within [lline, rline] for the line number stab.
	// If found, set info->eip_line to the right line number.
	// If not found, return -1.
	//
	// Hint:
	//	There's a particular stabs type used for line numbers.
	//	Look at the STABS documentation and <inc/stab.h> to find
	//	which one.
	// Your code here.
	stab_binsearch(stabs, &lline, &rline, N_SLINE, addr);
	if (lline <= rline)
	{
		info->eip_line = stabs[lline].n_desc;
	}
	else
	{
		return -1;
	}

	
	// Search backwards from the line number for the relevant filename
	// stab.
	// We can't just use the "lfile" stab because inlined functions
	// can interpolate code from a different file!
	// Such included source files use the N_SOL stab type.
	while (lline >= lfile
	       && stabs[lline].n_type != N_SOL
	       && (stabs[lline].n_type != N_SO || !stabs[lline].n_value))
		lline--;
	if (lline >= lfile && stabs[lline].n_strx < stabstr_end - stabstr)
		info->eip_file = stabstr + stabs[lline].n_strx;


	// Set eip_fn_narg to the number of arguments taken by the function,
	// or 0 if there was no containing function.
	if (lfun < rfun)
		for (lline = lfun + 1;
		     lline < rfun && stabs[lline].n_type == N_PSYM;
		     lline++)
			info->eip_fn_narg++;
	
	return 0;
}
Пример #27
0
// debuginfo_eip(addr, info)
//
//	Fill in the 'info' structure with information about the specified
//	instruction address, 'addr'.  Returns 0 if information was found, and
//	negative if not.  But even if it returns negative it has stored some
//	information into '*info'.
//
int
debuginfo_eip(uintptr_t addr, struct Eipdebuginfo *info)
{
	const struct Stab *stabs, *stab_end;
	const char *stabstr, *stabstr_end;
	int lfile, rfile, lfun, rfun, lline, rline;

	// Initialize *info
	info->eip_file = "<unknown>";
	info->eip_line = 0;
	info->eip_fn_name = "<unknown>";
	info->eip_fn_namelen = 9;
	info->eip_fn_addr = addr;
	info->eip_fn_narg = 0;

	// Find the relevant set of stabs
	if (addr >= ULIM) {
		stabs = __STAB_BEGIN__;
		stab_end = __STAB_END__;
		stabstr = __STABSTR_BEGIN__;
		stabstr_end = __STABSTR_END__;
	} else {
		// Can't search for user-level addresses yet!
  	        panic("User address");
	}

	// String table validity checks
	if (stabstr_end <= stabstr || stabstr_end[-1] != 0)
		return -1;

	// Now we find the right stabs that define the function containing
	// 'eip'.  First, we find the basic source file containing 'eip'.
	// Then, we look in that source file for the function.  Then we look
	// for the line number.

	// Search the entire set of stabs for the source file (type N_SO).
	lfile = 0;
	rfile = (stab_end - stabs) - 1;
	stab_binsearch(stabs, &lfile, &rfile, N_SO, addr);
	if (lfile == 0)
		return -1;

	// Search within that file's stabs for the function definition
	// (N_FUN).
	lfun = lfile;
	rfun = rfile;
	stab_binsearch(stabs, &lfun, &rfun, N_FUN, addr);

	if (lfun <= rfun) {
		// stabs[lfun] points to the function name
		// in the string table, but check bounds just in case.
		if (stabs[lfun].n_strx < stabstr_end - stabstr)
			info->eip_fn_name = stabstr + stabs[lfun].n_strx;
		info->eip_fn_addr = stabs[lfun].n_value;
		addr -= info->eip_fn_addr;
		// Search within the function definition for the line number.
		lline = lfun;
		rline = rfun;
	} else {
		// Couldn't find function stab!  Maybe we're in an assembly
		// file.  Search the whole file for the line number.
		info->eip_fn_addr = addr;
		lline = lfile;
		rline = rfile;
	}
	// Ignore stuff after the colon.
	info->eip_fn_namelen = strfind(info->eip_fn_name, ':') - info->eip_fn_name;


	// Search within [lline, rline] for the line number stab.
	// If found, set info->eip_line to the right line number.
	// If not found, return -1.
	//
	// Hint:
	//	There's a particular stabs type used for line numbers.
	//	Look at the STABS documentation and <inc/stab.h> to find
	//	which one.
	// Your code here.

	stab_binsearch(stabs, &lline, &rline, N_SLINE, addr);
	info.eip_line = (lline <= rline)?
					stabs[rrline].n_desc:
					-1;
	// Search backwards from the line number for the relevant filename
	// stab.
	// We can't just use the "lfile" stab because inlined functions
	// can interpolate code from a different file!
	// Such included source files use the N_SOL stab type.
	while (lline >= lfile
	       && stabs[lline].n_type != N_SOL
	       && (stabs[lline].n_type != N_SO || !stabs[lline].n_value))
		lline--;
	if (lline >= lfile && stabs[lline].n_strx < stabstr_end - stabstr)
		info->eip_file = stabstr + stabs[lline].n_strx;


	// Set eip_fn_narg to the number of arguments taken by the function,
	// or 0 if there was no containing function.
	if (lfun < rfun)
		for (lline = lfun + 1;
		     lline < rfun && stabs[lline].n_type == N_PSYM;
		     lline++)
			info->eip_fn_narg++;

	return 0;
}
Пример #28
0
int t1_rlist(REMAILER remailer[], int badchains[MAXREM][MAXREM])
{
  FILE *list, *excl;
  int i, listed = 0;
  int n = 0;
  char line[2 * LINELEN], l2[LINELEN], name[LINELEN], *flags;
  BUFFER *starex;

  starex = buf_new();
  excl = mix_openfile(STAREX, "r");
  if (excl != NULL) {
    buf_read(starex, excl);
    fclose(excl);
  }

  list = mix_openfile(TYPE1LIST, "r");
  if (list == NULL) {
    buf_free(starex);
    return (-1);
  }

  while (fgets(line, sizeof(line), list) != NULL && n < MAXREM) {
    if (strleft(line, "$remailer") &&
	strchr(line, '<') && strchr(line, '>') &&
	strchr(line, '{') && strchr(line, '{') + 4 < strchr(line, '}')) {
      if (line[strlen(line) - 1] == '\n')
	line[strlen(line) - 1] = '\0';
      if (line[strlen(line) - 1] == '\r')
	line[strlen(line) - 1] = '\0';
      while (line[strlen(line) - 1] == ' ')
	line[strlen(line) - 1] = '\0';
      if (line[strlen(line) - 1] != ';'
	  && fgets(l2, sizeof(l2), list) != NULL)
	strcatn(line, l2, LINELEN);
      flags = strchr(line, '>');
      strncpy(name, strchr(line, '{') + 2,
	      strchr(line, '}') - strchr(line, '{') - 3);
      name[strchr(line, '}') - strchr(line, '{') - 3] = '\0';
      name[20] = '\0';

      for (i = 1; i <= n; i++)
	if (streq(name, remailer[i].name))
	  break;
      if (i > n) {
	/* not in mix list */
	n++;
	strcpy(remailer[i].name, name);
	strncpy(remailer[i].addr, strchr(line, '<') + 1,
		strchr(line, '>') - strchr(line, '<'));
	remailer[i].addr[strchr(line, '>') - strchr(line, '<') - 1]
	  = '\0';
	remailer[i].flags.mix = 0;
	remailer[i].flags.post = strifind(flags, " post");
      }
      remailer[i].flags.cpunk = strfind(flags, " cpunk");
      remailer[i].flags.pgp = strfind(flags, " pgp");
      remailer[i].flags.pgponly = strfind(flags, " pgponly");
      remailer[i].flags.latent = strfind(flags, " latent");
      remailer[i].flags.middle = strfind(flags, " middle");
      remailer[i].flags.ek = strfind(flags, " ek");
      remailer[i].flags.esub = strfind(flags, " esub");
      remailer[i].flags.hsub = strfind(flags, " hsub");
      remailer[i].flags.newnym = strfind(flags, " newnym");
      remailer[i].flags.nym = strfind(flags, " nym");
      remailer[i].info[1].reliability = 0;
      remailer[i].info[1].latency = 0;
      remailer[i].info[1].history[0] = '\0';
      remailer[i].flags.star_ex = bufifind(starex, name);
   }
    if (strleft(line,
		"-----------------------------------------------------------------------"))
      break;
  }
  n++;				/* ?? */
  while (fgets(line, sizeof(line), list) != NULL) {
    if (strlen(line) >= 72 && strlen(line) <= 73)
      for (i = 1; i < n; i++)
	if (strleft(line, remailer[i].name) &&
	    line[strlen(remailer[i].name)] == ' ') {
	  strncpy(remailer[i].info[1].history, line + 42, 12);
	  remailer[i].info[1].history[12] = '\0';
	  remailer[i].info[1].reliability = 10000 * N(line[64])
	    + 1000 * N(line[65]) + 100 * N(line[66])
	    + 10 * N(line[68]) + N(line[69]);
	  remailer[i].info[1].latency = 36000 * N(line[55])
	    + 3600 * N(line[56]) + 600 * N(line[58])
	    + 60 * N(line[59]) + 10 * N(line[61])
	    + N(line[62]);
	  listed++;
	}
  }
  fclose(list);
  parse_badchains(badchains, TYPE1LIST, "Broken type-I remailer chains", remailer, n);
  if (listed < 4)		/* we have no valid reliability info */
    for (i = 1; i < n; i++)
      remailer[i].info[1].reliability = 10000;

#ifdef USE_PGP
  pgp_rlist(remailer, n);
#endif /* USE_PGP */
  buf_free(starex);
  return (n);
}
Пример #29
0
bool CHttpClient::ParseHeaders(const char * szBuffer, int& iBufferSize, int& iHeaderSize)
{
    // Find amount of whitespace
    int iWhiteSpace = 0;

    for (int i = 0; i < iBufferSize; i++)
    {
        if (szBuffer[i] != ' ')
            break;

        // Increment the whitespace amount
        iWhiteSpace++;
    }

    // Increment the header size
    iHeaderSize += iWhiteSpace;

    // Ignore the version, status code and status message
    // Will be in format 'HTTP/1.0 200 OK\r\n'
    int iIgnore = strfind(szBuffer, iBufferSize, "\r\n", iHeaderSize);

    if (iIgnore == -1)
        return false;

    int iIgnoreSize = (iIgnore - iHeaderSize);

    // Increment the header size
    iHeaderSize += (iIgnoreSize + 2); // + 2 for '\r\n'

    // Find all headers
    int iNameSplit;
    int iValueSplit;

    while ((iNameSplit = strfind(szBuffer, iBufferSize, ": ", iHeaderSize, "\r\n")) != -1)
    {
        // Get the header name
        int iNameSize = (iNameSplit - iHeaderSize);
        CString strName;
        strName.Set((szBuffer + iHeaderSize), iNameSize);

        // Increment the header size
        iHeaderSize += (iNameSize + 2); // + 2 for '\r\n'

        // Find the value end
        iValueSplit = strfind(szBuffer, iBufferSize, "\r\n", iHeaderSize);

        // Did we not find a value end?
        if (iValueSplit == -1)
            return false;

        // Get the header value
        int iValueSize = (iValueSplit - iHeaderSize);
        CString strValue;
        strValue.Set((szBuffer + iHeaderSize), iValueSize);

        // Increment the header size
        iHeaderSize += (iValueSize + 2); // + 2 for '\r\n'

        // Add the header to the header map
        m_headerMap[strName] = strValue;
    }

    // Did we not get any headers?
    if (m_headerMap.empty())
        return false;

    // Ignore the '\r\n' after the headers
    iHeaderSize += 2;

    // Decrement the buffer size by the header size
    iBufferSize -= iHeaderSize;

    // Success
    return true;
}
Пример #30
0
static struct http_request * uh_http_header_parse(struct client *cl, char *buffer, int buflen)
{
	char *method  = &buffer[0];
	char *path    = NULL;
	char *version = NULL;

	char *headers = NULL;
	char *hdrname = NULL;
	char *hdrdata = NULL;

	int i;
	int hdrcount = 0;

	static struct http_request req;

	memset(&req, 0, sizeof(req));


	/* terminate initial header line */
	if( (headers = strfind(buffer, buflen, "\r\n", 2)) != NULL )
	{
		buffer[buflen-1] = 0;

		*headers++ = 0;
		*headers++ = 0;

		/* find request path */
		if( (path = strchr(buffer, ' ')) != NULL )
			*path++ = 0;

		/* find http version */
		if( (path != NULL) && ((version = strchr(path, ' ')) != NULL) )
			*version++ = 0;


		/* check method */
		if( strcmp(method, "GET") && strcmp(method, "HEAD") && strcmp(method, "POST") )
		{
			/* invalid method */
			uh_http_response(cl, 405, "Method Not Allowed");
			return NULL;
		}
		else
		{
			switch(method[0])
			{
				case 'G':
					req.method = UH_HTTP_MSG_GET;
					break;

				case 'H':
					req.method = UH_HTTP_MSG_HEAD;
					break;

				case 'P':
					req.method = UH_HTTP_MSG_POST;
					break;
			}
		}

		/* check path */
		if( !path || !strlen(path) )
		{
			/* malformed request */
			uh_http_response(cl, 400, "Bad Request");
			return NULL;
		}
		else
		{
			req.url = path;
		}

		/* check version */
		if( (version == NULL) || (strcmp(version, "HTTP/0.9") &&
		    strcmp(version, "HTTP/1.0") && strcmp(version, "HTTP/1.1")) )
		{
			/* unsupported version */
			uh_http_response(cl, 400, "Bad Request");
			return NULL;
		}
		else
		{
			req.version = strtof(&version[5], NULL);
		}


		/* process header fields */
		for( i = (int)(headers - buffer); i < buflen; i++ )
		{
			/* found eol and have name + value, push out header tuple */
			if( hdrname && hdrdata && (buffer[i] == '\r' || buffer[i] == '\n') )
			{
				buffer[i] = 0;

				/* store */
				if( (hdrcount + 1) < array_size(req.headers) )
				{
					req.headers[hdrcount++] = hdrname;
					req.headers[hdrcount++] = hdrdata;

					hdrname = hdrdata = NULL;
				}

				/* too large */
				else
				{
					uh_http_response(cl, 413, "Request Entity Too Large");
					return NULL;
				}
			}

			/* have name but no value and found a colon, start of value */
			else if( hdrname && !hdrdata &&
			    ((i+1) < buflen) && (buffer[i] == ':')
			) {
				buffer[i] = 0;
				hdrdata = &buffer[i+1];

				while ((hdrdata + 1) < (buffer + buflen) && *hdrdata == ' ')
					hdrdata++;
			}

			/* have no name and found [A-Za-z], start of name */
			else if( !hdrname && isalpha(buffer[i]) )
			{
				hdrname = &buffer[i];
			}
		}

		/* valid enough */
		req.redirect_status = 200;
		return &req;
	}

	/* Malformed request */
	uh_http_response(cl, 400, "Bad Request");
	return NULL;
}