summary refs log tree commit diff stats
path: root/src/fe-text
AgeCommit message (Collapse)Author
2013-07-01Update fe-text's help messageTingPing
2013-04-28Don't hardcode "plugins" as the subdirectory for plugins in manyChristoph J. Thompson
places. modified: config-win32.h modified: configure.ac modified: plugins/checksum/Makefile.am modified: plugins/doat/Makefile.am modified: plugins/fishlim/Makefile.am modified: plugins/perl/Makefile.am modified: plugins/python/Makefile.am modified: plugins/sysinfo/Makefile.am modified: plugins/xdcc/Makefile.am modified: src/common/plugin.c modified: src/fe-text/fe-text.c
2013-04-27Reverts commit d964af81428a6d768aeb96906eb0538a30d919caTingPing
2013-04-25win32: Moved PlatformToolset configuration to individual project files. It ↵Arnavion
should be set before setting other properties or importing other props. This fixes the broken GUI Platform Toolset indicator, as well as VS compilation itself if another version such as 2010 was also installed.
2013-04-22fix warning in new glibTingPing
2013-04-05Fix root user warning running before g_type_initTingPing
closes #504
2013-04-02Apply to fe-text tooBerke Viktor
2013-04-01Remove another bunch of obsolete junkBerke Viktor
2013-03-31Supposed fix for license issuesBerke Viktor
I have no clue what to put here so I'll just use what the About dialog provides (unless specified otherwise in the file)
2013-03-27fix warningTingPing
2013-03-20Redesign the Ban List window. Closes Issues #303, #342, #427RichardHitt
This is a combination of 18 commits. The first commit's message is: Here is the initial banlist branch of RichardHitt/hexchat. Changed files are only src/fe-gtk/{banlist.c,fe-gtk.h}. This version works and contains my first efforts at selective sensitization of radio buttons and control buttons. From this point I intend to undertake a stepwise redesign. Step 1 will be to make the existing banlist code work for multiple simultaneous banlist windows (for different channels, obviously). It will be a hackathon with the only goal of getting it working. Step 2 will be the objectization and alpha-stage tidying-up of all the terrible looking stuff I will have done in Step 1. This is the 2nd commit message: Here's the post-Step-1 commit. It works for multiple banlist windows. Note particularly what I've done to banlist.h. Note that for many functions in banlist.c the argument is now a banlist_info *, rather than a session *. Note in banlist.c the initialization of array modes[] which contains driving information for the checkboxes. Of course those checkboxes aren't yet implemented. Maybe in Step 2 I will change to checkboxes from radio buttons; but definitely I will change to letting modes[] drive processing. This is the 3rd commit message: Converted to checkboxes. Much additional work. Note that the infrastructure for Auto-invite is not yet present in the hexchat tree. I'm nearly done with banlist, I think! This is the 4th commit message: Fleshed out 'invite'. Tagged masks uniformly, e.g. (b) (e) (I). General cleanup, nearly at the point of beta quality. This is the 5th commit message: Added fourth mode type: quiet. Did lots and lots of cleanup. Beta-ready? This is the 6th commit message: Get the banlist timestamps properly sortable. This is the 7th commit message: Redesign the supports_foo() routines. Now they're responsible for setting the flags in ->capable, ->readable, ->writeable. This is the 8th commit message: Deleted a couple of RBH comments. This is the 9th commit message: Now the ESC key will close the banlist window. This is the 10th commit message: Fix the fe-text occurrence of fe_add_ban_list(). This is the 11th commit message: Fixed also fe_ban_list_end() and removed fe_is_banwindow(). This is the 12th commit message: Use old-style initialization for array of structures modes[] This is the 13th commit message: Oops, incomplete regression of modes[] initialization. This fixes. This is the 14th commit message: Fixed strptime buy implementing a special version here. Fixed column width concerns by setting resizable and autosize. This is the 15th commit message: Get rid of testing line. This is the 16th commit message: Changed to gtkutil_destroy_on_esc () This is the 17th commit message: Remove no-longer-used functnion This is the 18th commit message: Minor cleanups to banlist.c, banlist.h Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. Author: RichardHitt <rbh00@netcom.com> Committer: Richard Hitt <rbh00@f17.rbh00.pacbell.net> Not currently on any branch. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: src/common/fe.h modified: src/common/hexchat.h modified: src/common/inbound.c modified: src/common/modes.c modified: src/common/proto-irc.c modified: src/common/server.c modified: src/fe-gtk/banlist.c modified: src/fe-gtk/banlist.h modified: src/fe-gtk/fe-gtk.c modified: src/fe-gtk/fe-gtk.h modified: src/fe-gtk/maingui.c modified: src/fe-text/fe-text.c
2013-03-16Handle EOF in text-feTingPing
2013-03-16fix fe-text on win32TingPing
It still throws out some errors
2013-03-16fix fe-textTingPing
2013-01-17fix fe-beep issue in fe-textTingPing
2013-01-09Make source cleah with cppcheck, except for mpc and saslRichardHitt
2012-12-23fix incorrect FSF addressDan Mashal
2012-11-04Some more platform unificationBerke Viktor
2012-11-04Eliminate warnings due to missing includesBerke Viktor
2012-11-03Initial commit for utf8 everywhere.Arnavion
2012-10-28Further doc relocations and conversionsBerke Viktor
2012-10-28More polishing for the About dialogBerke Viktor
2012-10-24A lot more rebrandingBerke Viktor
2012-10-24Rename libxchatcommon to libhexchatcommonBerke Viktor
2012-10-24Fix fe-text compilation - it still segfaults thoughBerke Viktor
2012-10-22Variable cleanup for the restBerke Viktor
2012-10-22Variable cleanup for input_*Berke Viktor
2012-10-22Variable cleanup for gui_*Berke Viktor
2012-10-21Move warning level to property sheetBerke Viktor
2012-10-18Update win32 dirent.h implementation and use header instead of static libraryBerke Viktor
2012-10-13Compatibility for Automake 1.12.4+Berke Viktor
2012-10-13Some HexChat-Text rebranding work leftBerke Viktor
2012-10-13Get rid of auto_save, we always want to saveBerke Viktor
2012-10-03Complete the VS2010 reversionBerke Viktor
2012-10-03Fix platform toolset for certain projects in legacy solutionBerke Viktor
2012-10-03Revert to VS2010 part4Berke Viktor
2012-10-02Use explicit project names, output filenames depend on themBerke Viktor
2012-10-02Oops, wrong find'n'replaceBerke Viktor
2012-10-02Remove hardcoding as much as possibleBerke Viktor
2012-10-02Change platform toolset to Visual Studio 2012Berke Viktor
2012-10-02Add XP (WDK) solution as a fallback optionBerke Viktor
2012-09-16Force 5.x subsystem globallyBerke Viktor
2012-09-15Update solution to Visual Studio 2012 Express and get rid of mpcInfoBerke Viktor
2012-07-21Add _AMD64_ definition for x64 builds, make Visual Studio even happierBerke Viktor
2012-07-21Add trailing backslashes to Output and Intermediate directories, make Visual ↵Berke Viktor
Studio happy
2012-07-14remove a few more *.user filesxhmikosr
2012-07-13Fix HexChat-Text compilation on Linux when NLS is enabledBerke Viktor
2012-07-13Fix frontend compilation on LinuxBerke Viktor
2012-07-13Another bunch of rebranding stuffBerke Viktor
2012-07-13Rename files, delete old windows makefilesBerke Viktor
tle='author berkeviktor@aol.com <berkeviktor@aol.com> 2011-02-28 18:59:32 +0100 committer berkeviktor@aol.com <berkeviktor@aol.com> 2011-02-28 18:59:32 +0100 add wdk changes to named branch' href='/git-repos/torxchat.git/commit/plugins/checksum/checksum.c?h=feature/tls-srp&id=d03d6e606b40157d910ddf99ab018156abeb8ef0'>d03d6e60 ^
e681eafa ^
d03d6e60 ^
d03d6e60 ^
83b6f548 ^
d03d6e60 ^
e681eafa ^
d03d6e60 ^
d03d6e60 ^

