1/*
2 * Copyright 2009 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Author(s):
6 *		Ma Jie, china.majie at gmail
7 */
8
9#include "PoorManLogger.h"
10
11#include <time.h>
12#include <netinet/in.h>
13
14#include <Messenger.h>
15#include <Message.h>
16#include <TypeConstants.h>
17
18#include "PoorManApplication.h"
19#include "PoorManWindow.h"
20#include "libhttpd.h"
21
22void
23poorman_log(const char* msg, bool needTimeHeader,
24	httpd_sockaddr* addr, rgb_color color)
25{
26	time_t now = time(NULL);
27
28	PoorManWindow* window = static_cast<PoorManApplication*>(be_app)->GetPoorManWindow();
29
30	if(!window->LogConsoleFlag() && !window->LogFileFlag())
31		return;
32
33	BMessenger messenger(window);
34	BMessage message(MSG_LOG);
35
36	if(message.AddString("cstring", msg) != B_OK)
37		return;
38	if(needTimeHeader){
39		if(message.AddData("time_t", B_TIME_TYPE, &now, sizeof(time_t)) != B_OK)
40			return;
41	}
42	if(addr != NULL)
43		message.AddString("addr", httpd_ntoa(addr));
44
45	if(color != BLACK)
46		message.AddData("rgb_color", B_RGB_COLOR_TYPE, &color, sizeof(rgb_color));
47
48	messenger.SendMessage(&message, (BHandler*)NULL, 1000000);
49}
50