NeoMutt  2024-02-01-23-g345d7b
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
win_chain.c File Reference

Mixmaster Chain Window. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "win_chain.h"
#include "color/lib.h"
#include "chain_data.h"
#include "remailer.h"
+ Include dependency graph for win_chain.c:

Go to the source code of this file.

Functions

static void cbar_update (struct ChainData *cd)
 Update the Chain bar (status bar)
 
static int chain_add (struct ChainData *cd, const char *s, struct RemailerArray *ra)
 Add a host to the chain.
 
static int win_chain_recalc (struct MuttWindow *win)
 Recalculate the Chain list - Implements MuttWindow::recalc() -.
 
static int win_chain_repaint (struct MuttWindow *win)
 Repaint the Chain list - Implements MuttWindow::repaint() -.
 
struct MuttWindowwin_chain_new (struct MuttWindow *win_cbar)
 Create a new Chain list Window.
 
void win_chain_init (struct MuttWindow *win, struct ListHead *chain, struct RemailerArray *ra)
 Initialise the Chain list Window.
 
int win_chain_extract (struct MuttWindow *win, struct ListHead *chain)
 Extract the Chain list data.
 
int win_chain_get_length (struct MuttWindow *win)
 Get the number of Remailers in the Chain.
 
bool win_chain_next (struct MuttWindow *win)
 Select the next entry in the Chain list.
 
bool win_chain_prev (struct MuttWindow *win)
 Select the previous entry in the Chain list.
 
bool win_chain_append (struct MuttWindow *win, struct Remailer *r)
 Add an item to the Chain, after the current item.
 
bool win_chain_insert (struct MuttWindow *win, struct Remailer *r)
 Add an item to the Chain, before the current item.
 
bool win_chain_delete (struct MuttWindow *win)
 Delete the current item from the Chain.
 
bool win_chain_validate (struct MuttWindow *win)
 Validate the Chain.
 

Detailed Description

Mixmaster Chain Window.

Authors
  • Richard Russon

This program 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 this program. If not, see http://www.gnu.org/licenses/.

Definition in file win_chain.c.

Function Documentation

◆ cbar_update()

static void cbar_update ( struct ChainData cd)
static

Update the Chain bar (status bar)

Parameters
cdChain data

Definition at line 62 of file win_chain.c.

63{
64 char buf[1024] = { 0 };
65 snprintf(buf, sizeof(buf), _("-- Remailer chain [Length: %d]"), cd->chain_len);
66 sbar_set_title(cd->win_cbar, buf);
67}
#define _(a)
Definition: message.h:28
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
int chain_len
Length of chain.
Definition: chain_data.h:48
struct MuttWindow * win_cbar
Chain Bar (status window)
Definition: chain_data.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ chain_add()

static int chain_add ( struct ChainData cd,
const char *  s,
struct RemailerArray *  ra 
)
static

Add a host to the chain.

Parameters
cdChain data
sHostname
raRemailer List
Return values
0Success
-1Error

Definition at line 77 of file win_chain.c.

78{
79 if (cd->chain_len >= MAX_MIXES)
80 return -1;
81
82 if (mutt_str_equal(s, "0") || mutt_istr_equal(s, "<random>"))
83 {
84 cd->chain[cd->chain_len++] = 0;
85 return 0;
86 }
87
88 struct Remailer **r = NULL;
89 ARRAY_FOREACH(r, ra)
90 {
91 if (mutt_istr_equal(s, (*r)->shortname))
92 {
93 cd->chain[cd->chain_len++] = ARRAY_FOREACH_IDX;
94 return 0;
95 }
96 }
97
98 /* replace unknown remailers by <random> */
99 cd->chain[cd->chain_len++] = 0;
100 return 0;
101}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define MAX_MIXES
Mixmaster's maximum chain length. Don't change this.
Definition: chain_data.h:29
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:721
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
int chain[MAX_MIXES]
Indexes of chain hosts.
Definition: chain_data.h:49
A Mixmaster remailer.
Definition: remailer.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ win_chain_new()

struct MuttWindow * win_chain_new ( struct MuttWindow win_cbar)

Create a new Chain list Window.

Parameters
win_cbarChain bar to keep updated (status bar)
Return values
ptrNew Chain list Window