83b6f548 ^

d03d6e60 ^
e681eafa ^
d03d6e60 ^
83b6f548 ^
d03d6e60 ^
83b6f548 ^


d03d6e60 ^
83b6f548 ^
d03d6e60 ^



83b6f548 ^
d03d6e60 ^
e681eafa ^
d03d6e60 ^











83b6f548 ^
d03d6e60 ^


e681eafa ^

83b6f548 ^

d03d6e60 ^
e681eafa ^

d03d6e60 ^
83b6f548 ^

d03d6e60 ^
e681eafa ^
d03d6e60 ^

45d4fa58 ^
d03d6e60 ^











83b6f548 ^
d03d6e60 ^

e681eafa ^
83b6f548 ^

d03d6e60 ^
e681eafa ^

d03d6e60 ^
83b6f548 ^

d03d6e60 ^
e681eafa ^
d03d6e60 ^

45d4fa58 ^
d03d6e60 ^

e3be4a0e ^

d03d6e60 ^
1b0c07f8 ^
d03d6e60 ^
83b6f548 ^

1b0c07f8 ^
d03d6e60 ^
83b6f548 ^


d03d6e60 ^
e681eafa ^


d03d6e60 ^
e3be4a0e ^
45d4fa58 ^
d03d6e60 ^


e681eafa ^
d03d6e60 ^


