Пример #1
0
int main(int ac, char **av)
{
    char *p, c;
    char buf[BUFSIZE];

    while ( (p = fgets(buf,BUFSIZE,stdin)) != NULL )
    {
        c = *p++;
        if ( *p++ != '=' )
            continue;
        switch ( c )
        {
        case 'G':
            parse_global(p);
            break;
        case 'T':
            parse_time_stats(p);
            break;
        case 'C':
            parse_client(p);
            break;
        case 'P':
            parse_pool(p);
            break;
        case 'S':
            parse_shared_pool(p);
            break;
        default:
            continue;
        }
    }
    return 0;
}
Пример #2
0
Файл: irc.c Проект: csko/yaosp
int irc_handle_join( const char* client, const char* chan){
    int error;
    client_t _client;

    error = parse_client(client, &_client);

    if(error != 0){
        return error;
    }

    /* If we join a channel, create a new channel in our internal array */
    if(strcmp(_client.nick, my_nick) == 0){
        error = create_chan(chan);

        if(error != 0){
            return error;
        }

    }

    /* Add new user to the user list of channel */
    addnick_chan(chan, _client.nick, 0);

    return 0;
}
Пример #3
0
/** Handle received data from a new (unregistered) connection.
 * @param[in] cptr Unregistered connection that sent us data.
 * @param[in] buffer Input buffer.
 * @param[in] length Number of bytes in input buffer.
 * @return 1 on success or CPTR_KILLED if the client is squit.
 */
int connect_dopacket(struct Client *cptr, const char *buffer, int length)
{
  const char* src;
  char*       endp;
  char*       client_buffer;

  assert(0 != cptr);

  update_bytes_received(cptr, length);

  client_buffer = cli_buffer(cptr);
  endp = client_buffer + cli_count(cptr);
  src = buffer;

  while (length-- > 0)
  {
    *endp = *src++;
    /*
     * Yuck.  Stuck.  To make sure we stay backward compatible,
     * we must assume that either CR or LF terminates the message
     * and not CR-LF.  By allowing CR or LF (alone) into the body
     * of messages, backward compatibility is lost and major
     * problems will arise. - Avalon
     */
    if (IsEol(*endp))
    {
      /* Skip extra LF/CR's */
      if (endp == client_buffer)
        continue;
      *endp = '\0';

      update_messages_received(cptr);

      if (parse_client(cptr, cli_buffer(cptr), endp) == CPTR_KILLED)
        return CPTR_KILLED;
      /* Socket is dead so exit */
      if (IsDead(cptr))
        return exit_client(cptr, cptr, &me, cli_info(cptr));
      else if (IsServer(cptr))
      {
        cli_count(cptr) = 0;
        return server_dopacket(cptr, src, length);
      }
      endp = client_buffer;
    }
    else if (endp < client_buffer + BUFSIZE)
      /* There is always room for the null */
      ++endp;
  }
  cli_count(cptr) = endp - cli_buffer(cptr);
  return 1;
}
Пример #4
0
/** Handle received data from a local client.
 * @param[in] cptr Local client that sent us data.
 * @param[in] length Total number of bytes in client's input buffer.
 * @return 1 on success or CPTR_KILLED if the client is squit.
 */
