OSDN Git Service

v1.0.2.8 master
authorAkira <akohta001@gmail.com>
Sun, 2 Feb 2014 01:55:22 +0000 (10:55 +0900)
committerAkira <akohta001@gmail.com>
Sun, 2 Feb 2014 01:55:22 +0000 (10:55 +0900)
Support
・alert timer.
・open 2ch link

36 files changed:
Makefile
Makefile.in
README
config.h
configure
configure.ac
help.txt
nce/account.php
nce/http_util.php
nce/nc_delete_attribute_db.php
nce/nc_delete_lines_file.php
nce/nc_insert_lines_file.php
nce/nc_write_file.php
src/_2ch/_2ch.c
src/_2ch/model_property.c
src/_2ch/parse_string.c
src/_2ch/search_2ch.c
src/cloud/nt_cloud2.c
src/inc/_2ch/model_2ch.h
src/inc/_2ch/search_2ch.h
src/inc/config.h
src/inc/env.h
src/inc/net/nt_http.h
src/inc/nt_string.h
src/inc/ui/disp.h
src/main.c
src/net/nt_http.c
src/net/nt_socket.c
src/ui/disp_alert.c [new file with mode: 0644]
src/ui/disp_reslist.c
src/utils/base64.c
src/utils/crypt.c
src/utils/db.c
src/utils/nt_pthread.c
src/utils/nt_std_t.c
src/utils/zip.c

index b470760..de6732b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,7 @@ OBJS = ${OBJ_DIR}/main.o ${OBJ_DIR}/utils/nt_std_t.o \
     ${OBJ_DIR}/ui/disp_history.o \
     ${OBJ_DIR}/ui/disp_win.o \
     ${OBJ_DIR}/ui/disp_editor.o \
+    ${OBJ_DIR}/ui/disp_alert.o \
     ${OBJ_DIR}/ui/disp_html_result.o \
     ${OBJ_DIR}/ui/disp_string.o
 
@@ -120,7 +121,7 @@ memtest :
        valgrind --leak-check=yes --track-origins=yes -v ./${TARGET}
 
 memtest2 :
-       valgrind --tool=helgrind --leak-check=yes --track-origins=yes -v ./${TARGET}
+       valgrind --tool=helgrind -v ./${TARGET}
 
 ${TARGET} : ${OBJS}
        ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS}
@@ -316,6 +317,10 @@ $(OBJ_DIR)/ui/disp_editor.o : ${SRC_DIR}/ui/disp_editor.c ${INC_FILES}
        @ ${SHELL} prepare_proj.sh
        ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 
 
+$(OBJ_DIR)/ui/disp_alert.o : ${SRC_DIR}/ui/disp_alert.c ${INC_FILES}
+       @ ${SHELL} prepare_proj.sh
+       ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 
+
 $(OBJ_DIR)/ui/disp_html_result.o : ${SRC_DIR}/ui/disp_html_result.c ${INC_FILES}
        @ ${SHELL} prepare_proj.sh
        ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 
index d146514..41d4bd0 100644 (file)
@@ -52,6 +52,7 @@ OBJS = ${OBJ_DIR}/main.o ${OBJ_DIR}/utils/nt_std_t.o \
     ${OBJ_DIR}/ui/disp_history.o \
     ${OBJ_DIR}/ui/disp_win.o \
     ${OBJ_DIR}/ui/disp_editor.o \
+    ${OBJ_DIR}/ui/disp_alert.o \
     ${OBJ_DIR}/ui/disp_html_result.o \
     ${OBJ_DIR}/ui/disp_string.o
 
@@ -120,7 +121,7 @@ memtest :
        valgrind --leak-check=yes --track-origins=yes -v ./${TARGET}
 
 memtest2 :
-       valgrind --tool=helgrind --leak-check=yes --track-origins=yes -v ./${TARGET}
+       valgrind --tool=helgrind -v ./${TARGET}
 
 ${TARGET} : ${OBJS}
        ${CC} ${CFLAGS} -o $@ ${OBJS} ${LIBS}
@@ -316,6 +317,10 @@ $(OBJ_DIR)/ui/disp_editor.o : ${SRC_DIR}/ui/disp_editor.c ${INC_FILES}
        @ ${SHELL} prepare_proj.sh
        ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 
 
+$(OBJ_DIR)/ui/disp_alert.o : ${SRC_DIR}/ui/disp_alert.c ${INC_FILES}
+       @ ${SHELL} prepare_proj.sh
+       ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 
+
 $(OBJ_DIR)/ui/disp_html_result.o : ${SRC_DIR}/ui/disp_html_result.c ${INC_FILES}
        @ ${SHELL} prepare_proj.sh
        ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< 
diff --git a/README b/README
index 20ee13f..f28ffa7 100644 (file)
--- a/README
+++ b/README
@@ -1,5 +1,5 @@
 
-    ntch  version 1.0.2.7
+    ntch  version 1.0.2.8
 
     This file is part of ntch.
 
index cdc4316..24676ca 100644 (file)
--- a/config.h
+++ b/config.h
 #define PACKAGE_NAME "ntch"
 
 /* Define to the full name and version of this package. */
-#define PACKAGE_STRING "ntch 1.0.2.7"
+#define PACKAGE_STRING "ntch 1.0.2.8"
 
 /* Define to the one symbol short name of this package. */
 #define PACKAGE_TARNAME "ntch"
 #define PACKAGE_URL "https://sourceforge.jp/projects/ntch/"
 
 /* Define to the version of this package. */
-#define PACKAGE_VERSION "1.0.2.7"
+#define PACKAGE_VERSION "1.0.2.8"
 
 /* Define to 1 if you have the ANSI C header files. */
 #define STDC_HEADERS 1
index 0d1062e..1ea14bb 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for ntch 1.0.2.7.
+# Generated by GNU Autoconf 2.69 for ntch 1.0.2.8.
 #
 # Report bugs to <akohta001@gmail.com>.
 #
@@ -580,8 +580,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='ntch'
 PACKAGE_TARNAME='ntch'
-PACKAGE_VERSION='1.0.2.7'
-PACKAGE_STRING='ntch 1.0.2.7'
+PACKAGE_VERSION='1.0.2.8'
+PACKAGE_STRING='ntch 1.0.2.8'
 PACKAGE_BUGREPORT='akohta001@gmail.com'
 PACKAGE_URL='https://sourceforge.jp/projects/ntch/'
 
