Add to check the input length
[platform/core/multimedia/libmedia-thumbnail.git] / server / thumb-server.c
1 /*
2  * media-thumbnail-server
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include "media-thumbnail.h"
23 #include "media-thumb-debug.h"
24 #include "media-thumb-ipc.h"
25 #include "media-thumb-util.h"
26 #include "thumb-server-internal.h"
27 #include <pthread.h>
28
29 #ifdef LOG_TAG
30 #undef LOG_TAG
31 #endif
32
33 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
34
35 static GMainLoop *g_thumb_server_mainloop;
36
37 int main(void)
38 {
39         int sockfd = -1;
40         GIOChannel *channel = NULL;
41
42         if (ms_cynara_initialize() != MS_MEDIA_ERR_NONE) {
43                 thumb_err("Cynara initialization failed");
44                 return -1;
45         }
46
47         /* Create and bind new tcp socket */
48         if (!_thumb_server_prepare_socket(&sockfd)) {
49                 thumb_err("Failed to create socket");
50                 return -1;
51         }
52
53         g_thumb_server_mainloop = g_main_loop_new(NULL, FALSE);
54
55         /* Create new channel to watch tcp socket */
56         channel = g_io_channel_unix_new(sockfd);
57         g_io_add_watch(channel, G_IO_IN, _thumb_server_read_socket, g_thumb_server_mainloop);
58         g_io_channel_unref(channel);
59
60         g_idle_add(_thumb_daemon_start_jobs, NULL);
61
62         thumb_info("Thumbnail server is running");
63         g_main_loop_run(g_thumb_server_mainloop);
64
65         thumb_info("Thumbnail server is shutting down");
66         close(sockfd);
67         g_main_loop_unref(g_thumb_server_mainloop);
68         ms_cynara_finish();
69
70         return 0;
71 }