Definition at line 184 of file win_chain.c.

185{
188
189 struct ChainData *cd = chain_data_new();
190 cd->win_cbar = win_cbar;
191
194 win->wdata = cd;
196 win->actions |= WA_RECALC;
197
198 return win;
199}
struct ChainData * chain_data_new(void)
Create new Chain data.
Definition: chain_data.c:37
static int win_chain_recalc(struct MuttWindow *win)
Recalculate the Chain list - Implements MuttWindow::recalc() -.
Definition: win_chain.c:106
static int win_chain_repaint(struct MuttWindow *win)
Repaint the Chain list - Implements MuttWindow::repaint() -.
Definition: win_chain.c:145
void chain_data_free(struct MuttWindow *win, void **ptr)
Free the Chain data - Implements MuttWindow::wdata_free() -.
Definition: chain_data.c:45
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:95
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
An ordered set of Remailer hosts.
Definition: chain_data.h:46
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
void * wdata
Private data.
Definition: mutt_window.h:145
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ win_chain_init()

void win_chain_init ( struct MuttWindow win,
struct ListHead *  chain,
struct RemailerArray *  ra 
)

Initialise the Chain list Window.

Parameters
winChain list Window
chainChain data
raArray of all Remailer hosts

Definition at line 207 of file win_chain.c.

208{
209 if (!win || !win->wdata)
210 return;
211
212 struct ChainData *cd = win->wdata;
213 cd->ra = ra;
214 cd->sel = 0;
215
216 struct ListNode *p = NULL;
217 STAILQ_FOREACH(p, chain, entries)
218 {
219 chain_add(cd, p->data, cd->ra);
220 }
221 if (cd->chain_len > 1)
222 cd->sel = cd->chain_len - 1;
223 win->actions |= WA_RECALC;
224}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
struct RemailerArray * ra
Array of all Remailer hosts.
Definition: chain_data.h:51
int sel
Current selection.
Definition: chain_data.h:47
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
static int chain_add(struct ChainData *cd, const char *s, struct RemailerArray *ra)
Add a host to the chain.
Definition: win_chain.c:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ win_chain_extract()

int win_chain_extract ( struct MuttWindow win,
struct ListHead *  chain 
)

Extract the Chain list data.

Parameters
winChain list Window
chainChain data
Return values
numNumber of entries in the Chain
-1Error

Definition at line 233 of file win_chain.c.

234{
235 if (!win || !win->wdata)
236 return -1;
237
238 struct ChainData *cd = win->wdata;
239
240 if (cd->chain_len)
241 {
242 char *t = NULL;
243 for (int i = 0; i < cd->chain_len; i++)
244 {
245 const int j = cd->chain[i];
246 if (j != 0)
247 {
248 struct Remailer **rp = ARRAY_GET(cd->ra, j);
249 t = (*rp)->shortname;
250 }
251 else
252 {
253 t = "*";
254 }
255
257 }
258 }
259 return cd->chain_len;
260}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ win_chain_get_length()

int win_chain_get_length ( struct MuttWindow win)

Get the number of Remailers in the Chain.

Parameters
winChain list Window
Return values
numNumber of entries in the Chain

Definition at line 267 of file win_chain.c.

268{
269 if (!win || !win->wdata)
270 return 0;
271
272 struct ChainData *cd = win->wdata;
273
274 return cd->chain_len;
275}
+ Here is the caller graph for this function:

◆ win_chain_next()

bool win_chain_next ( struct MuttWindow win)

Select the next entry in the Chain list.

Parameters
winChain list Window
Return values
trueSelection changed

Definition at line 282 of file win_chain.c.

283{
284 if (!win || !win->wdata)
285 return false;
286
287 struct ChainData *cd = win->wdata;
288
289 if (cd->chain_len && (cd->sel < (cd->chain_len - 1)))
290 {
291 cd->sel++;
292 }
293 else
294 {
295 mutt_error(_("You already have the last chain element selected"));
296 return false;
297 }
298
299 win->actions |= WA_REPAINT;
300 return true;
301}
#define mutt_error(...)
Definition: logging2.h:92
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
+ Here is the caller graph for this function:

◆ win_chain_prev()

bool win_chain_prev ( struct MuttWindow win)