@@ -1230,7 +1230,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures ntch 1.0.2.7 to adapt to many kinds of systems.
+\`configure' configures ntch 1.0.2.8 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1291,7 +1291,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of ntch 1.0.2.7:";;
+     short | recursive ) echo "Configuration of ntch 1.0.2.8:";;
    esac
   cat <<\_ACEOF
 
@@ -1372,7 +1372,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-ntch configure 1.0.2.7
+ntch configure 1.0.2.8
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1795,7 +1795,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by ntch $as_me 1.0.2.7, which was
+It was created by ntch $as_me 1.0.2.8, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -4797,7 +4797,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by ntch $as_me 1.0.2.7, which was
+This file was extended by ntch $as_me 1.0.2.8, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -4864,7 +4864,7 @@ _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-ntch config.status 1.0.2.7
+ntch config.status 1.0.2.8
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
index 5e0d736..ef51e65 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ([2.69])
-AC_INIT([ntch], [1.0.2.7], [akohta001@gmail.com],[ntch],[https://sourceforge.jp/projects/ntch/])
+AC_INIT([ntch], [1.0.2.8], [akohta001@gmail.com],[ntch],[https://sourceforge.jp/projects/ntch/])
 AC_CONFIG_SRCDIR([src/main.c])
 AC_CONFIG_HEADERS([config.h])
 
index 3cfe6ba..0c38180 100644 (file)
--- a/help.txt
+++ b/help.txt
@@ -1,5 +1,5 @@
 
-    ntch  version 1.0.2.7
+    ntch  version 1.0.2.8
 
     This file is part of ntch.
 
@@ -165,6 +165,16 @@ Linux用 2ch専用ブラウザー
                            例  
                           :ngwd \\/[a-z]/   左は正規表現を使わずに文字列として
                                            /[a-z]/ にマッチします。
+    :timer [ NNNN | NNNm | NNNs ]    指定時間後に通知ダイアログを表示します
+                    NNNN 表示するまでの時間をミリ秒で指定します
+                         例: :timer 120000 (2分をミリ秒で指定)
+                    NNNm 時間を分単位で指定します
+                         例: :timer 2m (2分を分単位で指定)
+                    NNNs 時間を秒単位で指定します
+                         例: :timer 120s (2分を秒単位で指定)
+    :link :l  [2ch アドレス]   2chのリンクを指定して開きます(前スレなどの表示に使います)
+                    例: :link http://pc11.2ch.net/test/read.cgi/linux/1118024349/  
+                    ※ 何らかの理由で開けないこともあります
 
 お気に入り一覧
     d   選択項目をお気に入りから削除
index b1c5213..93a4ac0 100644 (file)
@@ -8,6 +8,7 @@
  */
 include_once "user.php";
 include_once "database.php";
+include_once "http_util.php";
 
 
 $ERROR_MSG;
@@ -50,6 +51,19 @@ SELECT_USER;
        return $user;
 }
 
+function chk_file_name(&$val){
+       if(!isset($val)){
+               return false;
+       }
+       if(0 == strlen($val)){
+               return false;
+       }
+       if(FALSE === inspect_file_name($val)){
+               return false;
+       }
+       return true;
+}
+
 function chk_param(&$val){
        if(!isset($val)){
                return false;
@@ -57,8 +71,8 @@ function chk_param(&$val){
        if(0 == strlen($val)){
                return false;
        }
-       if(!get_magic_quotes_gpc()){
-               $val = addslashes($val);
+       if(FALSE === inspect_base64_param($val)){
+               return false;
        }
        return true;
 }
index 29cad17..971fb72 100644 (file)
@@ -6,8 +6,10 @@
  date: 2013-apr-13th
  License: GPLv3
  */
-$needle_64encode = array("=","+","/");
-$needle_urlencode = array("%3D","%2B","%2f");
+$needle_64encode = array("=","+","/","=","+","/");
+$needle_urlencode = array("%3D","%2B","%2F","%3d","%2b","%2f");
+$base64_param_pattern = "/^([a-zA-Z0-9]|\%2B|\%2F|\+|\/)+(\%3D|=){0,2}$/i";
+$file_name_pattern = "/^(\w)+((\.)?[a-zA-Z0-9]*)*$/";
 
 function replace_64symbol2urlencode($source){
        global $needle_64encode;
@@ -24,4 +26,21 @@ function replace_urlencodeTo64symbol($source){
                $needle_64encode, $source);
        return $result;
 }
+
+function inspect_base64_param($param){
+       global $base64_param_pattern;
+       if(preg_match($base64_param_pattern, $param)){
+               return TRUE;
+       }else{
+               return FALSE;
+       }
+}
+function inspect_file_name($param){
+       global $file_name_pattern;
+       if(preg_match($file_name_pattern, $param)){
+               return TRUE;
+       }else{
+               return FALSE;
+       }
+}
 ?>
\ No newline at end of file
index eac6906..64c1af8 100644 (file)
@@ -30,7 +30,7 @@ if(FALSE === $user){
 
 //--- parameter check start ---
 if(!chk_param($board_name) || !chk_param($dat_name) ||
-       !chk_param($res_number) || !chk_param($record_type)){
+       !chk_param($res_number)){
        echo ERROR303;
        exit;
 }
index a5bfe76..821001f 100644 (file)
@@ -25,7 +25,7 @@ if(FALSE === $user){
        exit;
 }
 
-if(!chk_param($file_name) || !$num || FALSE == is_numeric($num)){
+if(!chk_file_name($file_name) || !$num || FALSE == is_numeric($num)){
        echo ERROR303;
        exit;
 }
index 23f8ecd..6de5751 100644 (file)
@@ -25,7 +25,7 @@ if(FALSE === $user){
        exit;
 }
 
-if(!chk_param($file_name) || !$num || FALSE == is_numeric($num)){
+if(!chk_file_name($file_name) || !$num || FALSE == is_numeric($num)){
        echo ERROR303;
        exit;
 }
index e125c76..c9e258e 100644 (file)
@@ -25,7 +25,7 @@ if(FALSE === $user){
        exit;
 }
 
-if(!chk_param($file_name) || !$data){
+if(!chk_file_name($file_name) || !$data){
        echo ERROR303;
        exit;
 }
@@ -63,5 +63,5 @@ fclose($fp);
 
 
 echo SUCCESS100;
-echo "\n".$file_path;
+
 ?>
index aca3d42..ef3344f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -967,6 +967,7 @@ BOOL nt_set_sel_item(nt_2ch_model_handle h_model,
                        nt_searched_thread_handle h_searched_thread, const wchar_t** errorpp)
 {
        const wchar_t *board_name, *dat_name, *title;
+       wchar_t *cptr;
        nt_category_handle h_category;
        nt_board_handle h_board;
        nt_thread_handle h_thread;
@@ -975,6 +976,8 @@ BOOL nt_set_sel_item(nt_2ch_model_handle h_model,
        
        assert(h_sel_itemp);
        
+       h_thread = NULL;
+       
        h_sel_item = nt_2ch_selected_item_alloc();
        if(!h_sel_item){
                return FALSE;
@@ -1019,8 +1022,9 @@ BOOL nt_set_sel_item(nt_2ch_model_handle h_model,
        h_thread = nt_get_thread_by_dat_name(h_board, dat_name);
        if(!h_thread){
                if(!title)
-                       title = L"Dummy";
-               h_thread = nt_thread_dummy_alloc(title, dat_name, 0);
+                       h_thread = nt_thread_dummy_alloc(L"Dummy", dat_name, 0);
+               else
+                       h_thread = nt_thread_dummy_alloc(title, dat_name, 0);
                if(!h_thread){
                        *errorpp = L"スレッド情報が見つかりませんでした";
                        goto ERROR_TRAP;
@@ -1028,18 +1032,27 @@ BOOL nt_set_sel_item(nt_2ch_model_handle h_model,
        }
        
        nt_set_selected_thread(h_sel_item, h_thread);
-       nt_thread_release_ref(h_thread);
        
        if(!nt_read_thread(h_sel_item)){
                *errorpp = L"スレッドが開けませんでした";
                goto ERROR_TRAP;
        }
+       if(!title){
+               cptr = nt_read_thread_title(h_board, dat_name);
+               if(cptr){
+                       nt_thread_set_title(h_thread, cptr);
+                       free(cptr);
+               }
+       }
        
+       nt_thread_release_ref(h_thread);
        nt_board_release_ref(h_board);
        nt_category_release_ref(h_category);
        *h_sel_itemp = h_sel_item;
        return TRUE;
 ERROR_TRAP:
+       if(h_thread)
+               nt_thread_release_ref(h_thread);
        nt_board_release_ref(h_board);
        nt_category_release_ref(h_category);
        nt_2ch_selected_item_release_ref(h_sel_item);
index 81dc76a..6809f65 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -96,6 +96,21 @@ const wchar_t* nt_thread_get_title(nt_thread_handle h_thread)
        return threadp->name;
 }
 
+const wchar_t* nt_thread_set_title(
+               nt_thread_handle h_thread, const wchar_t* title)
+{
+       nt_thread_tp threadp;
+       assert(h_thread);
+       assert(h_thread->chk_sum == NT_2CH_THREAD_CHK_SUM);
+       assert(title);
+       threadp = (nt_thread_tp)h_thread;
+       
+       if(threadp->name)
+               free(threadp->name);
+       threadp->name = nt_w_str_clone(title);
+       return threadp->name;
+}
+
 const wchar_t* nt_thread_get_dat_name(nt_thread_handle h_thread)
 {
        nt_thread_tp threadp;
index 68ce697..b119920 100644 (file)
@@ -155,6 +155,7 @@ static nt_link_tp parse_number_list_local (const char *source,
        len = strlen(source);
        state = 0;
        prev = 0;
+       start = source;
 
        for(i = 0; i < len; i++){
                switch(source[i]){
index d3069e1..58e137b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -97,6 +97,80 @@ nt_searched_thread_handle nt_searched_thread_alloc(
        return &sthreadp->handle;
 }
 
+nt_searched_thread_handle nt_searched_thread_alloc2(
+               nt_2ch_model_handle h_model, 
+               const char *url)
+{
+       wchar_t *board_name;
+       wchar_t *dat_name;
+       nt_searched_thread_tp sthreadp;
+       char *cptr, *cptr1;
+       nt_board_handle h_board;
+       wchar_t wbuf[128];
+       char buf[128];
+       int len;
+       
+       cptr = strstr(url, "test/read.cgi/");
+       if(!cptr)
+               return NULL;
+       cptr += strlen("test/read.cgi/");
+       
+       cptr1 = strchr(cptr, '/');
+       if(!cptr1)
+               return NULL;
+       len = cptr1 - cptr;
+       memcpy(buf, cptr, len);
+       buf[len] = '\0';
+       
+       if((size_t)-1 == mbstowcs(wbuf, buf, sizeof(wbuf)/sizeof(wchar_t))){
+               return NULL;
+       }
+       
+       h_board = nt_get_board_by_address_match(h_model, wbuf);
+       if(!h_board){
+               return NULL;
+       }
+       board_name = nt_w_str_clone(nt_board_get_name(h_board));
+       nt_board_release_ref(h_board);
+       if(!board_name){
+               return NULL;
+       }
+       cptr1++;
+       cptr = strchr(cptr1, '/');
+       if(!cptr){
+               free(board_name);
+               return NULL;
+       }
+       len = cptr - cptr1;
+       memcpy(buf, cptr1, len);
+       strcpy(buf+len, ".dat");
+       buf[len+4] = '\0';
+       
+       if((size_t)-1 == mbstowcs(wbuf, buf, sizeof(wbuf)/sizeof(wchar_t))){
+               free(board_name);
+               return NULL;
+       }
+       dat_name = nt_w_str_clone(wbuf);
+       if(!dat_name){
+               free(board_name);
+               return NULL;
+       }
+       
+       sthreadp = malloc(sizeof(nt_searched_thread_t));
+       if(!sthreadp){
+               free(board_name);
+               free(dat_name);
+               return NULL;
+       }
+       
+       sthreadp->board_name = board_name;
+       sthreadp->dat_name = dat_name;
+       sthreadp->title = NULL;
+       sthreadp->handle.chk_sum = NT_SEARCHED_THREAD_CHK_SUM;
+       sthreadp->ref_count = 1;
+       return &sthreadp->handle;
+}
+
 int nt_searched_thread_add_ref(nt_searched_thread_handle h_searched_thread)
 {
        nt_searched_thread_tp sthreadp;
index d80901b..e4bf69e 100644 (file)
@@ -500,7 +500,7 @@ BOOL nt_cloud_query_attributes(nt_cloud_handle handle,
                nt_usr_db_handle db_handle, int depth)
 {
        char *url, *post_data, *line, *cptr;
-       char buf1[1024*16];
+       char *buf1;
        char buf2[256];
        char buf3[256];
        wchar_t board_nm_buf[128];
@@ -550,14 +550,15 @@ BOOL nt_cloud_query_attributes(nt_cloud_handle handle,
                strcat(post_data, "&last_query=");
                strcat(post_data, last_query);
        }
-       
-       if(!nt_http_post(url, post_data,
-                       buf1, sizeof(buf1), NULL, NULL, NULL, NULL)){
+       buf1 = NULL;
+       if(!nt_http_post3(url, post_data,
+                       &buf1, NULL, NULL, NULL, NULL)){
                nt_crypt_release_ref(h_crypt);
                if(last_query)
                        free(last_query);
                free(post_data);
                free(url);
+               free(buf1);
                return FALSE;
        }
        if(last_query)
@@ -569,24 +570,28 @@ BOOL nt_cloud_query_attributes(nt_cloud_handle handle,
        if(result_code == 301 && depth == 0){
                if(!nt_cloud_chk_user(handle)){
                        nt_crypt_release_ref(h_crypt);
+                       free(buf1);
                        return FALSE;
                }
                return nt_cloud_query_attributes(handle, 
                                db_handle, ++depth);
        }else if(result_code != 100){
                nt_crypt_release_ref(h_crypt);
+               free(buf1);
                return FALSE;
        }
        
        linkp = nt_split_line(buf1);
        if(!linkp){
                nt_crypt_release_ref(h_crypt);
+               free(buf1);
                return FALSE;
        }
        
        /* There is little data. */
        if(nt_link_num(linkp) < 4){
                nt_crypt_release_ref(h_crypt);
+               free(buf1);
                return TRUE;
        }
        wrkp = linkp;
@@ -596,12 +601,14 @@ BOOL nt_cloud_query_attributes(nt_cloud_handle handle,
        last_query = nt_str_clone((const char*)wrkp->data);
        if(!last_query){
                nt_crypt_release_ref(h_crypt);
+               free(buf1);
                return FALSE;
        }
        wrkp = wrkp->next;
        icd = iconv_open("wchar_t", "cp932");
        if(((iconv_t)-1) == icd){
                nt_crypt_release_ref(h_crypt);
+               free(buf1);
                free(last_query);
                return FALSE;
        }
@@ -661,6 +668,7 @@ LABEL1:
                                L"favorite", L"query_time", 0, last_query);
        
        free(last_query);
+       free(buf1);
        nt_all_link_free(linkp, NULL);
        iconv_close(icd);
        nt_crypt_release_ref(h_crypt);
index fd444f3..ac97a34 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -121,6 +121,8 @@ extern const wchar_t* nt_board_get_address(nt_board_handle h_board);
 extern int nt_board_get_thread_count(nt_board_handle h_board);
 extern int nt_thread_get_seq_number(nt_thread_handle h_thread);
 extern const wchar_t* nt_thread_get_title(nt_thread_handle h_thread);
+extern const wchar_t* nt_thread_set_title(
+               nt_thread_handle h_thread, const wchar_t* title);
 extern const wchar_t* nt_thread_get_dat_name(nt_thread_handle h_thread);
 extern int nt_thread_get_res_count(nt_thread_handle h_thread);
 extern int nt_res_get_seq_number(nt_res_handle h_res);
index 63d6486..acda1ee 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -27,6 +27,9 @@ typedef struct tag_nt_searched_thread_handle{
 extern nt_searched_thread_handle nt_searched_thread_alloc(
                const wchar_t *board_name,const wchar_t *dat_name,
                const wchar_t *title);
+extern nt_searched_thread_handle nt_searched_thread_alloc2(
+               nt_2ch_model_handle h_model, 
+               const char *url);
 extern int nt_searched_thread_add_ref(nt_searched_thread_handle h_searched_thread);
 extern int nt_searched_thread_release_ref(nt_searched_thread_handle h_searched_thread);
 
index cdc4316..24676ca 100644 (file)
 #define PACKAGE_NAME "ntch"
 
 /* Define to the full name and version of this package. */
-#define PACKAGE_STRING "ntch 1.0.2.7"
+#define PACKAGE_STRING "ntch 1.0.2.8"
 
 /* Define to the one symbol short name of this package. */
 #define PACKAGE_TARNAME "ntch"
 #define PACKAGE_URL "https://sourceforge.jp/projects/ntch/"
 
 /* Define to the version of this package. */
-#define PACKAGE_VERSION "1.0.2.7"
+#define PACKAGE_VERSION "1.0.2.8"
 
 /* Define to 1 if you have the ANSI C header files. */
 #define STDC_HEADERS 1
index 6767433..fa0032e 100644 (file)
@@ -66,7 +66,7 @@ extern char *MARU_PW;
 #define NT_INTI_DISP_FAVORITE  2
 #define NT_INTI_DISP_HISTORY   3
 
-#define NT_KEY_NONE (-1)
+#define NT_KEY_NONE (0)
 #define NT_KEY_UP 'k'
 #define NT_KEY_DOWN 'j'
 #define NT_KEY_LEFT 'h'
@@ -116,6 +116,7 @@ extern char *MARU_PW;
 #define NT_COMMAND1_HISTORY_2 "h"
 #define NT_COMMAND1_AUTOSCROLL_1 "autoscroll"
 #define NT_COMMAND1_AUTOSCROLL_2 "a"
+#define NT_COMMAND1_TIMER "timer"
 #define NT_COMMAND1_UPLOAD_1 "upload"
 #define NT_COMMAND1_UPLOAD_BOARD1 "board"
 #define NT_COMMAND1_UPLOAD_BOARD2 "b"
@@ -136,6 +137,10 @@ extern char *MARU_PW;
 #define NT_COMMAND1_NG_NAME_1 "ngname"
 #define NT_COMMAND1_NG_NAME_2 "ngnm"
 #define NT_COMMAND1_NG_ID_1 "ngid"
+#define NT_COMMAND1_OPEN_LINK_1 "link"
+#define NT_COMMAND1_OPEN_LINK_2 "l"
+#define NT_COMMAND1_REPLACE_RES_TEXT_1 "replace"
+#define NT_COMMAND1_REPLACE_RES_TEXT_2 "r"
 
 extern int set_option(int argc, char* argv[]);
 
index 594613a..d9be386 100644 (file)
@@ -66,6 +66,11 @@ extern int nt_http_post2(const char *url,
                char *out_buf, size_t out_buf_len,
                const char *referer, const char *user_agent, 
                nt_link_tp headers, nt_cookie_tp cookiep);
+extern int nt_http_post3(const char *url, const char *post_data,
+               char **out_buf, 
+               const char *referer, const char *user_agent, 
+               nt_link_tp extend_headers, 
+               nt_cookie_tp cookiep);
 extern BOOL nt_http_get(const char *url, const char *out_path,
                const char *referer, const char *user_agent, 
                nt_link_tp headers, BOOL range, BOOL ignore_cache);
index 3f54604..301d3eb 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -27,6 +27,7 @@
 #define NT_INFO_REFRESH_BOARD_SUCCESS (L"板を更新しました")
 #define NT_INFO_ADD_FAVORITE_SUCCEEDED (L"お気に入りに追加しました")
 #define NT_INFO_DEL_FAVORITE_SUCCEEDED (L"お気に入りから削除しました")
+#define NT_INFO_SET_ALERT_SUCCEEDED (L"アラートタイマーを設定しました")
 
 #define NT_INFO_UPLOAD_FAVORITE_SUCCEEDED (L"クラウドのお気に入りを更新しました")
 #define NT_INFO_UPLOAD_NG_FILES_SUCCEEDED (L"クラウドのNGファイルを更新しました")
index 3cd0757..b40e72b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
 #define DISP_CMD_UPLOAD_NG_FILES (17*256)
 #define DISP_CMD_EDIT_FAVORITE_BOARD (18*256)
 #define DISP_CMD_EDIT_FAVORITE_THREAD (19*256)
-
+#define DISP_CMD_OPEN_2CH_LINK (20*256)
+#define DISP_CMD_SET_ALERT (21*256)
 
 extern int disp_board_menu(nt_window_tp wp, 
                nt_2ch_model_handle h_model, nt_2ch_selected_item_handle h_select);
 extern int disp_threadlist(nt_window_tp wp, int state,
                nt_2ch_selected_item_handle h_select, nt_usr_db_handle usr_db_handle);
 extern int disp_reslist(nt_window_tp wp, int state,
-               nt_2ch_selected_item_handle h_select, nt_usr_db_handle usr_db_handle,
-               nt_ng_word_handle h_ng_word, nt_cloud_handle h_cloud);
+               nt_2ch_model_handle h_model, 
+               nt_usr_db_handle usr_db_handle,
+               nt_ng_word_handle h_ng_word, nt_cloud_handle h_cloud,
+               nt_2ch_selected_item_handle h_select, 
+               nt_searched_thread_handle *h_sel_threadp);
 extern int disp_thread_search(nt_window_tp wp, 
                int prev_state, nt_link_tp thread_list, 
                nt_searched_thread_handle *h_sel_threadp);
@@ -89,6 +93,16 @@ extern int disp_history(nt_window_tp wp, int prev_state,
                nt_usr_db_handle h_usr_db,
                nt_searched_thread_handle *h_sel_threadp,
                nt_link_tp *update_board_list);
+extern nt_window_tp disp_alert_win_alloc(
+               WINDOW *parent,
+               int src_lines, int src_cols,
+               const wchar_t *message,
+               const char *cmd_param);
+extern int disp_alert(nt_window_tp wp);
+extern int nt_disp_alert_get_alarm_value(const char *param);
+extern int init_alert_ctx(void *ptr, const wchar_t *msg);
+extern int free_alert_ctx(void *ptr);
+
 extern void free_board_menu_ctx(void *ptr);
 extern void init_threadlist_ctx(void *ptr);
 extern void free_threadlist_ctx(void *ptr);
index 374746a..b21787e 100644 (file)
@@ -251,6 +251,7 @@ ERROR_TRAP:
 #define TIMER_ID_AUTO_UPDATE_NONE 0
 #define TIMER_ID_AUTO_UPDATE 1
 #define TIMER_ID_AUTO_SCROLL 2
+#define TIMER_ID_ALERT 3
 static int auto_update_timer_func(int id)
 {
        switch(id){
@@ -258,6 +259,8 @@ static int auto_update_timer_func(int id)
                return TIMER_ID_AUTO_UPDATE;
        case TIMER_ID_AUTO_SCROLL:
                return TIMER_ID_AUTO_SCROLL;
+       case TIMER_ID_ALERT:
+               return TIMER_ID_ALERT;
        }
        return TIMER_ID_AUTO_UPDATE_NONE;
 }
@@ -276,6 +279,7 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
        nt_window_tp search_winp = NULL;
        nt_window_tp favorite_winp = NULL;
        nt_window_tp history_winp = NULL;
+       nt_window_tp alert_winp = NULL;
        char buf[256];
        wchar_t title_buf[128];
        wchar_t wch;
@@ -297,7 +301,10 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
        BOOL auto_scrolling;
        nt_timer_handle h_timer_auto_update;
        nt_timer_handle h_timer_auto_scroll;
+       nt_timer_handle h_timer_alert;
        nt_timer_handle h_timer;
+       int expire;
+       BOOL show_alert = FALSE;
        
        state = DISP_STATE_BOARDMENU;
        if(INIT_DISP_STATE == NT_INTI_DISP_FAVORITE){
@@ -315,6 +322,8 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                        TIMER_ID_AUTO_SCROLL, -1, auto_update_timer_func);
        h_timer_auto_update = nt_timer_alloc(
                        TIMER_ID_AUTO_UPDATE, NT_AUTO_UPDATE_INTERVAL, auto_update_timer_func);
+       h_timer_alert = nt_timer_alloc(
+                       TIMER_ID_ALERT, -1, auto_update_timer_func);
 
        h_write_data = NULL;
        marup = NULL;
@@ -493,76 +502,114 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                                                LINES - num, COLS, num, 0))
                                goto END_WHILE;
                        rwinp->key = ch;
-                       state = disp_reslist(rwinp, state, h_sel_items, db_handle, h_ng_word, h_cloud);
+                       h_searched_thread = NULL;
+                       state = disp_reslist(rwinp, state, 
+                                       app_2ch_model, db_handle, h_ng_word, h_cloud, 
+                                       h_sel_items, &h_searched_thread);
                        auto_scrolling = FALSE;
-                       if(DISP_CMD(state)){
-                               if(DISP_CMD(state) == DISP_CMD_AUTO_SCROLL){
-                                       if(0 >= nt_timer_get_interval(h_timer_auto_scroll)){
-                                               nt_timer_set_interval(
-                                                       h_timer_auto_scroll, NT_AUTO_SCROLL_INTERVAL);
-                                       }
-                                       auto_scrolling = TRUE;
-                                       state = DISP_STATE_RESLIST;
-                               }else if(DISP_CMD(state) == DISP_CMD_REFRESH){
-                                       state = DISP_STATE_RESLIST;
-                                       ch = NT_KEY_NONE;
-                                       if(!nt_read_thread(h_sel_items)){
-                                               status_msg = NT_ERR_MSG_REFRESH_THREAD_FAILED;
-                                               wclear(scrp);
-                                               continue;
-                                       }
+                       if(DISP_CMD(state) == DISP_CMD_AUTO_SCROLL){
+                               if(0 >= nt_timer_get_interval(h_timer_auto_scroll)){
+                                       nt_timer_set_interval(
+                                               h_timer_auto_scroll, NT_AUTO_SCROLL_INTERVAL);
+                               }
+                               auto_scrolling = TRUE;
+                               state = DISP_STATE_RESLIST;
+                       }else if(DISP_CMD(state) == DISP_CMD_REFRESH){
+                               state = DISP_STATE_RESLIST;
+                               ch = NT_KEY_NONE;
+                               if(!nt_read_thread(h_sel_items)){
+                                       status_msg = NT_ERR_MSG_REFRESH_THREAD_FAILED;
+                                       wclear(scrp);
+                                       continue;
+                               }
+                               if(rwinp->data){
+                                       free_reslist_ctx(rwinp->data);
+                                       rwinp->data = NULL;
+                               }
+                               status_msg = NT_INFO_REFRESH_THREAD_SUCCESS;
+                               wclear(scrp);
+                               continue;
+                       }else if(DISP_CMD(state) == DISP_CMD_REENTER){
+                               DISP_CLR_CMD(state);
+                               ch = NT_KEY_NONE;
+                               continue;
+                       }else if(DISP_CMD(state) == DISP_CMD_SET_ALERT){
+                               DISP_CLR_CMD(state);
+                               ch = NT_KEY_NONE;
+                               expire = nt_disp_alert_get_alarm_value(buf);
+                               if(expire <= 0)
+                                       break;
+                               if(!alert_winp){
+                                       alert_winp = disp_alert_win_alloc(scrp, LINES, COLS, L"Time expired.", buf);
+                               }
+                               if(!alert_winp)
+                                       goto END_WHILE;
+                               nt_timer_set_interval(
+                                               h_timer_alert, expire);
+                               status_msg = NT_INFO_SET_ALERT_SUCCEEDED;
+                               continue;
+                       }else if(DISP_CMD(state) == DISP_CMD_OPEN_2CH_LINK && h_searched_thread){
+                               ch = NT_KEY_NONE;
+                               if(nt_set_sel_item(app_2ch_model,
+                                               &h_sel_items_tmp, h_searched_thread, &status_msg)){
+                                       disp_state = DISP_STATE_RESLIST;
+                                       nt_2ch_selected_item_release_ref(h_sel_items);
+                                       h_sel_items = h_sel_items_tmp;
                                        if(rwinp->data){
                                                free_reslist_ctx(rwinp->data);
                                                rwinp->data = NULL;
                                        }
-                                       status_msg = NT_INFO_REFRESH_THREAD_SUCCESS;
-                                       wclear(scrp);
-                                       continue;
-                               }else if(DISP_CMD(state) == DISP_CMD_REENTER){
-                                       DISP_CLR_CMD(state);
-                                       ch = NT_KEY_NONE;
-                                       continue;
-                               }else if(DISP_CMD(state) == DISP_CMD_EDIT_NGWORD){
-                                       ch = NT_KEY_NONE;
-                                       if(!h_ng_word)
-                                               break;
-                                       linkp = nt_ng_word_get_words(h_ng_word);
-                                       linkp = disp_editor3(linkp);
-                                       if(linkp && nt_ng_word_set_words(h_ng_word, linkp, h_cloud)){
-                                               ch = NT_KEY_CMD_NGWORD_UPDATE;
-                                       }
-                                       DISP_CLR_CMD(state);
-                                       keypad(stdscr, true);
-                                       wclear(scrp);
-                                       continue;
-                               }else if(DISP_CMD(state) == DISP_CMD_EDIT_NGNAME){
-                                       ch = NT_KEY_NONE;
-                                       if(!h_ng_word)
-                                               break;
-                                       linkp = nt_ng_word_get_names(h_ng_word);
-                                       linkp = disp_editor3(linkp);
-                                       if(linkp && nt_ng_word_set_names(h_ng_word, linkp, h_cloud)){
-                                               ch = NT_KEY_CMD_NGWORD_UPDATE;
-                                       }
-                                       DISP_CLR_CMD(state);
-                                       keypad(stdscr, true);
-                                       wclear(scrp);
-                                       continue;
-                               }else if(DISP_CMD(state) == DISP_CMD_EDIT_NGID){
-                                       ch = NT_KEY_NONE;
-                                       if(!h_ng_word)
-                                               break;
-                                       linkp = nt_ng_word_get_ids(h_ng_word);
-                                       linkp = disp_editor3(linkp);
-                                       if(linkp && nt_ng_word_set_ids(h_ng_word, linkp, h_cloud)){
-                                               ch = NT_KEY_CMD_NGWORD_UPDATE;
+                                       if(twinp->data){
+                                               free_threadlist_ctx(twinp->data);
+                                               twinp->data = NULL;
                                        }
-                                       DISP_CLR_CMD(state);
-                                       keypad(stdscr, true);
-                                       wclear(scrp);
-                                       continue;
                                }
+                               nt_searched_thread_release_ref(h_searched_thread);
+                               h_searched_thread = NULL;
+                               DISP_CLR_CMD(state);
+                               wclear(scrp);
+                               continue;
+                       }else if(DISP_CMD(state) == DISP_CMD_EDIT_NGWORD){
+                               ch = NT_KEY_NONE;
+                               if(!h_ng_word)
+                                       break;
+                               linkp = nt_ng_word_get_words(h_ng_word);
+                               linkp = disp_editor3(linkp);
+                               if(linkp && nt_ng_word_set_words(h_ng_word, linkp, h_cloud)){
+                                       ch = NT_KEY_CMD_NGWORD_UPDATE;
+                               }
+                               DISP_CLR_CMD(state);
+                               keypad(stdscr, true);
+                               wclear(scrp);
+                               continue;
+                       }else if(DISP_CMD(state) == DISP_CMD_EDIT_NGNAME){
+                               ch = NT_KEY_NONE;
+                               if(!h_ng_word)
+                                       break;
+                               linkp = nt_ng_word_get_names(h_ng_word);
+                               linkp = disp_editor3(linkp);
+                               if(linkp && nt_ng_word_set_names(h_ng_word, linkp, h_cloud)){
+                                       ch = NT_KEY_CMD_NGWORD_UPDATE;
+                               }
+                               DISP_CLR_CMD(state);
+                               keypad(stdscr, true);
+                               wclear(scrp);
+                               continue;
+                       }else if(DISP_CMD(state) == DISP_CMD_EDIT_NGID){
+                               ch = NT_KEY_NONE;
+                               if(!h_ng_word)
+                                       break;
+                               linkp = nt_ng_word_get_ids(h_ng_word);
+                               linkp = disp_editor3(linkp);
+                               if(linkp && nt_ng_word_set_ids(h_ng_word, linkp, h_cloud)){
+                                       ch = NT_KEY_CMD_NGWORD_UPDATE;
+                               }
+                               DISP_CLR_CMD(state);
+                               keypad(stdscr, true);
+                               wclear(scrp);
+                               continue;
                        }
+                       DISP_CLR_CMD(state);
                        if(!auto_scrolling){
                                nt_timer_set_interval(h_timer_auto_scroll, -1);
                        }
@@ -937,7 +984,10 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                        print_error(scrp, status_msg);
                        status_msg = NULL;
                }
-
+               if(show_alert && alert_winp){
+                       disp_alert(alert_winp);
+               }
+               
                move(LINES-1,COLS-1);
                touchwin(scrp);
                wrefresh(scrp);
@@ -968,6 +1018,13 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                                                                nt_all_link_free(linkp, _2ch_selected_item_free);
                                                                //fprintf(stderr, "Update request calling.!\n");
                                                        }
+                                                       ch = NT_KEY_NONE;
+                                                       break;
+                                               case TIMER_ID_ALERT:
+                                                       //fputs("Timer expired!\n", stderr);
+                                                       show_alert = TRUE;
+                                                       nt_timer_set_interval(h_timer_alert, -1);
+                                                       ch = NT_KEY_NONE;
                                                        break;
                                                }
                                                nt_timer_release_ref(h_timer);
@@ -995,15 +1052,18 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                case NT_KEY_BOTTOM:
                case KEY_END:
                case NT_KEY_REFRESH:
+                       show_alert = FALSE;
                        break;
                case NT_KEY_CLOSE:
                case KEY_LEFT:
                        wclear(scrp);
+                       show_alert = FALSE;
                        break;
                case KEY_HOME:
                        ch = NT_KEY_COMMAND1;
                        nt_add_wch(scrp,ch,0);
                        strncpy(buf,"1",2);
+                       show_alert = FALSE;
                        break;
                case NT_KEY_COMMAND1:
                case NT_KEY_COMMAND2:
@@ -1016,9 +1076,11 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                        getstr(buf);
                        cbreak();
                        noecho();
+                       show_alert = FALSE;
                        break;
                case NT_KEY_ERASE:
                        wclear(scrp);
+                       show_alert = FALSE;
                        break;
                case NT_KEY_QUIT:
                        result = TRUE;
@@ -1026,6 +1088,8 @@ static BOOL DoLoop(WINDOW *scrp, nt_usr_db_handle db_handle,
                }/* end switch*/
        }/* end while */
 END_WHILE:
+       if(h_timer_alert)
+               nt_timer_release_ref(h_timer_alert);
        if(h_timer_auto_update)
                nt_timer_release_ref(h_timer_auto_update);
        if(h_timer_auto_scroll)
@@ -1042,6 +1106,11 @@ END_WHILE:
        free_board_menu_ctx(bwinp->data);
        free_threadlist_ctx(twinp->data);
        free_reslist_ctx(rwinp->data);
+       if(alert_winp){
+               if(alert_winp->data)
+                       free_alert_ctx(alert_winp->data);
+               nt_disp_win_free(alert_winp);
+       }
        if(history_winp){
                if(history_winp->data)
                        free_history_ctx(history_winp->data);
index 9d5784b..6bef9ea 100644 (file)
@@ -42,6 +42,11 @@ static nt_http_header_tp nt_http_init_header(const char *url);
 static void nt_http_free_header(nt_http_header_tp headerp);
 static BOOL nt_http_init_header2(
                nt_http_header_tp headerp, const char *out_path);
+static int nt_http_post_local(const char *url, const char *post_data,
+               char **out_buf, size_t out_buf_len, 
+               const char *referer, const char *user_agent, 
+               nt_link_tp extend_headers, 
+               nt_cookie_tp cookiep);
 
 BOOL nt_http_post(const char *url, const char *post_data,
                char *out_buf, size_t out_buf_len, 
@@ -50,8 +55,8 @@ BOOL nt_http_post(const char *url, const char *post_data,
                nt_cookie_tp cookiep)
 {
        int result_code;
-       result_code = nt_http_post2(url, post_data,
-               out_buf, out_buf_len, referer, user_agent, 
+       result_code = nt_http_post_local(url, post_data,
+               &out_buf, out_buf_len, referer, user_agent, 
                extend_headers, cookiep);
        return (result_code == 200) ? TRUE : FALSE;
 }
@@ -62,6 +67,32 @@ int nt_http_post2(const char *url, const char *post_data,
                nt_link_tp extend_headers, 
                nt_cookie_tp cookiep)
 {
+       return nt_http_post_local(url, post_data,
+                                       &out_buf, out_buf_len, 
+                                       referer, user_agent, 
+                                       extend_headers, 
+                                       cookiep);
+}
+int nt_http_post3(const char *url, const char *post_data,
+               char **out_buf, 
+               const char *referer, const char *user_agent, 
+               nt_link_tp extend_headers, 
+               nt_cookie_tp cookiep)
+{
+       return nt_http_post_local(url, post_data,
+                                       out_buf, 0, 
+                                       referer, user_agent, 
+                                       extend_headers, 
+                                       cookiep);
+}
+
+#define BUF_LEN_DELTA (1024*4)
+int nt_http_post_local(const char *url, const char *post_data,
+               char **out_buf, size_t out_buf_len, 
+               const char *referer, const char *user_agent, 
+               nt_link_tp extend_headers, 
+               nt_cookie_tp cookiep)
+{
        nt_socket_tp socketp = NULL;
        int fd = -1, sockfd = 0;
        char data[1024*8];
@@ -75,6 +106,10 @@ int nt_http_post2(const char *url, const char *post_data,
        char itoa_buf[33];
        char cookie_data[1024];
        char *cptr, *p1, *p2, *p3;
+       int len, new_len;
+       char *tmp_buf;
+       BOOL is_realloc_buf;
+       
 
        result = 0;
        nt_http_header_tp headerp = nt_http_init_header(url);
@@ -161,8 +196,8 @@ int nt_http_post2(const char *url, const char *post_data,
                        nt_http_free_header(headerp);
                        return result;
                }
-               memcpy(out_buf, data+nread, data_len-nread);
-               out_buf[data_len - nread] = '\0';
+               memcpy(*out_buf, data+nread, data_len-nread);
+               (*out_buf)[data_len - nread] = '\0';
        }else{
                if(headerp->port == -1)
                        headerp->port = 80;
@@ -198,12 +233,24 @@ int nt_http_post2(const char *url, const char *post_data,
                        return result;
                }
        }
+       
+       
        result = responsep->status_code;
        switch(result){
        case 200:
                if(IS_SET_FLAG(headerp,SSL_FLAG)){
                }else{
-                       cptr = out_buf;
+                       if(out_buf_len == 0){
+                               tmp_buf = malloc(BUF_LEN_DELTA);
+                               if(!tmp_buf)
+                                       goto ERROR_TRAP;
+                               *out_buf = tmp_buf;
+                               out_buf_len = BUF_LEN_DELTA;
+                               is_realloc_buf = TRUE;
+                       }else{
+                               is_realloc_buf = FALSE;
+                       }
+                       cptr = *out_buf;
                        do{
                                nread = read(sockfd, data, sizeof(data));
                                switch(nread){
@@ -212,8 +259,19 @@ int nt_http_post2(const char *url, const char *post_data,
                                case 0:
                                        break;
                                default:
-                                       if(out_buf_len <= (cptr - out_buf) + nread){
-                                               goto ERROR_TRAP;
+                                       len = cptr - (*out_buf);
+                                       if(out_buf_len <= len + nread){
+                                               if(!is_realloc_buf)
+                                                       goto ERROR_TRAP;
+                                               new_len = ((len + nread) / BUF_LEN_DELTA + 1) * BUF_LEN_DELTA;
+                                               tmp_buf = malloc(new_len);
+                                               if(!tmp_buf)
+                                                       goto ERROR_TRAP;
+                                               memcpy(tmp_buf, *out_buf, len);
+                                               free(*out_buf);
+                                               *out_buf = tmp_buf;
+                                               out_buf_len = new_len;
+                                               cptr = (*out_buf) + len;
                                        }
                                        memcpy(cptr, data, nread);
                                        cptr[nread] = '\0';
@@ -224,7 +282,7 @@ int nt_http_post2(const char *url, const char *post_data,
                        if(nread > 0){
                                result = 0;
                        }else if(IS_SET_FLAG(responsep, CHUNKED_FLAG)){
-                               p3 = p1 = out_buf;
+                               p3 = p1 = *out_buf;
                                while(0 < (nread = strtol(p1, &p2, 16))){
                                        memmove(p3, p2+2, nread);
                                        p3 += nread;
index f5165ee..8e8909a 100644 (file)
@@ -41,6 +41,7 @@ nt_socket_tp nt_socket_init(int port, char *addr)
        struct addrinfo *addr_out, *addr_list;
        struct sockaddr_in  *s_addr;
        struct sockaddr_in6 *s_addr6;
+       int err;
        
 #else
        struct hostent *hostinfo;
@@ -66,7 +67,9 @@ nt_socket_tp nt_socket_init(int port, char *addr)
        addr_limit.ai_family = AF_UNSPEC;
        addr_limit.ai_socktype = SOCK_STREAM;
        addr_limit.ai_protocol = IPPROTO_TCP;
-       if(0 != getaddrinfo(addr, NULL, &addr_limit, &addr_out)){
+       err = getaddrinfo(addr, NULL, &addr_limit, &addr_out);
+       if(0 != err){
+                fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(err));
                free(ptr);
                return NULL;
        }
diff --git a/src/ui/disp_alert.c b/src/ui/disp_alert.c
new file mode 100644 (file)
index 0000000..77db726
--- /dev/null
@@ -0,0 +1,214 @@
+/* Copyright 2014 Akira Ohta (akohta001@gmail.com)
+    This file is part of ntch.
+
+    The ntch is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    The ntch is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with ntch.  If not, see <http://www.gnu.org/licenses/>.
+    
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <signal.h>
+#include <limits.h>
+
+
+#include "env.h"
+#include "error.h"
+#include "nt_string.h"
+#include "_2ch/_2ch.h"
+#include "utils/nt_std_t.h"
+#include "utils/text.h"
+#include "utils/file.h"
+#include "ui/disp.h"
+#include       "ui/disp_string.h"
+
+#define NT_ALERT_WIN_TITLE_HEIGHT 3
+#define NT_ALERT_WIN_CLIENT_HEIGHT 8
+#define NT_ALERT_WIN_HEIGHT (NT_ALERT_WIN_TITLE_HEIGHT + NT_ALERT_WIN_CLIENT_HEIGHT)
+#define NT_ALERT_WIN_WIDTH 40
+
+typedef struct tag_ctx_alert_t *ctx_alert_tp;
+typedef struct tag_ctx_alert_t{
+       wchar_t *message;
+       int x;
+       int y;
+       int lines;
+       int cols;
+}ctx_alert_t;
+
+
+nt_window_tp disp_alert_win_alloc(
+               WINDOW *parent,
+               int src_lines, int src_cols,
+               const wchar_t *message,
+               const char *cmd_param)
+{
+       nt_window_tp winp = NULL;
+       wchar_t *cptr;
+       int x, y, cols, lines;
+       ctx_alert_tp ctxp;
+       
+       cptr = nt_w_str_clone(message);
+       if(!cptr){
+               return NULL;
+       }
+       ctxp = malloc(sizeof(ctx_alert_t));
+       if(!ctxp){
+               free(cptr);
+               return NULL;
+       }
+       ctxp->message = cptr;
+       
+       if(src_lines > NT_ALERT_WIN_HEIGHT){
+               lines = NT_ALERT_WIN_HEIGHT;
+               y = (src_lines - NT_ALERT_WIN_HEIGHT) / 2;
+       }else{
+               lines = src_lines;
+               y = 0;
+       }
+       if(src_cols > NT_ALERT_WIN_WIDTH){
+               cols = NT_ALERT_WIN_WIDTH;
+               x = (src_cols - NT_ALERT_WIN_WIDTH) / 2;
+       }else{
+               cols = src_cols;
+               x = 0;
+       }
+       
+       winp = nt_disp_win_alloc(parent, lines, cols, y, x, cmd_param);
+       if(!winp){
+               free(cptr);
+               free(ctxp);
+               return NULL;
+       }
+       winp->data = ctxp;
+       ctxp->x = x;
+       ctxp->y = y;
+       ctxp->cols = cols;
+       ctxp->lines = lines;
+       return winp;
+}
+
+
+static void draw_frame(nt_window_tp wp, int cols, int lines)
+{
+       int i;
+       
+       wmove(wp->wp, 0, 0);
+       nt_add_wch(wp->wp, L'+', 0);
+       nt_add_wnch(wp->wp, L'-', 0, cols - 2);
+       nt_add_wch(wp->wp, L'+', 0);
+       
+       wmove(wp->wp, 1, 0);
+       nt_add_wch(wp->wp, L'|', 0);
+       nt_add_wnch(wp->wp, L' ', 0, cols - 2);
+       nt_add_wch(wp->wp, L'|', 0);
+       
+       wmove(wp->wp, 2, 0);
+       nt_add_wch(wp->wp, L'+', 0);
+       nt_add_wnch(wp->wp, L'-', 0, cols - 2);
+       nt_add_wch(wp->wp, L'+', 0);
+       
+       for(i = 3; i < (lines - 1); i++){
+               wmove(wp->wp, i, 0);
+               nt_add_wch(wp->wp, L'|', 0);
+               nt_add_wnch(wp->wp, L' ', 0, cols - 2);
+               nt_add_wch(wp->wp, L'|', 0);
+       }
+       wmove(wp->wp, i, 0);
+       nt_add_wch(wp->wp, L'+', 0);
+       nt_add_wnch(wp->wp, L'-', 0, cols - 2);
+       nt_add_wch(wp->wp, L'+', 0);
+       
+}
+
+int disp_alert(nt_window_tp wp)
+{
+       ctx_alert_tp ctxp;
+       int offset_y, offset_x, length;
+       
+       ctxp = (ctx_alert_tp)wp->data;
+       assert(ctxp);
+       assert(ctxp->message);
+       
+       draw_frame(wp, ctxp->cols, ctxp->lines);
+       
+       offset_y = (ctxp->lines - 3) / 2 + 3;
+       
+       length = nt_get_wc_count_within_colmns(ctxp->message, ctxp->cols - 2);
+       
+       offset_x = (ctxp->cols - length ) / 2;
+       
+       wmove(wp->wp, offset_y, offset_x);
+       nt_add_wnstr(wp->wp, ctxp->message, 0, length);
+       
+       return 0;
+}
+
+
+int nt_disp_alert_get_alarm_value(const char *param)
+{
+       const char *start, *end;
+       long int num;
+       if(!nt_strtok(param, ' ', &start, &end))
+               return -1;
+       
+       if(start >= end)
+               return -1;
+       
+       if(0 != strncmp(start, 
+                       NT_COMMAND1_TIMER, strlen(NT_COMMAND1_TIMER)))
+               return -1;
+       
+       if(!nt_strtok(end, ' ', &start, &end))
+               return -1;
+       
+       
+       num = strtol(start, (char**)&end, 10);
+       if(num < 0 || num == LONG_MIN  || num == LONG_MAX)
+               return -1;
+       switch(*end){
+       case ' ':
+       case '\0':
+       case '\n':
+       case '\t':
+               break;
+       case 's':
+               num *= 1000;
+               break;
+       case 'm':
+               num *= 60000;
+               break;
+       default:
+               return -1;
+       }
+       return num;
+}
+
+
+int init_alert_ctx(void *ptr, const wchar_t *msg)
+{
+       return 0;
+}
+int free_alert_ctx(void *ptr)
+{
+       ctx_alert_tp ctxp;
+       
+       ctxp = (ctx_alert_tp)ptr;
+       free(ctxp->message);
+       free(ctxp);
+       return 0;
+}
+
index 7cae298..b8d466c 100644 (file)
@@ -49,6 +49,9 @@
 #define NT_CMD_EDT_NGWORD 12
 #define NT_CMD_EDT_NGNAME 13
 #define NT_CMD_EDT_NGID 14
+#define NT_CMD_OPEN_LINK 15
+#define NT_CMD_REPLACE_RES_TEXT 16
+#define NT_CMD_SET_ALTER 17
 
 #define AUTO_SCROLL_NONE 0
 #define AUTO_SCROLL_UP  -1
@@ -120,8 +123,12 @@ static int get_id_num(ctx_reslist_tp ctxp, const wchar_t *misc);
 static BOOL set_res_header(ctx_reslist_tp ctxp, res_data_tp res_datap,
                                wchar_t *buf, size_t buf_len);
 
-int disp_reslist(nt_window_tp wp, int prev_state, nt_2ch_selected_item_handle h_select,
-       nt_usr_db_handle usr_db_handle, nt_ng_word_handle h_ng_word, nt_cloud_handle h_cloud)
+int disp_reslist(nt_window_tp wp, int prev_state, 
+               nt_2ch_model_handle h_model, 
+               nt_usr_db_handle usr_db_handle,
+               nt_ng_word_handle h_ng_word, nt_cloud_handle h_cloud,
+               nt_2ch_selected_item_handle h_select, 
+               nt_searched_thread_handle *h_sel_threadp)
 {
        ctx_reslist_tp ctxp, child_ctxp;
        res_data_tp res_datap;
@@ -442,6 +449,8 @@ int disp_reslist(nt_window_tp wp, int prev_state, nt_2ch_selected_item_handle h_
                switch(cmd){
                case NT_CMD_AUTO_SCROLL:
                        return DISP_CMD_AUTO_SCROLL | DISP_STATE_RESLIST;
+               case NT_CMD_SET_ALTER:
+                       return DISP_CMD_SET_ALERT | DISP_STATE_RESLIST;
                case NT_CMD_SEARCH_THREAD:
                        return DISP_STATE_SEARCH_THREAD;
                case NT_CMD_FAVORITE:
@@ -481,6 +490,13 @@ int disp_reslist(nt_window_tp wp, int prev_state, nt_2ch_selected_item_handle h_
                case NT_CMD_EDT_NGID:
                        free_disp_lines_ctx(wp->data);
                        return DISP_CMD_EDIT_NGID | DISP_STATE_RESLIST;
+               case NT_CMD_OPEN_LINK:
+                       *h_sel_threadp = nt_searched_thread_alloc2(h_model, endp);
+                       if(h_sel_threadp)
+                               return DISP_CMD_OPEN_2CH_LINK | DISP_STATE_RESLIST;
+                       break;
+               case NT_CMD_REPLACE_RES_TEXT:
+                       break;
                default:
                        if(cmd == NT_CMD_TREE){
                                linkp = parse_tree_list((ctx_reslist_tp)wp->data, endp);
@@ -969,6 +985,9 @@ static int parse_cmd1(const char *param, const char **end)
                0 == strncmp(NT_COMMAND1_AUTOSCROLL_2,param,
                        strlen(NT_COMMAND1_AUTOSCROLL_2))){
                return NT_CMD_AUTO_SCROLL;
+       }else if(0 == strncmp(NT_COMMAND1_TIMER,param,
+                       strlen(NT_COMMAND1_TIMER))){
+               return NT_CMD_SET_ALTER;
        }else if(0 == strncmp(NT_COMMAND1_NG_WORD_1,param,len) ||
                        0 == strncmp(NT_COMMAND1_NG_WORD_2,param, len)){
                if(!nt_strtok(*end, ' ', &start, end))
@@ -998,6 +1017,26 @@ static int parse_cmd1(const char *param, const char **end)
                        return NT_CMD_EDT_NGID;
                *end = start;
                return NT_CMD_ADD_NGID;
+       }else if(0 == strncmp(NT_COMMAND1_OPEN_LINK_1,param,len) ||
+                       0 == strncmp(NT_COMMAND1_OPEN_LINK_2,param, len)){
+               if(!nt_strtok(*end, ' ', &start, end))
+                       return NT_CMD_NONE;
+               
+               len = *end - start;
+               if(len <= 0)
+                       return NT_CMD_NONE;
+               *end = start;
+               return NT_CMD_OPEN_LINK;
+       }else if(0 == strncmp(NT_COMMAND1_REPLACE_RES_TEXT_1,param,len) ||
+                       0 == strncmp(NT_COMMAND1_REPLACE_RES_TEXT_2,param, len)){
+               if(!nt_strtok(*end, ' ', &start, end))
+                       return NT_CMD_NONE;
+               
+               len = *end - start;
+               if(len <= 0)
+                       return NT_CMD_NONE;
+               *end = start;
+               return NT_CMD_REPLACE_RES_TEXT;
        }
        return NT_CMD_NONE;
 }
index bb497e3..bd5f063 100644 (file)
@@ -49,9 +49,10 @@ static char base64decode_tbl[] = {
 };
 
 
-static BOOL s2i(const char** cpp, char *cp)
+static BOOL s2i(char** cpp, char *cp)
 {
        char c, c1, c2;
+       char *p;
        c1 = (*cpp)[0];
        c2 = (*cpp)[1];
        
@@ -73,7 +74,9 @@ static BOOL s2i(const char** cpp, char *cp)
        else
                return FALSE;
        *cp = c;
-       *cpp += 2;
+       p = *cpp;
+       p += 2;
+       *cpp = p;
        return TRUE;
 }
 
@@ -100,7 +103,7 @@ int nt_base64_url_decode(
                }else if(c == -2){/* % */
                        if(cptr + 2 > end_ptr)
                                return -1;
-                       if(!s2i((const char**)&cptr, &c))
+                       if(!s2i((char**)&cptr, &c))
                                return -1;
                        if(c == '='){
                                state = 5;
index d9a81ad..389e9f3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
index 7e23596..167468a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
 #include <string.h>
 #include <assert.h>
 #include <openssl/sha.h>
+#include <pthread.h>
 
 #include "env.h"
 #include "utils/nt_std_t.h"
 #include "utils/db.h"
 
+static pthread_mutex_t g_init_path_lock_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 const char *nt_db_get_log_path()
 {
        static char path[256];
        static int f = 0;
+       pthread_mutex_lock(&g_init_path_lock_mutex);
        if(f == 0){
                strcpy(path, LOG_PATH);
                strcat(path, "/");
                strcat(path, LOG_DB_NAME);
        }
+       pthread_mutex_unlock(&g_init_path_lock_mutex);
        return path;
 }
 
@@ -40,11 +45,13 @@ const char *nt_db_get_idx_path()
 {
        static char path[256];
        static int f = 0;
+       pthread_mutex_lock(&g_init_path_lock_mutex);
        if(f == 0){
                strcpy(path, LOG_PATH);
                strcat(path, "/");
                strcat(path, INDEX_DB_NAME);
        }
+       pthread_mutex_unlock(&g_init_path_lock_mutex);
        return path;
 }
 
index 7734217..b1130c3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
@@ -303,18 +303,20 @@ int nt_pthread_add_ref(nt_pthread_handle h_pthread)
        assert(h_pthread->chk_sum == NT_PTHREAD_CHK_SUM);
        pthreadp = (nt_pthread_tp)h_pthread;
        assert(pthreadp->ref_count > 0);
-       return ++pthreadp->ref_count;
+       return nt_pthread_increment_int(&pthreadp->ref_count);
 }
 
 int nt_pthread_release_ref(nt_pthread_handle h_pthread)
 {
        nt_pthread_tp pthreadp;
+       int c;
        assert(h_pthread);
        assert(h_pthread->chk_sum == NT_PTHREAD_CHK_SUM);
        pthreadp = (nt_pthread_tp)h_pthread;
        assert(pthreadp->ref_count > 0);
-       if(0 != --pthreadp->ref_count)
-               return pthreadp->ref_count;
+       c = nt_pthread_decrement_int(&pthreadp->ref_count);
+       if(0 != c)
+               return c;
        free(h_pthread);
        return 0;
 }
index 67927b4..48bbe03 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
+/* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
     This file is part of ntch.
 
     The ntch is free software: you can redistribute it and/or modify
index dcee641..a5ed17d 100644 (file)
@@ -103,6 +103,7 @@ BOOL nt_zip_inflate2(int in_fd, int out_fd)
        int nread, len;
 
        in_buf_remain = chunk_remain = 0;
+       nread = 0;
 
        do{
                if(in_buf_remain == 0){