Example #1
0
void handle_MOTD(char** params, int socket)
{
  char msgbuf[512];
  FILE *file;
  char filebuf[501];
  char user[500];
  int len;
  char nick[10];

  //find the nick of recpient
  struct ClientData *srcUser = (struct ClientData *)list_seek(&clientList, &socket);
  strcpy(nick, srcUser->nick);
  
  file = fopen("./motd.txt", "r");
  if(file != NULL){
    //start send
    sprintf(msgbuf, ":%s 375 %s :- %s Message of the day - \r\n", host, nick, host);
    sendMessage(msgbuf, socket);

    //get one line at a time
    while(NULL != fgets(filebuf, 500, file)){
      //check if the last char is a newline
      len = strlen(filebuf);
      if(filebuf[len-1] == '\n')
	filebuf[len-1] = '\0';
      
      sprintf(msgbuf, ":%s 372 %s :- %s\r\n", host, nick, filebuf);
      sendMessage(msgbuf, socket);
    }

    //end send
    sprintf(msgbuf, ":%s 376 %s :End of MOTD command\r\n", host, nick);
    sendMessage(msgbuf, socket);
    fclose(file);
    
  } else {
    struct ClientData * ourCli = (struct ClientData *)list_seek(&clientList, &socket);
    strcpy(user, ourCli->user);
    sprintf(msgbuf, ":%s 422 %s :MOTD File is missing\r\n", host, user);
    sendMessage(msgbuf, socket);
    return;
  }

  /*//tokenize MOTD around newlines
  printf("file is: %s", filebuf);
  bmotd = bfromcstr(filebuf);
  bmotdtok = bsplit(bmotd, '\n');
  
  //send each part of the motd
  printf("qty %d\n", bmotdtok->qty);
  for(i=0; i<(bmotdtok->qtly); i++){
    curpart = bstraEntry(bmotdtok, i);
    sprintf(msgbuf, ":%s 372 %s\r\n", host, curpart);
    sendMessage(msgbuf, socket);
  }
  */
  return;
}
Example #2
0
/* Return the content based ID for a node.
 * This includes :
 *  command
 *  input files (content)
 *  output files (name) : 
 *	    important addition as changed expected outputs may not 
 *	    be reflected in the command and not present in archive
 *  LATER : environment variables (name:value)
 *  returns a string the caller needs to free
 **/