int client_dopacket(struct Client *cptr, unsigned int length)
{
  assert(0 != cptr);

  update_bytes_received(cptr, length);
  update_messages_received(cptr);

  if (CPTR_KILLED == parse_client(cptr, cli_buffer(cptr), cli_buffer(cptr) + length))
    return CPTR_KILLED;
  else if (IsDead(cptr))
    return exit_client(cptr, cptr, &me, cli_info(cptr));

  return 1;
}
Пример #5
0
static void handle_clients() {
    prev_client = NULL;
    current_client = active_clients;
    while (current_client) {
        DEBUG_OUT("Handling client: %d\n", current_client->socket);
        /* Read to the client */
        int bytes_read;
        while (current_client->buffer_content < CLIENT_RECV_BUFFER && (bytes_read = read(current_client->socket, &current_client->buffer[current_client->buffer_content], CLIENT_RECV_BUFFER - current_client->buffer_content)) > 0) {
            DEBUG_OUT("Read %d bytes from %d\n", bytes_read, current_client->socket);
            current_client->buffer_content += bytes_read;
        }
        DEBUG_OUT("bytes_read is %d\n", bytes_read);
        /* Either buffer is full, or we have read all that the client has sent, or the client has disconnected */
        if (bytes_read == 0) {
            DEBUG_OUT("Client disconnected\n");
            /* Client has disconnected */
            current_client->should_disconnect = 1;
        } else {
            current_client->buffer[current_client->buffer_content] = 0;
            parse_client(current_client);
            /* If buffer is full at this point in time then we cannot handle the next message from the client */
            if (current_client->buffer_content == CLIENT_RECV_BUFFER) {
                DEBUG_OUT("Buffer is full.\n");
                current_client->should_disconnect = 1;
            }
        }

        if (current_client->should_disconnect) {
            close(current_client->socket);
            FD_CLR(current_client->socket, &readset);
            if (prev_client != NULL) {
                DEBUG_OUT("Setting prev_client->next\n");
                prev_client->next = current_client->next;
            }
            if (active_clients == current_client) {
                DEBUG_OUT("Setting active_clients\n");
                active_clients = current_client->next;
            }
            client * tmp = current_client->next;
            current_client->next = free_clients;
            free_clients = current_client;
            current_client = tmp;
        } else {
            prev_client = current_client;
            current_client = current_client->next;
        }
    }
}
Пример #6
0
int		main(int ac, char **av)
{
	int				sock;
	t_env			*e;
	t_client		client;

	if (ac < 3)
	{
		printf("Not enough arg\n");
		return (-1);
	}
	sock = 0;
	parse_client(av, ac, &client);
	e = (t_env *)malloc(sizeof(t_env));
	printf("%s et %s\n", client.host, client.port);
	client.name = ft_strjoin(client.name, "\n");
	init_client(sock, e, client);
	return (0);
}
Пример #7
0
Файл: irc.c Проект: csko/yaosp
int irc_handle_mode( const char* sender, const char* chan, const char* msg){
    char buf[ 256 ];
    view_t* channel;
    struct client _sender;
    int error;

    time_t now;
    char timestamp[ 128 ];

    error = parse_client(sender, &_sender);

    if ( error < 0 ) {
        return error;
    }

    channel = ui_get_channel( chan );

    if ( channel == NULL ) {
        return -1;
    }

    /* Create timestamp */

    time( &now );

    if ( now != ( time_t )-1 ) {
        struct tm tmval;

        gmtime_r( &now, &tmval );
        strftime( ( char* )timestamp, sizeof( timestamp ), timestamp_format, &tmval );
    } else {
        timestamp[ 0 ] = 0;
    }

    snprintf( buf, sizeof( buf ), "%s {%s} %s", timestamp, _sender.nick, msg );

    view_add_text( channel, buf );

    return 0;
}
Пример #8
0
static int parse(struct radproxy_data *cfg, int linenum, char *args[], int argc)
{
	char *errmsg = NULL;
	static int kwtype = 0;

	if (argc <= 0) {
		printf("line %d: no parameter\n", linenum);
		return -1;
	}

	if (strcasecmp(args[0], "listen") == 0) {
		kwtype = KW_LISTEN;
	} else if (strcasecmp(args[0], "client") == 0) {
		kwtype = KW_CLIENT;
		return 0;
	}
	/*else {
		printf("line %d: unknown keyword '%s'", linenum, args[0]);
		return -2;
	}*/

	switch(kwtype)
	{
	case KW_CLIENT:
		{
			struct radproxy_client *c = parse_client(linenum, args, argc);
			if (!c)
				goto error;
			if (!cfg->clients) {
				cfg->clients = c;
			} else {
				struct radproxy_client *p = cfg->clients;
				while (p && p->next) p=p->next;
				p->next = c;
			}
		}
		break;
	case KW_LISTEN:
		{
			struct radproxy_desc *p;
			if (strcasecmp(args[0], "listen") == 0) {
				if (argc != 2) {
					errmsg = "a port number needed after keyword listen";
					goto error;
				}

				p = calloc(1, sizeof(*p));
				if (!p)
					goto error;

				p->port = atoi(args[1]);
				if (p->port <= 0) {
					errmsg = "invalid port number";
					goto error;
				}

				if (cfg->proxys) {
					struct radproxy_desc *q = cfg->proxys;
					while (q && q->next) q = q->next;
					q->next = p;
				} else {
					cfg->proxys = p;
				}
				break;
			}

			p = cfg->proxys;
			while (p &&p->next) p=p->next;
			if (!p) {
				errmsg = "go hell";
				goto error;
			}
			if (strcasecmp(args[0], "mode") == 0) {
				if (argc != 2) {
					goto error;
				}

				if (strcasecmp(args[1], "radius") == 0) {
					p->mode = mode_radius;
				} else if (strcasecmp(args[1], "udp") == 0) {
					p->mode = mode_udp;
				} else {
					errmsg = "unknown mode";
					goto error;
				}
			} else if (strcasecmp(args[0], "option") == 0) {
				if (argc < 2) {
					errmsg = "not enough parameter after keyword option";
					goto error;
				}

				if (strcasecmp(args[1], "state") == 0) {
					p->option |= OPTION_STATE;
					if (argc != 3) {
						errmsg = "a state timeout number needed after 'state'";
						goto error;
					}
					p->state_timeout = atoi(args[2]);
					if (p->state_timeout < 0) {
						p->state_timeout = 60;
						printf("invalid state timeout value '%d', reset to 60s\n", p->state_timeout);
					}
					p->ht_state = fr_hash_table_create(hash_state, hash_state_cmp, NULL);
				} else if (strcasecmp(args[1], "roundrobin") == 0) {
					p->option |= OPTION_ROUND_ROBIN;
				} else if (strcasecmp(args[1], "source") == 0) {
					p->option |= OPTION_SOURCE;
				} else if (strcasecmp(args[1], "sign") == 0) {
					p->option |= OPTION_SIGN;
				} else if (strcasecmp(args[1], "packchk") == 0) {
					p->option |= OPTION_PACK_CHECK;
				} else if (strcasecmp(args[1], "failover") == 0) {
					p->option |= OPTION_FAILOVER;
					if (argc != 5) {
						errmsg = "parameter 'interv'(s) 'timeout'(ms) 'maxtry' needed after keyword 'failover'";
						goto error;
					}

					p->interv = atoi(args[2]);
					p->timeout = atoi(args[3]);
					p->maxtry = atoi(args[4]);

					if (p->interv <= 0)
						p->interv = 10;
					if (p->timeout <= 0)
						p->timeout = 3000;
					if (p->maxtry <= 0)
						p->maxtry = 3;
				} else {
					printf("line %d: unknown keyword '%s'\n", linenum, args[1]);
					goto error;
				}
			} else if (strcasecmp(args[0], "server") == 0) {
				struct radproxy_backend_server *s = parse_server(linenum, args+1, argc-1);
				if (s) {
					struct radproxy_backend_server **q = realloc(p->servers, (p->server_cnt+1)*sizeof(struct radproxy_back_server*));
					if (q) {
						q[p->server_cnt] = s;
						p->servers = q;
						p->server_cnt += 1;
					}
				} else {
					goto error;
				}
			} else if (strcasecmp(args[0], "name") == 0) {
				if (argc >= 2) {
					if (p->name)
						free(p->name);
					p->name = strdup(args[1]);
				}
			}

		}
		break;
	}

	return 0;

error:
	if (errmsg)
	printf("line %d: %s\n", linenum, errmsg);
	return 1;
}