Exemple #1
1
/*
 * Show some adapter details.
 * The IP-address, netmask etc. are what Winsock uses. We ignore
 * them and use what WATTCP.CFG specifies.
 */
static void show_link_details (void)
{
#if defined(USE_DEBUG)
  const ADAPTER_INFO *ai;
  int   i, real_media;
  BOOL  is_up;
  DWORD ver, MTU, speed;
  mac_address mac;

  if (!_pkt_inf)
     return;

  ai = (const ADAPTER_INFO*) _pkt_inf->adapter_info;
  if (!ai)
  {
    (*_printf) ("  not available\n");
    return;
  }

  (*_printf) ("  %d network address%s:\n",
              ai->NNetworkAddresses, ai->NNetworkAddresses > 1 ? "es" : "");
  for (i = 0; i < ai->NNetworkAddresses; i++)
  {
    const npf_if_addr        *if_addr = ai->NetworkAddresses + i;
    const struct sockaddr_in *ip_addr = (const struct sockaddr_in*) &if_addr->IPAddress;
    const struct sockaddr_in *netmask = (const struct sockaddr_in*) &if_addr->SubnetMask;
    const struct sockaddr_in *brdcast = (const struct sockaddr_in*) &if_addr->Broadcast;

    (*_printf) ("  IP-addr %s", inet_ntoa(ip_addr->sin_addr));
    (*_printf) (", netmask %s", inet_ntoa(netmask->sin_addr));
    (*_printf) (", broadcast %s\n", inet_ntoa(brdcast->sin_addr));
  }
  if (ai->NNetworkAddresses <= 0)
     (*_printf) ("\n");

  if (get_perm_mac_address(&mac))
     (*_printf) ("  MAC-addr %02X:%02X:%02X:%02X:%02X:%02X, ",
                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  if (get_interface_mtu(&MTU))
     (*_printf) ("MTU %lu, ", MTU);

  (*_printf) ("link-type %s, ",
              list_lookup(_pktdevclass, logical_media, DIM(logical_media)));

  if (get_real_media(&real_media))
     (*_printf) (" over %s, ", list_lookup(real_media, phys_media, DIM(phys_media)));

  if (get_connected_status(&is_up))
     (*_printf) ("%s, ", is_up ? "UP" : "DOWN");

  if (get_interface_speed(&speed))
     (*_printf) ("%luMb/s, ", speed);

  if (pkt_get_api_ver(&ver))
     (*_printf) ("NDIS %d.%d", hiBYTE(ver), loBYTE(ver));
  (*_printf) ("\n");
#endif
}
Exemple #2
0
void putfile_handler(http_response *resp, node *cookie, node* param) {
  FILE *fp;
  char *username, *filename, *content, decoded[MAX_FILESIZE+1];
  int bytes;
  size_t written;

  filename = list_lookup(param, "filename");
  content = list_lookup(param, "content");
  if (filename && content) {
    fp = fopen(filename, "w+");
    if (fp) {
      decode(content, decoded);
      written = fwrite(decoded, sizeof(char), strlen(decoded), fp);
      if (written == strlen(decoded)) {
        fclose(fp);
        bytes = 0;
        username = list_lookup(cookie, "username"); 
        if (username) {
          bytes = sprintf(resp->body, "Username: %s\n", username);
        }
        sprintf(resp->body + bytes, "%s has been saved successfully.", filename);
        resp->status = OK;
        resp->opt_flags |= OPT_CONTENT_LENGTH;
      } else {
        resp->status = FORBIDDEN;
      }
    } else {
      resp->status = FORBIDDEN;
    }
  } else {
    resp->status = FORBIDDEN;
  }
  resp->content_type = TEXT;
}
Exemple #3
0
void delcart_handler(http_response* resp, node* param, node* cookie) {
  char *itemnr, *item_name, *username;
  int bytes, max_n, n, del_n;
  node *node;
  char str[STR_SIZE];
  
  itemnr = list_lookup(param, "itemnr");
  if (itemnr) {
    node = cookie;
    sprintf(str, "item%s", itemnr);
    while (node) {
      if (strcmp(node->name, str) == 0) {
        break;
      }
      node = node->next;
    }
    if (node) {
      del_n = atoi(node->name + 4);
      max_n = max_item_nr(cookie);
      node = malloc(sizeof(node));
      sprintf(node->name, "item%i", max_n);
      strcpy(node->value, "0");
      node->next = NULL;
      resp->expire = append_list(resp->expire, node);
      for (n = del_n; n < max_n; n++) {
        sprintf(str, "item%i", n+1);
        item_name = list_lookup(cookie, str);
        node = malloc(sizeof(node));
        sprintf(node->name, "item%i", n);
        strcpy(node->value, item_name);
        node->next = NULL;
        resp->cookie = append_list(resp->cookie, node);
      }
      bytes = 0;
      username = list_lookup(cookie, "username"); 
      if (username) {
        bytes = sprintf(resp->body, "Username: %s\n", username);
      }
      for (n = 1; n < del_n; n++) {
        sprintf(str, "item%i", n);
        item_name = list_lookup(cookie, str);
        bytes += sprintf(resp->body + bytes, "%i. %s\r\n", n, item_name);
      }
      for (n = del_n; n < max_n; n++)   {
        sprintf(str, "item%i", n);
        item_name = list_lookup(resp->cookie, str);
        bytes += sprintf(resp->body + bytes, "%i. %s\r\n", n, item_name);
      }
      resp->status = OK;
      resp->opt_flags |= OPT_CONTENT_LENGTH;
      
    } else {
      resp->status = FORBIDDEN;
    }
  } else {
    resp->status = FORBIDDEN;
  }
  resp->content_type = TEXT;
  resp->cache_control = NO_CACHE;
}
Exemple #4
0
void checkout_handler(http_response *resp, node* cookie) {
  char *username, *item_name;
  int max_n, n, bytes;
  char str[STR_SIZE];
  node* item;
  FILE *fp;

  username = list_lookup(cookie, "username");
  fp = fopen("CHECKOUT.txt", "a+");
  if (username && fp) {
    bytes = sprintf(resp->body, "Username: %s\n", username);
    max_n = max_item_nr(cookie);
    for (n = 1; n <= max_n; n++) {
      sprintf(str, "item%i", n);
      item_name = list_lookup(cookie, str);
      item = malloc(sizeof(node));
      strcpy(item->name, str);
      strcpy(item->value, "0");
      item->next = NULL;
      resp->expire = append_list(resp->expire, item);
      bytes += sprintf(resp->body + bytes, "%i. %s\r\n",n , item_name);
    }
    fwrite(resp->body, sizeof(char), bytes, fp);
    fclose(fp);
    resp->status = OK;
    resp->opt_flags |= OPT_CONTENT_LENGTH;
  } else {
    resp->status = FORBIDDEN;
  }
  resp->content_type = TEXT;
  resp->cache_control = NO_CACHE;
}
Exemple #5
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    for (int i = 0; i<map->n; i++) {
        if (list_lookup(map->lists[i], key) != NULL) {
            return list_lookup(map->lists[i], key);
        }
    }
    return NULL;
}
int main ()
{
	//these work fine - functions given by Allen
    Hashable *hashable1 = make_hashable_int (1);
    Hashable *hashable2 = make_hashable_string ("Allen");
    Hashable *hashable3 = make_hashable_int (2);

    // make_int_value also given
    Value *value1 = make_int_value (17);
	//failing here!
    Node *node1 = make_node(hashable1, value1, NULL);
	fprintf(stdout, "Print node:\n");
    print_node (node1);

    Value *value2 = make_string_value ("Downey");
    Node *list = prepend(hashable2, value2, node1);
	fprintf(stdout, "Print list:\n");
    print_list (list);

    // run some test lookups
    Value *value = list_lookup (list, hashable1);
	fprintf(stdout, "List lookup:\n");
    print_lookup(value);

	fprintf(stdout, "List lookup:\n");
    value = list_lookup (list, hashable2);
    print_lookup(value);

	fprintf(stdout, "List lookup:\n");
    value = list_lookup (list, hashable3);
    print_lookup(value);

    // make a map
    Map *map = make_map(10);
    map_add(map, hashable1, value1);
    map_add(map, hashable2, value2);

    printf ("Map\n");
    print_map(map);

    // run some test lookups
    value = map_lookup(map, hashable1);
    print_lookup(value);

    value = map_lookup(map, hashable2);
    print_lookup(value);

    value = map_lookup(map, hashable3);
    print_lookup(value);

    return 0;
}
Exemple #7
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    int hashval = hash_hashable(key) % map->n;
    Node *list = map->lists[hashval];
    
    return list_lookup(list, key);
}
Exemple #8
0
char const *phone_from_id (int32 phone_id)
/*------------------------------------------------------------*
 * return the string coresponding to phone_id if there is one
 *------------------------------------------------------------*/
{
    return ((char *) list_lookup (&phones_list, phone_id));
}
int main(int argc, char *argv[])
{
	List list;
	List_node *abc;

	list_init(&list);

	check(list_size(&list) == 0);
	list_insert(&list, "abc");
	check(list_size(&list) == 1);
	abc = list_lookup_data(&list, "abc", cmp_string);
	check(abc != NULL);
	check(list_lookup(&list, abc) == abc);
	check(list_lookup_data(&list, "def", cmp_string) == NULL);
	check(cmp_string((char *) list_head(&list)->data, "abc") == 0);
	list_insert(&list, "def");
	check(list_size(&list) == 2);
	check(cmp_string((char *) list_head(&list)->data, "def") == 0);
	list_delete(&list, abc);
	check(list_lookup_data(&list, "abc", cmp_string) == NULL);
	list_delete_data(&list, "def", cmp_string);
	check(list_size(&list) == 0);

	list_free(&list, NULL);

	return 0;
}
Exemple #10
0
void getfile_handler(http_response* resp, node* param, time_t since) {
  FILE *fp;
  char *filename;
  size_t read;
  struct stat filestat;

  filename = list_lookup(param, "filename");
  if (filename) {
    // printf("getfile: %s\n", filename);
    fp = fopen(filename, "r");
    if (fp) {
      stat(filename, &filestat);
      if (filestat.st_mtime <= since) {
        resp->status = NOT_MODIFIED;
      } else {
        read = fread(resp->body, sizeof(char), MAX_FILESIZE, fp);
        resp->body[read] = 0;
        resp->status = OK;
        resp->content_type = BINARY;
        resp->opt_flags |= OPT_CONTENT_LENGTH | OPT_LAST_MODIFIED;
        resp->last_modified = filestat.st_mtime;

      }
    } else {
      resp->status = NOT_FOUND;
      resp->content_type = TEXT;
    }

  } else {
      resp->status = FORBIDDEN;
      resp->content_type = TEXT;
  }
  resp->cache_control = PUBLIC;
}
void insereEmFicheiro(int shardid, char *key, char *value) {
    shard_t *aux;
    aux=vetorShards[shardid];
    int index=hash(key);
    char file[1000];
    sprintf(file,"f%d.txt",shardid);
    char *existe = list_lookup(aux->array[index], key,shardid);
    if(existe == NULL) {
        FILE *pFile = fopen(file,"w");
        if (!pFile) {
            exit (1);
        }
        fprintf(pFile,"%s %s\n", key, value);
        fclose(pFile);
    }
    else {
        FILE *pFile= fopen(file,"a");
        if (!pFile) {
            exit (1);
        }
        char keyInserir[KV_SIZE], valueInserir[KV_SIZE];
        while(fscanf(pFile,"%s %s", keyInserir, valueInserir) == 2) {
            if(strcmp(keyInserir, key) != 0)
                fprintf(pFile,"%s %s\n", keyInserir, valueInserir);
        }
        fclose(pFile);
    }
}
Exemple #12
0
int main ()
{
    Hashable *hashable1 = make_hashable_int (1);
    Hashable *hashable2 = make_hashable_string ("Allen");
    Hashable *hashable3 = make_hashable_int (2);

    // make a list by hand
    Value *value1 = make_int_value (17);
    Node *node1 = make_node(hashable1, value1, NULL);
    print_node (node1);

    Value *value2 = make_string_value ("Downey");
    Node *list = prepend(hashable2, value2, node1);
    print_list (list);

    // run some test lookups
    Value *value = list_lookup (list, hashable1);
    print_lookup(value);

    value = list_lookup (list, hashable2);
    print_lookup(value);

    value = list_lookup (list, hashable3);
    print_lookup(value);

    // make a map
    Map *map = make_map(10);
    map_add(map, hashable1, value1);
    map_add(map, hashable2, value2);

    printf ("Map\n");
    print_map(map);

    // run some test lookups
    value = map_lookup(map, hashable1);
    print_lookup(value);

    value = map_lookup(map, hashable2);
    print_lookup(value);

    value = map_lookup(map, hashable3);
    print_lookup(value);

    return 0;
}
Exemple #13
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    int index;
    Node *list;

    index = hash_hashable(key) % map->n;
    list = (map->lists)[index];
    return list_lookup(list, key);
}
Exemple #14
0
/* Looks up a key and returns the corresponding value, or NULL */
Value *list_lookup(Node *list, Hashable *key)
{
    if (list->key == key)
        return list->value;
    else if (list->next == NULL)
        return NULL;
    else
        return list_lookup(list->next, key);
}
Exemple #15
0
List* LocalVarListInsert(List* local_var,DICT_NODE* node, int type, int size, List* function_list){
	if(list_lookup(local_var,node->text)==NULL){
		local_var=list_insert(local_var,type,size,node->text,0);
	} 
	else{
		printf("->Redeclaracao de variavel local (linha %d)\n", getLineNumber());
		exit(IKS_ERROR_DECLARED);
	}
	return local_var;
}
Exemple #16
0
List* FunctionListInsert(List* function_list,DICT_NODE* node, int type, int size, int label){
	if(list_lookup(function_list,node->text)==NULL){
		function_list=list_insert(function_list,type,size,node->text,label);
	} 
	else{
		printf("->Redeclaracao de funcao (linha %d)\n", getLineNumber());
		exit(IKS_ERROR_DECLARED);
	}
	return function_list;
}
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    int hashValue = hash_hashable(key);
    if(hashValue > map->n - 1){
        hashValue = hashValue % (map->n -1);
    }
    if (map->lists[hashValue]){
        return list_lookup(map->lists[hashValue],key);
    }
    return NULL;
}
int shmdt(const void *shmaddr)
{
	unsigned long addr = ((long) shmaddr) & (-4096UL);
	struct genlist *item = list_lookup(addr_list, addr);
	if (!item)
		return real_shmdt(shmaddr);
	munmap((void *) addr, (long) item->data);
	list_remove(item);
	list_len--;
	return 0;
}
Exemple #19
0
List* GlobalVarListInsert(List* list,DICT_NODE* node,int control,int type, int size){
	switch(control){
		case GLOBAL_VAR_DEC_IDENTIFIER_CONTROL:		if(list_lookup(list,node->text)==NULL)
									list=list_insert(list,type,size,node->text,0); 
								else{
									printf("->Redeclaracao de variavel global (linha = %d)\n", getLineNumber());
									exit(IKS_ERROR_DECLARED);
								}		
								break;

		case GLOBAL_VET_DEC_IDENTIFIER_CONTROL:		if(list_lookup(list,node->text)==NULL){
									list=list_insert(list,type,size,node->text,0);
								}
								else{
									printf("->Redeclaracao de vetor (linha %d)\n", getLineNumber());
									exit(IKS_ERROR_DECLARED); 
								}
								break;
	}
	return list;
}
void server_get(buffer*aux, int shardId, char* key) {
    buffer*aux2;
    aux2=aux;
    shard_t* d;
    char *resposta;
    resposta=(char*)malloc(KV_SIZE*sizeof(char));
    int index;
    d=vetorShards[shardId];
    index=hash(key);
    resposta=list_lookup(d->array[index], key,shardId);
    aux2->resposta=resposta;
}
Exemple #21
0
/*
 * is_crypted: looks up nick in the crypt_list and returns the encryption key
 * if found in the list.  If not found in the crypt_list, null is returned.
 */
Crypt	*is_crypted (const char *nick)
{
    Crypt	*tmp;

    if (!crypt_list)
        return NULL;
    if ((tmp = (Crypt *) list_lookup((List **)&crypt_list, nick,
                                     !!strchr(nick, ','), !REMOVE_FROM_LIST)) != NULL) {
        return tmp;
    } else {
        return NULL;
    }
}
Exemple #22
0
void addcart_handler(http_response* resp, node* param, node* cookie) {
  char *item_name, *username;
  int max_n, n, bytes;
  node* node;
  char str[STR_SIZE];

  item_name = list_lookup(param, "item");
  if (item_name) {
    decode(item_name, str);
    max_n = max_item_nr(cookie);
    node = malloc(sizeof(node));
    sprintf(node->name, "item%i", max_n + 1);
    strcpy(node->value, str);
    node->next = NULL;
    resp->cookie = append_list(resp->cookie, node);

    bytes = 0;
    username = list_lookup(cookie, "username"); 
    if (username) {
      bytes = sprintf(resp->body, "Username: %s\n", username);
    }
    for (n = 1; n <= max_n; n++) {
      sprintf(str, "item%i", n);
      item_name = list_lookup(cookie, str);
      decode(item_name, str);
      bytes += sprintf(resp->body + bytes, "%i. %s\r\n", n, str);
    }
    sprintf(resp->body + bytes, "%i. %s\r\n", max_n + 1, node->value);
    resp->status = OK;
    resp->opt_flags |= OPT_CONTENT_LENGTH | OPT_COOKIE_EXPIRE;
    
  } else {
    resp->status = FORBIDDEN;
  }
  resp->content_type = TEXT;
  resp->cache_control = NO_CACHE;
}
Exemple #23
0
/*
 * remove_crypt: removes the given nickname from the crypt_list, returning 0
 * if successful, and 1 if not (because the nickname wasn't in the list)
 */
static	int	remove_crypt (char *nick)
{
    Crypt	*tmp;

    if ((tmp = (Crypt *) list_lookup((List **)&crypt_list, nick, !USE_WILDCARDS,
                                     REMOVE_FROM_LIST)) != NULL)
    {
        new_free((char **)&(tmp->nick));
        new_free((char **)&(tmp->key));
        new_free((char **)&(tmp->prog));
        new_free((char **)&tmp);
        return (0);
    }
    return (1);
}
Exemple #24
0
void knock_handler(http_response* resp, node* cookie) {
  char *username; 
  int bytes;
 
  resp->status = OK;
  resp->cache_control = PUBLIC;
  resp->content_type = TEXT;

  bytes = 0;
  username = list_lookup(cookie, "username"); 
  if (username) {
    bytes = sprintf(resp->body, "Username: %s\n", username);
  }
  sprintf(resp->body + bytes, KNOCK_RESP);
  resp->opt_flags |= OPT_CONTENT_LENGTH;
}
Exemple #25
0
void logout_handler(http_response* resp, node* cookie) {
  char *username;
  node* expire;

  username = list_lookup(cookie, "username");
  if (username) {
    resp->status = OK;
    sprintf(resp->body, "User %s was logged out.\n", username);
    expire = (node*) malloc(sizeof(node));
    strcpy(expire->name, "username");
    strcpy(expire->value, "0");
    expire->next = NULL;
    resp->expire = append_list(resp->expire, expire);
    resp->opt_flags |= OPT_CONTENT_LENGTH;

  } else {
    resp->status = FORBIDDEN;
  }
  resp->cache_control = PUBLIC;
  resp->content_type = TEXT;
}
Exemple #26
0
void login_handler(http_response* resp, node* param) {
  char *username;
  node *cookie;

  username = list_lookup(param, "username");
  if (username) {
    resp->status = OK;
    sprintf(resp->body, "Username: %s\n", username);
    cookie = (node*) malloc(sizeof(node));
    strcpy(cookie->name, "username");
    strcpy(cookie->value, username);
    cookie->next = NULL;
    resp->cookie = append_list(resp->cookie, cookie);
    resp->opt_flags |= OPT_CONTENT_LENGTH | OPT_COOKIE_EXPIRE;

  } else {
    resp->status = FORBIDDEN;
  }
  resp->cache_control = PUBLIC;
  resp->content_type = TEXT;
}
void removeFicheiro(int shardid, char *key) {
    shard_t *aux;
    aux=vetorShards[shardid];
    int index=hash(key);
    char *existe = list_lookup(aux->array[index], key,shardid);
    char* buraco = calloc(KV_SIZE,sizeof(char));
    if(existe != NULL) {
        char file[1000];
        sprintf(file,"f%d",shardid);
        FILE* pFile= fopen(file,"w+");
        if (!pFile) {
            exit (1);
        }
        char keyInserir[KV_SIZE], valueInserir[KV_SIZE];
        while(fscanf(pFile,"%s %s", keyInserir, valueInserir) == 2) {
            if(strcmp(keyInserir, key) == 0) {
                fprintf(pFile,"%s %s\n", keyInserir, buraco);
            }
        }
        fclose(pFile);
    }
}
Exemple #28
0
/* Looks up a key and returns the corresponding value, or NULL. */
Value *map_lookup(Map *map, Hashable *key)
{
    return list_lookup(map->lists[get_map_index(map, key)], key);
}
Exemple #29
0
int32
phone_type (int32 phone_id)
{
    return ((int32) list_lookup (&phone_type_map, phone_id));
}
Exemple #30
0
int32
phone_len (int32 phone_id)
{
    return ((int32) list_lookup (&phone_model_len, phone_id));
}