char * batch_task_generate_id(struct batch_task *t) {
	if(t->hash)
		free(t->hash);
	unsigned char *hash = xxcalloc(1, sizeof(char *)*SHA1_DIGEST_LENGTH);
	struct batch_file *f;

	sha1_context_t context;
	sha1_init(&context);

	/* Add command to the archive id */
	sha1_update(&context, "C", 1);
	sha1_update(&context, t->command, strlen(t->command));
	sha1_update(&context, "\0", 1);

	/* Sort inputs for consistent hashing */
	list_sort(t->input_files, batch_file_outer_compare);

	/* add checksum of the node's input files together */
	struct list_cursor *cur = list_cursor_create(t->input_files);
	for(list_seek(cur, 0); list_get(cur, (void**)&f); list_next(cur)) {
		char * file_id;
		if(path_is_dir(f->inner_name) == 1){
			f->hash = batch_file_generate_id_dir(f->outer_name);
			file_id = xxstrdup(f->hash);
		}
		else{
			file_id = batch_file_generate_id(f);
		}
		sha1_update(&context, "I", 1);
		sha1_update(&context, f->outer_name, strlen(f->outer_name));
		sha1_update(&context, "C", 1);
		sha1_update(&context, file_id, strlen(file_id));
		sha1_update(&context, "\0", 1);
		free(file_id);
	}
	list_cursor_destroy(cur);

	/* Sort outputs for consistent hashing */
	list_sort(t->output_files, batch_file_outer_compare);

	/* add checksum of the node's output file names together */
	cur = list_cursor_create(t->output_files);
	for(list_seek(cur, 0); list_get(cur, (void**)&f); list_next(cur)) {
		sha1_update(&context, "O", 1);
		sha1_update(&context, f->outer_name, strlen(f->outer_name));
		sha1_update(&context, "\0", 1);
	}
	list_cursor_destroy(cur);

	sha1_final(hash, &context);
	t->hash = xxstrdup(sha1_string(hash));
	free(hash);
	return xxstrdup(t->hash);
}
Example #3
0
void handle_NOTICE(char** params, int socket)
{
  char msgbuf[512];
  int destsocket;
  channel *chan;
  struct ClientData *srcUser;
  
  //get the destination and message from the command
  char *dest = params[1];
  char *msg = params[10];

  srcUser = (struct ClientData *)list_seek(&clientList, &socket);
  
  if(dest[0] == '#'){//channel

    chan = (channel *) findChannel(dest);
    if(chan == NULL){
      //sprintf(msgbuf, ":%s 401 %s %s :No such nick/channel\r\n", host, srcUser->nick, dest);
      //sendMessage(msgbuf, socket);
      return;
    }

    //check if the user is in the channel
    if(isUserInChannel(socket, chan) == -1){
      //sprintf(msgbuf, ":%s 404 %s %s :Cannot send to channel\r\n", host, srcUser->user, dest);
      //sendMessage(msgbuf, socket);
      return;
    }

    sprintf(msgbuf, ":%s!%s@hostname NOTICE %s :%s\r\n", srcUser->nick, srcUser->user, dest, msg);
    printf("message was: %s\n", msgbuf);
    messageAllUsers(msgbuf, chan, socket);

  } else {    //user
  
    //find the information of the destination
    struct ClientData * destUser = findUser(dest, &clientList);
    if(destUser == NULL){
      return;
    }
    destsocket = destUser->ourSocket;
    
    //find the nick of the source
    struct ClientData *srcUser = (struct ClientData *)list_seek(&clientList, &socket);
    
    //send the message
    sprintf(msgbuf, ":%s!%s@sentuser NOTICE %s :%s\r\n", srcUser->nick, srcUser->user, dest, msg);
    sendMessage(msgbuf, destsocket);
    return;

  }
}
Example #4
0
void start_of_line(point_t *pt, window *w)
{
	if(!pt)
		pt = w->ui_pos;

	start_of_line_given(list_seek(w->buf->head, pt->y, false), pt);
}
int makeflow_archive_is_preserved(struct archive_instance *a, struct batch_task *t, char *task_path) {
	struct batch_file *f;
	struct stat buf;
	// If the task does NOT adhere to the sandbox or there is a failure with getting the stat
	if(makeflow_archive_task_adheres_to_sandbox(t) || (stat(task_path, &buf) < 0)){
		/* Not helpful unless you know the task number. */
		debug(D_MAKEFLOW_HOOK, "task %d has not been previously archived at %s", t->taskid, task_path);
		return 0;
	}

	struct list_cursor *cur = list_cursor_create(t->output_files);
	// Iterate through output files making sure they all exist
	for(list_seek(cur, 0); list_get(cur, (void**)&f); list_next(cur)) {
		// Get path of the output file
		char *filename = string_format("%s/output_files/%s", task_path, basename(f->inner_name));
		// Check the statistics of the output file at the location
		int file_exists = stat(filename, &buf);
		// If there is a failure with running stat delete the cursor and free memory
		if (file_exists < 0) {
			list_cursor_destroy(cur);
			// Print debug error
			debug(D_MAKEFLOW_HOOK, "output file %s not found in archive at %s: %d %s", 
				f->outer_name, filename, errno, strerror(errno));
			free(filename);
			return 0;
		}
		free(filename);
	}
	// Free list cursor memory
	list_cursor_destroy(cur);

	return 1;
}
Example #6
0
void handle_WHOIS(char** params, int socket)
{
  char msgbuf[512];
  char *nick = params[1];
  char user[500];
  char realname[500];
  struct ClientData * vip = findUser(nick,&clientList); //the VIP who everyone wants to know about, for whom they keep walking around town asking WHOIS in all caps and demanding a reply
  struct ClientData * looker = (struct ClientData *)list_seek(&clientList, &socket);
  char lookernick[10];
  strcpy(lookernick, looker->nick);

  //check if the nick exists
  if(vip == NULL){
    sprintf(msgbuf, ":%s 401 %s %s :No such nick/channel\r\n", host, lookernick, nick);
    sendMessage(msgbuf, socket);
    return;
  }
  strcpy(user, vip->user);
  strcpy(realname, vip->real);

  //send the info
  sprintf(msgbuf, ":%s 311 %s %s %s %s * :%s\r\n", host, lookernick, nick, user, host, realname);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf, ":%s 312 %s %s %s :The best server ever\r\n", host, lookernick, nick, host);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf, ":%s 318 %s %s :End of WHOIS list\r\n", host, lookernick, nick);
  sendMessage(msgbuf, socket);
  
  return;
}
Example #7
0
CK_RV C_SetPIN(CK_SESSION_HANDLE hSession,
	       CK_CHAR_PTR pOldPin, CK_ULONG ulOldLen, CK_CHAR_PTR pNewPin, CK_ULONG ulNewLen)
{
	CK_RV rv;
	struct sc_pkcs11_session *session;
	struct sc_pkcs11_slot *slot;

	if ((pOldPin == NULL_PTR && ulOldLen > 0) || (pNewPin == NULL_PTR && ulNewLen > 0))
		return CKR_ARGUMENTS_BAD;

	rv = sc_pkcs11_lock();
	if (rv != CKR_OK)
		return rv;

	session = list_seek(&sessions, &hSession);
	if (!session) {
		rv = CKR_SESSION_HANDLE_INVALID;
		goto out;
	}

	slot = session->slot;
	sc_log(context, "Changing PIN (session 0x%lx; login user %d)", hSession, slot->login_user);

	if (!(session->flags & CKF_RW_SESSION)) {
		rv = CKR_SESSION_READ_ONLY;
		goto out;
	}

	rv = slot->card->framework->change_pin(slot, pOldPin, ulOldLen, pNewPin, ulNewLen);
out:
	sc_pkcs11_unlock();
	return rv;
}
Example #8
0
void handle_OPER(char **params, int socket) {
    char * name = params[1];
    char * password = params[2];
    char msgbuf[512];
    pthread_mutex_lock(&listLock);
    struct ClientData * ourCli = (struct ClientData *)list_seek(&clientList, &socket);
    pthread_mutex_unlock(&listLock);
    if(ourCli == NULL) {
            printf("Failing on list seek.\n");
    }

    if(strlen(name)<1) {
        //expect a user name but should ignore it
        return;
    }
        //this needs to be updated to be the -o command which is passwd
    if(strcmp(passwd, password) != 0) {
        //ERR_PASSWDMISMATCH
        sprintf(msgbuf, ":%s 464 %s :Password incorrect\r\n", host, ourCli->nick);
        sendMessage(msgbuf, socket);
    }
    else {//update their mode
            if(setMode(ourCli->userModes, 'o')>0) {   //RLP_YOUREOPER     
                 sprintf(msgbuf, ":%s 381 %s :You are now an IRC operator\r\n", host, ourCli->nick);
                 sendMessage(msgbuf, socket);
                 sprintf(msgbuf, ":%s MODE %s :+s\r\n", host, ourCli->nick); //assuming we can trust 3.1.5
            }
    }
    return;
}
Example #9
0
/* Internal version of C_CloseSession that gets called with
 * the global lock held */