Select the previous entry in the Chain list.

Parameters
winChain list Window
Return values
trueSelection changed

Definition at line 308 of file win_chain.c.

309{
310 if (!win || !win->wdata)
311 return false;
312
313 struct ChainData *cd = win->wdata;
314
315 if (cd->sel)
316 {
317 cd->sel--;
318 }
319 else
320 {
321 mutt_error(_("You already have the first chain element selected"));
322 return false;
323 }
324
325 win->actions |= WA_REPAINT;
326 return true;
327}
+ Here is the caller graph for this function:

◆ win_chain_append()

bool win_chain_append ( struct MuttWindow win,
struct Remailer r 
)

Add an item to the Chain, after the current item.

Parameters
winChain list Window
rSelected Remailer host
Return values
trueItem added to Chain

Definition at line 335 of file win_chain.c.

336{
337 if (!win || !win->wdata || !r)
338 return false;
339
340 struct ChainData *cd = win->wdata;
341
342 if ((cd->chain_len < MAX_MIXES) && (cd->sel < cd->chain_len))
343 cd->sel++;
344
345 return win_chain_insert(win, r);
346}
bool win_chain_insert(struct MuttWindow *win, struct Remailer *r)
Add an item to the Chain, before the current item.
Definition: win_chain.c:354
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ win_chain_insert()

bool win_chain_insert ( struct MuttWindow win,
struct Remailer r 
)

Add an item to the Chain, before the current item.

Parameters
winChain list Window
rSelected Remailer host
Return values
trueItem added to Chain

Definition at line 354 of file win_chain.c.

355{
356 if (!win || !win->wdata || !r)
357 return false;
358
359 struct ChainData *cd = win->wdata;
360
361 if (cd->chain_len < MAX_MIXES)
362 {
363 cd->chain_len++;
364 for (int i = cd->chain_len - 1; i > cd->sel; i--)
365 cd->chain[i] = cd->chain[i - 1];
366
367 cd->chain[cd->sel] = r->num;
368 }
369 else
370 {
371 /* L10N The '%d' here hard-coded to 19 */
372 mutt_error(_("Mixmaster chains are limited to %d elements"), MAX_MIXES);
373 return false;
374 }
375
376 win->actions |= WA_RECALC;
377 return true;
378}
int num
Index number.
Definition: remailer.h:41
+ Here is the caller graph for this function:

◆ win_chain_delete()

bool win_chain_delete ( struct MuttWindow win)

Delete the current item from the Chain.

Parameters
winChain list Window
Return values
trueItem deleted

Definition at line 385 of file win_chain.c.

386{
387 if (!win || !win->wdata)
388 return false;
389
390 struct ChainData *cd = win->wdata;
391
392 if (cd->chain_len)
393 {
394 cd->chain_len--;
395
396 for (int i = cd->sel; i < cd->chain_len; i++)
397 cd->chain[i] = cd->chain[i + 1];
398
399 if ((cd->sel == cd->chain_len) && cd->sel)
400 cd->sel--;
401 }
402 else
403 {
404 mutt_error(_("The remailer chain is already empty"));
405 return false;
406 }
407
408 win->actions |= WA_RECALC;
409 return true;
410}
+ Here is the caller graph for this function:

◆ win_chain_validate()

bool win_chain_validate ( struct MuttWindow win)

Validate the Chain.

Parameters
winChain list Window
Return values
trueChain is valid

Definition at line 417 of file win_chain.c.

418{
419 if (!win || !win->wdata)
420 return false;
421
422 struct ChainData *cd = win->wdata;
423 if (cd->chain_len == 0)
424 return false;
425
426 int last_index = cd->chain[cd->chain_len - 1];
427 if (last_index != 0)
428 {
429 struct Remailer **rp = ARRAY_GET(cd->ra, last_index);
430 if ((*rp)->caps & MIX_CAP_MIDDLEMAN)
431 {
432 mutt_error(_("Error: %s can't be used as the final remailer of a chain"),
433 (*rp)->shortname);
434 return false;
435 }
436 }
437
438 return true;
439}
#define MIX_CAP_MIDDLEMAN
Must be a middle-man (not at the end of a chain)
Definition: remailer.h:32
+ Here is the caller graph for this function: