~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to ipc/tests/IpcCat.cpp

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2015-08-26 20:07:19 UTC
  • mfrom: (0.12.19)
  • Revision ID: package-import@ubuntu.com-20150826200719-t3qktwtjhs7qzjq1
Tags: 2:1.8.2-0ubuntu0.14.04.1
* New upstream release v1.8.2 to support Thunderbird 38
  - Fixes LP: #1489103 - Per-account settings missing after Thunderbird
    update

* Depend on gnupg2 instead of gnupg. Whilst this enigmail version still
  works with gnupg 1.4.*, it pops up an alert warning that it will be the
  last version to do so
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ***** BEGIN LICENSE BLOCK *****
2
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
 
 *
4
 
 * The contents of this file are subject to the Mozilla Public
5
 
 * License Version 1.1 (the "MPL"); you may not use this file
6
 
 * except in compliance with the MPL. You may obtain a copy of
7
 
 * the MPL at http://www.mozilla.org/MPL/
8
 
 *
9
 
 * Software distributed under the MPL is distributed on an "AS
10
 
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
 
 * implied. See the MPL for the specific language governing
12
 
 * rights and limitations under the MPL.
13
 
 *
14
 
 * The Original Code is ipc-pipe.
15
 
 *
16
 
 * The Initial Developer of the Original Code is Patrick Brunschwig.
17
 
 * Portions created by Patrick Brunschwig <patrick@enigmail.net> are
18
 
 * Copyright (C) 2010 Patrick Brunschwig. All Rights Reserved.
19
 
 *
20
 
 * Contributor(s):
21
 
 *
22
 
 * Alternatively, the contents of this file may be used under the terms of
23
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
24
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
26
 
 * of those above. If you wish to allow use of your version of this file only
27
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
28
 
 * use your version of this file under the terms of the MPL, indicate your
29
 
 * decision by deleting the provisions above and replace them with the notice
30
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
31
 
 * the provisions above, a recipient may use your version of this file under
32
 
 * the terms of any one of the MPL, the GPL or the LGPL.
33
 
 * ***** END LICENSE BLOCK ***** */
34
 
 
35
 
 
36
 
/*
37
 
 * Helper tool to read or write data to/from stdin/stdout
38
 
 *
39
 
 * Usage:
40
 
 * IpcCat {write|read|dump|getenv} arg
41
 
 *
42
 
 * Parameters:
43
 
 *   write:  read from stdin and write to file <arg>
44
 
 *   read:   read from file <arg> and write to stdout
45
 
 *   dump:   read from stdin; write to stdout
46
 
 *   getenv: print value of environment variable <arg>
47
 
 *
48
 
 * Exit codes:
49
 
 *   0:    success
50
 
 *   > 0:  failure
51
 
 */
52
 
 
53
 
#include <stdio.h>
54
 
#include <string.h>
55
 
#include <stdlib.h>
56
 
 
57
 
int main(int argc, char* argv[])
58
 
{
59
 
 
60
 
  if (argc < 2)
61
 
    return 1;
62
 
 
63
 
  const char* fileName;
64
 
  const int maxLen = 255;
65
 
  char buffer[maxLen + 1];
66
 
  long totalBytes = 0;
67
 
 
68
 
  // "dump" function
69
 
  if (strcmp(argv[1], "dump") == 0) {
70
 
    fputs("Starting dump\n", stderr);
71
 
    while(fgets(buffer, maxLen, stdin)) {
72
 
      fputs(buffer, stdout);
73
 
      totalBytes += strlen(buffer);
74
 
      if (! stdin)
75
 
        fputs("\n", stdout);
76
 
    }
77
 
    sprintf(buffer, "Dumped %ld bytes\n", totalBytes);
78
 
    fputs(buffer, stderr);
79
 
  }
80
 
 
81
 
  // "write" function
82
 
  else if (strcmp(argv[1], "write") == 0) {
83
 
    if (argc < 3)
84
 
      return 1;
85
 
 
86
 
    fileName = argv[2];
87
 
    if (!fileName)
88
 
      return 2;
89
 
 
90
 
    FILE* outfile = fopen(fileName, "w");
91
 
    if (!outfile)
92
 
      return 3;
93
 
 
94
 
    fputs("Starting write\n", stderr);
95
 
    while(fgets(buffer, maxLen, stdin)) {
96
 
      fputs(buffer, outfile);
97
 
      totalBytes += strlen(buffer);
98
 
      if (! stdin) {
99
 
        fputs("\n", outfile);
100
 
      }
101
 
    }
102
 
    fclose(outfile);
103
 
    sprintf(buffer, "Wrote %ld bytes\n", totalBytes);
104
 
    fputs(buffer, stderr);
105
 
  }
106
 
 
107
 
  // "read" function
108
 
  else if (strcmp(argv[1], "read") == 0) {
109
 
    if (argc < 3)
110
 
      return 1;
111
 
 
112
 
    fileName = argv[2];
113
 
 
114
 
    FILE* infile = fopen(fileName, "r");
115
 
    if (!infile)
116
 
      return 5;
117
 
 
118
 
    size_t bytesRead;
119
 
    bytesRead = maxLen;
120
 
 
121
 
    fputs("Starting read\n", stderr);
122
 
    while (bytesRead == (size_t) maxLen) {
123
 
      bytesRead = fread (buffer, 1, maxLen, infile);
124
 
      totalBytes += bytesRead;
125
 
      buffer[bytesRead] = 0;
126
 
      fputs(buffer, stdout);
127
 
    }
128
 
    fclose (infile);
129
 
 
130
 
    sprintf(buffer, "Read %ld bytes\n", totalBytes);
131
 
    fputs(buffer, stderr);
132
 
  }
133
 
 
134
 
  // "getenv" function
135
 
  else if (strcmp(argv[1], "getenv") == 0) {
136
 
    if (argc < 3)
137
 
      return 1;
138
 
 
139
 
    sprintf(buffer, "Reading environment variable %s\n", argv[2]);
140
 
    fputs(buffer, stderr);
141
 
    char* envVar = getenv(argv[2]);
142
 
 
143
 
    if (! envVar)
144
 
      fputs("not defined\n", stdout);
145
 
    else
146
 
      fputs(envVar, stdout);
147
 
  }
148
 
  else {
149
 
    return 4;
150
 
  }
151
 
 
152
 
  fflush(stderr);
153
 
  fflush(stdout);
154
 
 
155
 
  return 0;
156
 
}