static CK_RV sc_pkcs11_close_session(CK_SESSION_HANDLE hSession)
{
	struct sc_pkcs11_slot *slot;
	struct sc_pkcs11_session *session;

	sc_log(context, "real C_CloseSession(0x%lx)", hSession);

	session = list_seek(&sessions, &hSession);
	if (!session)
		return CKR_SESSION_HANDLE_INVALID;

	/* If we're the last session using this slot, make sure
	 * we log out */
	slot = session->slot;
	slot->nsessions--;
	if (slot->nsessions == 0 && slot->login_user >= 0) {
		slot->login_user = -1;
		slot->card->framework->logout(slot);
	}

	if (list_delete(&sessions, session) != 0)
		sc_log(context, "Could not delete session from list!");
	free(session);
	return CKR_OK;
}
Example #10
0
struct list *list_split(struct list *l, list_op_t comparator, const void *arg) {
	assert(l);

	void *item;
	struct list *out = NULL;

	if (!arg) return NULL;
	if (l->length < 2) return NULL;

	struct list_cursor *cur = list_cursor_create(l);
	for (list_seek(cur, 0); list_get(cur, &item); list_next(cur)) {
		if (comparator(item, arg)) break;
	}

	while (list_get(cur, &item)) {
		if (!out) out = list_create();
		struct list_cursor *end = list_cursor_create(out);
		list_insert(end, item);
		list_cursor_destroy(end);
		list_drop(cur);
		list_next(cur);
	}

	list_cursor_destroy(cur);
	return out;
}
Example #11
0
int list_push_head(struct list *l, void *item) {
	struct list_cursor *cur = list_cursor_create(l);
	list_seek(cur, 0);
	list_insert(cur, item);
	list_cursor_destroy(cur);
	return 1;
}
Example #12
0
CK_RV get_session(CK_SESSION_HANDLE hSession, struct sc_pkcs11_session **session)
{
	*session = list_seek(&sessions, &hSession);
	if (!*session)
		return CKR_SESSION_HANDLE_INVALID;
	return CKR_OK;
}
Example #13
0
CK_RV C_Logout(CK_SESSION_HANDLE hSession)
{				/* the session's handle */
	CK_RV rv;
	struct sc_pkcs11_session *session;
	struct sc_pkcs11_slot *slot;

	rv = sc_pkcs11_lock();
	if (rv != CKR_OK)
		return rv;

	session = list_seek(&sessions, &hSession);
	if (!session) {
		rv = CKR_SESSION_HANDLE_INVALID;
		goto out;
	}

	sc_log(context, "C_Logout(hSession:0x%lx)", hSession);

	slot = session->slot;

	if (slot->login_user >= 0) {
		slot->login_user = -1;
		rv = slot->card->framework->logout(slot);
	} else
		rv = CKR_USER_NOT_LOGGED_IN;

      out:sc_pkcs11_unlock();
	return rv;
}
Example #14
0
CK_RV C_Login(CK_SESSION_HANDLE hSession,	/* the session's handle */
	      CK_USER_TYPE userType,	/* the user type */
	      CK_CHAR_PTR pPin,	/* the user's PIN */
	      CK_ULONG ulPinLen)
{				/* the length of the PIN */
	CK_RV rv;
	struct sc_pkcs11_session *session;
	struct sc_pkcs11_slot *slot;

	if (pPin == NULL_PTR && ulPinLen > 0)
		return CKR_ARGUMENTS_BAD;

	rv = sc_pkcs11_lock();
	if (rv != CKR_OK)
		return rv;

	if (userType != CKU_USER && userType != CKU_SO && userType != CKU_CONTEXT_SPECIFIC) {
		rv = CKR_USER_TYPE_INVALID;
		goto out;
	}
	session = list_seek(&sessions, &hSession);
	if (!session) {
		rv = CKR_SESSION_HANDLE_INVALID;
		goto out;
	}

	sc_log(context, "C_Login(0x%lx, %d)", hSession, userType);

	slot = session->slot;

	if (!(slot->token_info.flags & CKF_USER_PIN_INITIALIZED)) {
		rv = CKR_USER_PIN_NOT_INITIALIZED;
		goto out;
	}

	/* TODO: check if context specific is valid */
	if (userType == CKU_CONTEXT_SPECIFIC) {
		if (slot->login_user == -1) {
			rv = CKR_OPERATION_NOT_INITIALIZED;
			goto out;
		} else
		rv = slot->card->framework->login(slot, userType, pPin, ulPinLen);
	} else {
		if (slot->login_user >= 0) {
			if ((CK_USER_TYPE) slot->login_user == userType)
				rv = CKR_USER_ALREADY_LOGGED_IN;
			else
				rv = CKR_USER_ANOTHER_ALREADY_LOGGED_IN;
			goto out;
		}

		rv = slot->card->framework->login(slot, userType, pPin, ulPinLen);
		if (rv == CKR_OK)
			slot->login_user = userType;
	}

      out:sc_pkcs11_unlock();
	return rv;
}
Example #15
0
/*Function to handle a QUIT message -> I assume we want to free the client's user struct */
void handle_QUIT(char** params, int socket)
{
  //find the nick of the quitter
  struct ClientData *srcUser = (struct ClientData *)list_seek(&clientList, &socket);
  list_delete(&clientList, srcUser); //delete the corresponding clientData struct in the list
  close(socket);
  return;
}
Example #16
0
void handle_TOPIC(char** params, int socket) {
  char *chanName = params[1];
  char *msg = params[10];
  char *colonflag = params[9];
  char msgbuf[512];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *userstruct;
  char *newtopic;
  int chandneflag = 0;
  
  //search for user by socket
  //printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  userstruct = (struct ClientData *)list_seek(&clientList, &socket);
  pthread_mutex_unlock(&listLock);
  user = userstruct->user;
  nick = userstruct->nick;

  //search for channel by name
  //printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);

  //if channel doesn't exist
  if(chan == NULL){
    chandneflag = 1;
  }

  //if user is not in channel
  //printf("checking if user is in channel\n");
  if(chandneflag || (isUserInChannel(socket, chan) == -1)){
    sprintf(msgbuf, ":%s 442 %s %s :You're not on that channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //check what the User wants to do, check the topic or change it?
  if(colonflag[0] == 'n'){
    if((chan->topic)[0] != '\0'){
      sprintf(msgbuf, ":%s 332 %s %s :%s\r\n", host, nick, chanName, chan->topic);
      sendMessage(msgbuf, socket);
    } else {
      sprintf(msgbuf, ":%s 331 %s %s :No topic is set\r\n", host, nick, chanName);
      sendMessage(msgbuf, socket);
    }
  } else {
    free(chan->topic);
    newtopic = strdup(msg);
    chan->topic = newtopic;
    sprintf(msgbuf, ":%s!%[email protected] TOPIC %s :%s\r\n", nick, user, chanName, chan->topic);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  }
  
  return;
}
Example #17
0
File: slot.c Project: llogar/OpenSC
CK_RV slot_get_slot(CK_SLOT_ID id, struct sc_pkcs11_slot ** slot)
{
	if (context == NULL)
		return CKR_CRYPTOKI_NOT_INITIALIZED;

	*slot = list_seek(&virtual_slots, &id);	/* FIXME: check for null? */
	if (!*slot)
		return CKR_SLOT_ID_INVALID;
	return CKR_OK;
}
Example #18
0
//doesn't currently handle when user is already in channel
void handle_JOIN(char** params, int socket){
  char *chanName = params[1];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *beingAdded;
  char msgbuf[515];
  int ifnew = 0;
  
  //search for user by socket
  //printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  beingAdded = (struct ClientData *)list_seek(&clientList, &socket);
  printf("%s\n", beingAdded->nick);
  pthread_mutex_unlock(&listLock);
  user = beingAdded->user;
  nick = beingAdded->nick;
  
  //search for channel by name
  printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);

  //if it doesn't exist, create the channel
  if(chan == NULL){
    chan = createChannel(chanName, 0, 0, "", socket);
    pthread_mutex_lock(&chanListLock);
    list_append(&channelList, chan);
    pthread_mutex_unlock(&chanListLock);
    ifnew = 1;
  }
  
  //add user to that channel
  printf("adding user to channel\n");
  //start by checking if user is already joined
  if(isUserInChannel(socket, chan) != -1){
    //printf("user is already in channel\n");
    return;
  } else {
    pairUserWithChannel(beingAdded, chan, ifnew, socket);
  }
  //send out the message
  printf("sending message\n");
  sprintf(msgbuf, ":%s!%s@hostname JOIN %s\r\n", nick, user, chanName); //needs user address
  sendMessage(msgbuf, socket);
  messageAllUsers(msgbuf, chan, socket);
  if((chan->topic)[0] != '\0'){
    sprintf(msgbuf, ":%s 332 %s %s :%s\r\n", host, nick, chanName, chan->topic);
    sendMessage(msgbuf, socket);
  }
  sprintf(msgbuf, ":%s!%s@hostname 353 %s = %s :nicknames eventually go here\r\n", nick, user, nick, chanName);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf, ":%s!%s@hostname 366 %s %s :End of NAMES list\r\n", nick, user, nick, chanName);
  sendMessage(msgbuf, socket);
  return;
}
Example #19
0
void handle_PART(char ** params, int socket) {
  char *chanName = params[1];
  char *msg = params[10];
  char msgbuf[512];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *userstruct;
  
  //printf("msg: %s\n", msg);

  //search for user by socket
  printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  userstruct = (struct ClientData *)list_seek(&clientList, &socket);
  pthread_mutex_unlock(&listLock);
  user = userstruct->user;
  nick = userstruct->nick;
  
  //search for channel by name
  printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);
  
  //if channel doesn't exist
  if(chan == NULL){
    sprintf(msgbuf, ":%s 403 %s %s :No such channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //if user is not in channel
  printf("checking if user is in channel\n");
  if(isUserInChannel(socket, chan) == -1){
    sprintf(msgbuf, ":%s 442 %s %s :You're not on that channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //check if they have a parting message
  if(msg[0] == '\0'){
    //msg = nick;
    sprintf(msgbuf, ":%s!%s@hostname PART %s\r\n", nick, user, chanName);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  } else {
    sprintf(msgbuf, ":%s!%s@hostname PART %s :%s\r\n", nick, user, chanName, msg);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  }
  //do the deed
  printf("actually remvoing user\n");
  removeUser(socket, chan);
  
  return;
}
Example #20
0
///
/// Writes a word of data into the specified bin.
///
/// @param path The path to load.
/// @return Whether the bin was loaded successfully.
///
bool bins_write(freed_bstring name, uint16_t word)
{
	struct ldbin* bin = list_seek(&ldbins.bins, name.ref);
	if (bin == NULL)
	{
		bautodestroy(name);
		return false;
	}
	bin_write(bin, word);
	return true;
}
Example #21
0
void list_free(struct list *l) {
	void *item;

	if (!l)
		return;

	struct list_cursor *cur = list_cursor_create(l);
	for (list_seek(cur, 0); list_get(cur, &item); list_next(cur)) {
		free(item);
	}
	list_cursor_destroy(cur);
}
Example #22
0
/*Function to handle a NICK message to our client by updating the user struct associated with the socket # it's coming from to have the right nickname */
void handle_NICK(char** params, int socket)
{
  char msgbuf[512];
  char *nick;
  char *user;

  //read the nick we got in the command
  nick = params[1];

  //check if the nick is already taken
  struct ClientData * ifused = findUser(nick,&clientList);
  if(ifused != NULL){
    printf("nick was taken\n");
    sprintf(msgbuf, ":%s 433 * %s :Nickname is already in use\r\n", host, nick);
    sendMessage(msgbuf, socket);
    return;
  }

  //look in the list of users for the matching socket number
  pthread_mutex_lock(&listLock);
  struct ClientData * ourCli = (struct ClientData *)list_seek(&clientList, &socket);
  if(ourCli == NULL) {
    printf("Failing on list seek.\n"); 
  }
  //add in their nick
  strcpy(ourCli->nick, nick);
  user = ourCli->user;
  pthread_mutex_unlock(&listLock);

  //list_dump_file(&clientList, "oneuserlist.txt", NULL);

  //logging!
  printf("Client # %d now has nickname %s.\n", ourCli->ourSocket, nick);
  printf("Client # %d also has username %s.\n", ourCli->ourSocket, user);

  //check if they have registered both a nick and a user
  if(nick[0] != '\0' && user[0] != '\0'){
    ourCli->registered = 1; //yay
    sprintf(msgbuf,":%s 001 %s :Welcome to the Internet Relay Network %s!%[email protected]\r\n", host, nick, nick, user);
    //welcome them
    sendMessage(msgbuf, ourCli->ourSocket);
    sprintf(msgbuf, ":%s 002 %s :Your host is %s, running version chirc-0.1\r\n", host, nick, host);
    sendMessage(msgbuf, ourCli->ourSocket);
    sprintf(msgbuf, ":%s 003 %s :This server was created 2012-01-02 13:30:04\r\n", host, nick);
    sendMessage(msgbuf, ourCli->ourSocket);
    sprintf(msgbuf, ":%s 004 %s %s chirc-0.1 ao mtov\r\n", host, nick, host);
    sendMessage(msgbuf, ourCli->ourSocket);
    handle_LUSERS(NULL, socket);
    handle_MOTD(NULL, socket);
  }

  return;
}
Example #23
0
void *list_peek_tail(struct list *l) {
	void *item = NULL;

	if (!l)
		return NULL;

	struct list_cursor *cur = list_cursor_create(l);
	list_seek(cur, -1);
	list_get(cur, &item);
	list_cursor_destroy(cur);

	return item;
}
Example #24
0
void handle_LIST(char **params, int socket){
  printf("at the top of handle_list, plenty of time to fill the printf buffer and send a message\n");
  char msgbuf[512];
  char* nick;
  char *chanName = params[1];
  channel* chan;
  
  struct ClientData * ourCli = (struct ClientData *)list_seek(&clientList, &socket);
  nick = ourCli->nick;

  //printf("Ahfksadkfhkwelkheiowhrihfksadnfnkahseihiofhiohdsfaskdnfkneifhihdisjfkalsdklfjksdjfij\n");
  //printf("chan null is :%d\n", chanName == NULL);
  //printf("shfksadkfhkwelkheiowhrihfksadnfnkahseihiofhiohdsfaskdnfkneifhihdisjfkalsdklfjksdjfij\n");
  if(chanName != NULL){
    chan = (channel *) findChannel(chanName);

    //if channel doesn't exist
    if(chan == NULL){
      return;
    }

    sprintf(msgbuf, ":%s 322 %s %s %d :%s\r\n", host, nick, chanName, chan->nusers, chan->topic); //add stuff
    sendMessage(msgbuf, socket);
    sprintf(msgbuf, ":%s 323 %s :End of LIST\r\n", host, nick);
    sendMessage(msgbuf, socket);
    
  } else {
  
    pthread_mutex_lock(&chanListLock);
    if(list_iterator_start(&channelList) == 0){
      printf("could not iterate list\n");
      return;
    }
    printf("starting channel iterator\n");
    while(list_iterator_hasnext(&channelList)){
      chan = (channel *) list_iterator_next(&channelList);
      printf("sending channel info\n");
      sprintf(msgbuf, ":%s 322 %s %s %d :%s\r\n", host, nick, chan->name, chan->nusers, chan->topic); //add stuff
      sendMessage(msgbuf, socket);  
    }

    list_iterator_stop(&channelList);
    pthread_mutex_unlock(&chanListLock);

    sprintf(msgbuf, ":%s 323 %s :End of LIST\r\n", host, nick);
    sendMessage(msgbuf, socket);
  }
  
  
  return;
}
Example #25
0
/* Function to return a list of users connected/in a channel */
void handle_LUSERS(char** params, int socket)
{
  char msgbuf[512];
  int numUsers = 0;
  int numUnregUsers = 0;
  
  pthread_mutex_lock(&listLock);
  struct ClientData *cur;
  struct ClientData *cli;
  char user[500];

  //iterate through the list of users, get the number that are registered and unregistered
  if(list_iterator_start(&clientList) ==0) 
   {
      printf("Error iterating the list.\n");
      return;
   }
   while(list_iterator_hasnext(&clientList))
   {
     cur = (struct ClientData *)list_iterator_next(&clientList);
     if(cur->registered){
       numUsers++;
     } else {
       numUnregUsers++;
     }
   }
   if(list_iterator_stop(&clientList) == 0)
   {
      printf("Error iterating the list.\n");
      return;
   }
   pthread_mutex_unlock(&listLock);

   //get the client we are sending this to
   cli = (struct ClientData *)list_seek(&clientList, &socket);
   strcpy(user, cli->user);

   //send the message
   sprintf(msgbuf, ":%s 251 %s :There are %d users and 0 services on 1 servers\r\n", host, user, numUsers);
  sendMessage(msgbuf, socket);   
  sprintf(msgbuf,":%s 252 %s 0 :operator(s) online\r\n", host, user);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf, ":%s 253 %s %d :unknown connection(s)\r\n",host, user, numUnregUsers);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf,":%s 254 %s 0 :channels formed\r\n",host, user);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf,":%s 255 %s :I have %d clients and 1 servers\r\n",host, user, numUsers+numUnregUsers);
  sendMessage(msgbuf, socket);
  return;
}
Example #26
0
static int m_word1(
		const buffer_t *buf, const int dir,
		const bool end, const bool big_words,
		point_t *to)
{
	list_t *l = list_seek(buf->head, to->y, false);

	enum word_state st = word_state(l, to->x, big_words);
	bool find_word = true;

	if(st & (W_KEYWORD | W_NON_KWORD)){
		/* we're on a word - if we're an end motion and not at the end,
		 * just need to move to the end */
		if(end == (dir > 0)){
			if(word_state(l, to->x + dir, big_words) != st){
				/* at the end - next */
			}else{
				/* seek to end and we're done */
				word_seek_to_end(l, dir, to, big_words);
				return MOTION_SUCCESS;
			}
		}

		/* skip to space or other word type */
		enum word_state other_word = ((W_KEYWORD | W_NON_KWORD) & ~st);

		l = word_seek(l, dir, to, W_SPACE | other_word, big_words);

		/* if we're on another word type, we're done */
		if(word_state(l, to->x, big_words) & other_word)
			find_word = false;
		else if(!l || !l->len_line)
			find_word = false; /* onto a new and empty - stop */
		/* else space - need to find the next word */

	}else{
		/* on space or none, go to next word */
	}

	if(find_word){
		l = word_seek(l, dir, to, W_KEYWORD | W_NON_KWORD, big_words);
		if(!l)
			return MOTION_FAILURE;
	}

	if(end == (dir > 0))
		word_seek_to_end(l, dir, to, big_words);

	return MOTION_SUCCESS;
}
Example #27
0
struct list *list_duplicate(struct list *src) {
	void *item;
	struct list *dst = list_create();
	struct list_cursor *src_cur = list_cursor_create(src);
	struct list_cursor *dst_cur = list_cursor_create(dst);

