Example #1
0
void add_mime_type(const char *extension, const char *type)
{
    unsigned int hash;

    hash = get_mime_hash_value(extension);
    hash_insert(mime_hashtable, hash, extension, type);
}
Example #2
0
void add_mime_type(char *extension, char *type)
{
	int hash;
	hash_struct *current;

	if (!extension)
		return;

	hash = get_mime_hash_value(extension);

	current = mime_hashtable[hash];

	if (!current) {
		mime_hashtable[hash] = (hash_struct *) malloc(sizeof(hash_struct));
		mime_hashtable[hash]->key = strdup(extension);
		mime_hashtable[hash]->value = strdup(type);
		mime_hashtable[hash]->next = NULL;
	} else {
		while (current) {
			if (!strcmp(current->key, extension))
				return;			/* don't add extension twice */
			if (current->next)
				current = current->next;
			else
				break;
		}

		current->next = (hash_struct *) malloc(sizeof(hash_struct));
		current = current->next;

		current->key = strdup(extension);
		current->value = strdup(type);
		current->next = NULL;
	}
}
Example #3
0
File: hash.c Project: Akagi201/boa
void add_mime_type(const char *extension, const char *type)
{
    unsigned int hash;

    hash = get_mime_hash_value(extension);
    if (hash_insert(mime_hashtable, hash, extension, type) == NULL)
	DIE("Failed to hash_insert mime type.");
}
Example #4
0
void add_mime_type(char *extension, char *type)
{
    unsigned int hash;
    hash_struct *current, *next;

    if (!extension)
        return;

    hash = get_mime_hash_value(extension);

    current = mime_hashtable[hash];

    while (current) {
        if (!strcmp(current->key, extension))
            return;         
        if (current->next)
            current = current->next;
        else
            break;
    }

    
    next = (hash_struct *) malloc(sizeof (hash_struct));
    if (!next) {
        DIE("malloc of hash_struct failed!");
    }
    next->key = strdup(extension);
    if (!next->key)
        DIE("malloc of hash_struct->key failed!");
    next->value = strdup(type);
    if (!next->value)
        DIE("malloc of hash_struct->value failed!");
    next->next = NULL;

    if (!current) {
        mime_hashtable[hash] = next;
    } else {
        current->next = next;
    }
}
Example #5
0
char *get_mime_type(char *filename)
{
	char *extension;
	hash_struct *current;

	int hash;

	extension = strrchr(filename, '.');

	if (!extension || *extension++ == '\0')
		return default_type;

	hash = get_mime_hash_value(extension);
	current = mime_hashtable[hash];

	while (current) {
		if (!strcmp(current->key, extension))	/* hit */
			return current->value;
		current = current->next;
	}

	return default_type;
}
Example #6
0
char *get_mime_type(const char *filename)
{
    char *extension;
    hash_struct *current;

    unsigned int hash;

    if (filename == NULL) {
        log_error_time();
        fprintf(stderr,
                "Attempt to hash NULL string! [get_mime_type]\n");
        return default_type;
    } else if (filename[0] == '\0') {
        log_error_time();
        fprintf(stderr,
                "Attempt to hash empty string! [get_mime_type]\n");
        return default_type;
    }

    extension = strrchr(filename, '.');

    /* remember, extension points to the *last* '.' in the filename,
     * which may be NULL or look like:
     *  foo.bar
     *  foo. (in which case extension[1] == '\0')
     */
    /* extension[0] *can't* be NIL */
    if (!extension || extension[1] == '\0')
        return default_type;

    /* make sure we hash on the 'bar' not the '.bar' */
    ++extension;

    hash = get_mime_hash_value(extension);
    current = hash_find(mime_hashtable, extension, hash);
    return (current ? current->value : default_type);
}
Example #7
0
void add_virtual_host(char *name, char *docroot)
{
  int hash;
  hash_struct *current;

  if (!name)
    return;
	

  hash = get_mime_hash_value(name);

  current = virtualhost_hashtable[hash];

  if (!current) {
    virtualhost_hashtable[hash] = (hash_struct *) malloc(sizeof(hash_struct));
    virtualhost_hashtable[hash]->key = strdup(name);
    virtualhost_hashtable[hash]->value = strdup(docroot);
    virtualhost_hashtable[hash]->next = NULL;
  } else {
    while (current) {
      if (!strcmp(current->key, name))
        return;     /* don't add extension twice */
      if (current->next)
        current = current->next;
      else
        break;
    }

    current->next = (hash_struct *) malloc(sizeof(hash_struct));
    current = current->next;

    current->key = strdup(name);
    current->value = strdup(docroot);
    current->next = NULL;
  }
 virtualhost = 1;
}