e2acf19d ^


d03d6e60 ^
83b6f548 ^
e681eafa ^
83b6f548 ^
e681eafa ^
83b6f548 ^
d03d6e60 ^
e681eafa ^


d03d6e60 ^
e681eafa ^
d03d6e60 ^



e681eafa ^
d03d6e60 ^
e681eafa ^
d03d6e60 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
          
                                        
  





                                                                                
  

                                                                             
  






                                                                                



                   
                   


                      
                        
                 
 
            





                          









                           
                           


                                                                                                                             
 
                                                                                                                   


                                                                 
 
                                                                 










                                                                                    
     
















                                                                  
      





































                                                              
                      
 
                                 
 
                                           
         
                                                                     
                 
                                                                                                              

                    
                 
                                                                                 
                 
         
            
         
                                                        
         

 

            
 
                                                            
 
                                          
         


                                     
         
                            



           
              
 
                                                                                   











                                                                                                                                       
                                                                                  


                                                                                                                                  

                                                                                                    

                    
                 

                                                                                                                                                                                 
                 

            
         
                                                            

         
                                











                                                                                                                                       
                                                                                  

                                                                                                                                  
                                                                                                                               

                    
                 

                                                                                                                                                                  
                 

            
         
                                                            

         
                                

 

                                                         
 
                                                 
         

                               
                                                      
         


                                    
         


                                                                                                            
         
 
                                


   
                                                                                                                             


                           


                                  
 
                                                     
                                                           
         
                                                                        
         
 


                                                                                                         
 
                                                        



                 
                            
 
                                                          

                 
/* HexChat
 * Copyright (c) 2010-2012 Berke Viktor.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
#include <sys/types.h>
#include <openssl/sha.h>
#include <glib.h>

#ifdef WIN32
#ifndef snprintf
#define snprintf _snprintf
#endif
#ifndef stat64
#define stat64 _stat64
#endif
#else
/* for INT_MAX */
#include <limits.h>
#define __USE_LARGEFILE64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#endif

#include <sys/stat.h>

#include "hexchat-plugin.h"

#define BUFSIZE 32768
#define DEFAULT_LIMIT 256									/* default size is 256 MiB */

static hexchat_plugin *ph;									/* plugin handle */
static char name[] = "Checksum";
static char desc[] = "Calculate checksum for DCC file transfers";
static char version[] = "3.1";

/* Use of OpenSSL SHA256 interface: http://adamlamers.com/?p=5 */
static void
sha256_hash_string (unsigned char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65])
{
	int i;
	for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
	{
		sprintf (outputBuffer + (i * 2), "%02x", hash[i]);
	}
	outputBuffer[64] = 0;
}

#if 0
static void
sha256 (char *string, char outputBuffer[65])
{
	int i;
	unsigned char hash[SHA256_DIGEST_LENGTH];
	SHA256_CTX sha256;

	SHA256_Init (&sha256);
	SHA256_Update (&sha256, string, strlen (string));
	SHA256_Final (hash, &sha256);

	for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
	{
		sprintf (outputBuffer + (i * 2), "%02x", hash[i]);
	}
	outputBuffer[64] = 0;
}
#endif

