Beispiel #1
0
/*
 * This is clever, say you want to change the console to use two
 * files for out/err.  You pass in two strings, it will properly
 * close the existing handles (if they're not std* handles) and
 * open them.  Now say you want TO use stdout and stderr, this
 * allows you to do that so long as you cast them to (char*).
 * Say you need stdout for out, but want a file for error, you can
 * do this too, just cast the stdout for (char*) and stick to a
 * string for the error file.
 */
int con_change(const char *out, const char *err) {
    con_close();

    if (!out) out = (const char *)((!console.handle_out) ? (fs_file_t*)stdout : console.handle_out);
    if (!err) err = (const char *)((!console.handle_err) ? (fs_file_t*)stderr : console.handle_err);

    if (GMQCC_IS_DEFINE(out)) {
        console.handle_out = (fs_file_t*)(GMQCC_IS_STDOUT(out) ? stdout : stderr);
        con_enablecolor();
    } else if (!(console.handle_out = fs_file_open(out, "w"))) return 0;

    if (GMQCC_IS_DEFINE(err)) {
        console.handle_err = (fs_file_t*)(GMQCC_IS_STDOUT(err) ? stdout : stderr);
        con_enablecolor();
    } else if (!(console.handle_err = fs_file_open(err, "w"))) return 0;

    return 1;
}
Beispiel #2
0
void *client_handler(void *input) {
    client_state_t *state = (client_state_t *) input;
    int error = 0;

    if (!input) return NULL;
    init_client(input);
    printf("client_handler starting\n");
    state->state |= CLIENT_STATE_CONNECTED;
    global_addclient(state->global,state);
    while (state->thread_state == THREAD_STATE_RUNNING) {
        if ((error = client_subrun(state)) == CON_ERROR_NONE) continue;
        printf("Client break, reason: %d\n",error);
        break;
    }
    printf("Done client %d\n",state->thread_state);
    char *text = malloc(128);
    sprintf(text, "LEAVE %s\r\n", state->username);
    global_send_others(state->global, text, state);
    if (con_is_ok(state->connection)) con_close(state->connection);
    global_delclient(state->global, state);
    state_client_free(state);
    return NULL;
}
Beispiel #3
0
int http_response_create(struct server_conf *server,http_request_line_t *request,http_response_t *response){
        char path[MAX_FILENAME_LEN];
        char buf[BUFF_SIZE];
        char *ls=NULL,*content=NULL;
	int response_len;
        if(server&&server->docroot)
                strncpy(path,server->docroot,strlen(server->docroot)+1);
        else
                strncpy(path,ROOTDIR,strlen(ROOTDIR)+1);
        if(request->uri_start==request->uri_end){
        //if(request->uri_end=request->uri_start){	
                ls=http_response_ls(path);
                if(ls){
			//printf("ls len is %d\n",strlen(ls));
                        http_response_add_status_line(response,200,desc_200);
                        sprintf(buf,"Content-length:%d",strlen(ls));
                        http_response_add_headers(response,buf);
			con_close(response);
                        http_response_add_body(response,ls);
			//printf("response: %d\n%s\n",response->len,response->data);
			//printf("header length is %d\n",strlen(buf)+17);
                        write(request->fd,response->data,response->len);
                        free(ls);
			free_response(response);
			return 1;
                }//endif
		else{
			log_debug(LOG_LEVEL_DEBUG,"open for document root dir failed!");
			http_response_send_error(request->fd,500,desc_500,content_500);
			return(-1);

		}//end else
        }//endif uri is "/",do ls -la
        else{
		/*main work*/	
		printf("path:%s\n",path);
		strncat(path,request->uri_start,request->uri_end-request->uri_start+1);
		printf("path:%s\n",path);
		content=http_response_readfile(path);
		if(!content){
		//404
		    http_response_send_error(request->fd,404,desc_404,content_404);
		    log_debug(LOG_LEVEL_DEBUG,"send not found!");
		    return 1;
		}
		//printf("content is 0x%x\n",content);
                http_response_add_status_line(response,200,desc_200);
		response_len=strlen(content);
                sprintf(buf,"Content-length:%d",response_len);
                http_response_add_headers(response,buf);
		con_close(response);
                //printf("response:%s\n",content);
		http_response_add_body(response,content);
		//printf("content ok\n");
                write(request->fd,response->data,response->len);
                //printf("content len is %d\n",strlen(content));
		//printf("free content(0x%x)\n",content);
		free(content);
		content=NULL;
		free_response(response);
		return 1;
        }//end else
}
Beispiel #4
0
void con_reset() {
    con_close();
    con_init ();
}