	for (list_seek(src_cur, 0); list_get(src_cur, &item); list_next(src_cur)) {
		list_insert(dst_cur, item);
	}

	list_cursor_destroy(src_cur);
	list_cursor_destroy(dst_cur);
	return dst;
}
Example #28
0
void *list_pop_head(struct list *l) {
	void *item = NULL;

	if (!l)
		return NULL;

	struct list_cursor *cur = list_cursor_create(l);
	list_seek(cur, 0);
	list_get(cur, &item);
	list_drop(cur);
	list_cursor_destroy(cur);

	return item;
}
Example #29
0
void list_delete(struct list *l) {
	if (!l)
		return;

	struct list_cursor *cur = list_cursor_create(l);
	list_seek(cur, 0);
	do {
		list_drop(cur);
	} while (list_next(cur));
	list_cursor_destroy(cur);

	bool ok = list_destroy(l);
	assert(ok);
}
Example #30
0
int actorrun(actorrun_arg_t * args){
    void * persistent_data = NULL;
    while(1){
        message * msg = threadsafe_deq(args->queue);
        if(msg == NULL){
            usleep(1000); //TODO: set this up with condition variable
        } else {
            handler * hnd = list_seek(&(args->handler->handlers), &(msg->msgtype));
            (hnd->handling_function)(msg->data, &persistent_data);
            free(msg);
        }
    }
    return 0;
}