static int
sha256_file (char *path, char outputBuffer[65])
{
	int bytesRead;
	unsigned char *buffer;
	unsigned char hash[SHA256_DIGEST_LENGTH];
	SHA256_CTX sha256;

	FILE *file = fopen (path, "rb");
	if (!file)
	{
		return -534;
	}

	SHA256_Init (&sha256);
	buffer = malloc (BUFSIZE);
	bytesRead = 0;

	if (!buffer)
	{
		return ENOMEM;
	}

	while ((bytesRead = fread (buffer, 1, BUFSIZE, file)))
	{
		SHA256_Update (&sha256, buffer, bytesRead);
	}

	SHA256_Final (hash, &sha256);
	sha256_hash_string (hash, outputBuffer);

	fclose (file);
	free (buffer);
	return 0;
}

static void
set_limit (char* size)
{
	int buffer = atoi (size);

	if (buffer > 0 && buffer < INT_MAX)
	{
		if (hexchat_pluginpref_set_int (ph, "limit", buffer))
		{
			hexchat_printf (ph, "File size limit has successfully been set to: %d MiB\n", buffer);
		}
		else
		{
			hexchat_printf (ph, "File access error while saving!\n");
		}
	}
	else
	{
		hexchat_printf (ph, "Invalid input!\n");
	}
}

static int
get_limit ()
{
	int size = hexchat_pluginpref_get_int (ph, "limit");

	if (size <= -1 || size >= INT_MAX)
	{
		return DEFAULT_LIMIT;
	}
	else
	{
		return size;
	}
}

static void
print_limit ()
{
	hexchat_printf (ph, "File size limit for checksums: %d MiB", get_limit ());
}

static int
dccrecv_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[2], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[2], sum);						/* word[2] is the full filename */
			/* try to print the checksum in the privmsg tab of the sender */
			hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3]));
			hexchat_printf (ph, "SHA-256 checksum for %s (local):  %s\n", word[1], sum);
		}
		else
		{
			hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3]));
			hexchat_printf (ph, "SHA-256 checksum for %s (local):  (size limit reached, no checksum calculated, you can increase it with /CHECKSUM INC)\n", word[1]);
		}
	}
	else
	{
		hexchat_printf (ph, "File access error!\n");
	}

	return HEXCHAT_EAT_NONE;
}

static int
dccoffer_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[3], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[3], sum);						/* word[3] is the full filename */
			hexchat_commandf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): %s", word[2], word[1], sum);
		}
		else
		{
			hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3]));
			hexchat_printf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): (size limit reached, no checksum calculated)", word[2], word[1]);
		}
	}
	else
	{
		hexchat_printf (ph, "File access error!\n");
	}

	return HEXCHAT_EAT_NONE;
}

static int
checksum (char *word[], char *word_eol[], void *userdata)
{
	if (!g_ascii_strcasecmp ("GET", word[2]))
	{
		print_limit ();
	}
	else if (!g_ascii_strcasecmp ("SET", word[2]))
	{
		set_limit (word[3]);
	}
	else
	{
		hexchat_printf (ph, "Usage: /CHECKSUM GET|INC|DEC\n");
		hexchat_printf (ph, "  GET - print the maximum file size (in MiB) to be hashed\n");
		hexchat_printf (ph, "  SET <filesize> - set the maximum file size (in MiB) to be hashed\n");
	}

	return HEXCHAT_EAT_NONE;
}

int
hexchat_plugin_init (hexchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	ph = plugin_handle;

	*plugin_name = name;
	*plugin_desc = desc;
	*plugin_version = version;

	/* this is required for the very first run */
	if (hexchat_pluginpref_get_int (ph, "limit") == -1)
	{
		hexchat_pluginpref_set_int (ph, "limit", DEFAULT_LIMIT);
	}

	hexchat_hook_command (ph, "CHECKSUM", HEXCHAT_PRI_NORM, checksum, "Usage: /CHECKSUM GET|SET", 0);
	hexchat_hook_print (ph, "DCC RECV Complete", HEXCHAT_PRI_NORM, dccrecv_cb, NULL);
	hexchat_hook_print (ph, "DCC Offer", HEXCHAT_PRI_NORM, dccoffer_cb, NULL);

	hexchat_printf (ph, "%s plugin loaded\n", name);
	return 1;
}

int
hexchat_plugin_deinit (void)
{
	hexchat_printf (ph, "%s plugin unloaded\n", name);
	return 1;
}