changed puts("") but putchar('\n')

and added clang format so the formatting changed
This commit is contained in:
qorg11 2021-07-07 16:23:39 +02:00
parent 50a2682cab
commit d9afa6076a
No known key found for this signature in database
GPG key ID: 343FC20A4ACA62B9
2 changed files with 265 additions and 93 deletions

166
clainsafecli/.clang-format Normal file
View file

@ -0,0 +1,166 @@
---
Language: Cpp
# BasedOnStyle: Mozilla
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: TopLevel
AlwaysBreakAfterReturnType: TopLevel
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: true
AfterControlStatement: Never
AfterEnum: true
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: false
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Mozilla
BreakBeforeInheritanceComma: true
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 5
ContinuationIndentWidth: 5
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
StatementAttributeLikeMacros:
- Q_EMIT
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 5
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 5
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: false
PenaltyBreakAssignment: 5
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 5
UseCRLF: false
UseTab: Always
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

View file

@ -22,20 +22,19 @@ main(int argc, char **argv)
ipv6_flag = ipv4_flag = false; ipv6_flag = ipv4_flag = false;
char *token = NULL; char *token = NULL;
long silent_flag = 0L; long silent_flag = 0L;
char *buffer = (char *)calloc(1024,sizeof(char)); char *buffer = (char *)calloc(1024, sizeof(char));
char *socks_proxy_url, *http_proxy_url; char *socks_proxy_url, *http_proxy_url;
if(buffer == NULL) { if(buffer == NULL) {
fprintf(stderr,"Error allocating memory!\n"); fprintf(stderr, "Error allocating memory!\n");
return -1; return -1;
} }
CURL *easy_handle = curl_easy_init(); CURL *easy_handle = curl_easy_init();
if(!easy_handle) { if(!easy_handle) {
fprintf(stderr,"Error initializing libcurl\n"); fprintf(stderr, "Error initializing libcurl\n");
return -1; return -1;
} }
if(argc == optind) { if(argc == optind) {
@ -45,98 +44,95 @@ main(int argc, char **argv)
int option_index = 0; int option_index = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"server", required_argument,0,'s'}, { "server", required_argument, 0, 's' },
{"help" , no_argument ,0,'h'}, { "help", no_argument, 0, 'h' },
{"socks-proxy", required_argument,0,'p'}, { "socks-proxy", required_argument, 0, 'p' },
{"token" , required_argument,0,'T'}, { "token", required_argument, 0, 'T' },
{"http-proxy", no_argument ,0,'P'}, { "http-proxy", no_argument, 0, 'P' },
{"silent", no_argument ,0,'S'}, { "silent", no_argument, 0, 'S' },
{"ipv4" , no_argument ,0,'4'}, { "ipv4", no_argument, 0, '4' },
{"ipv6" , no_argument ,0,'6'}, { "ipv6", no_argument, 0, '6' },
{0 , 0 ,0, 0 } { 0, 0, 0, 0 }
}; };
int c = 0; int c = 0;
while((c = getopt_long(argc,argv, "46hT:p:P:Ss:", while((c = getopt_long(
long_options,&option_index)) != -1) { argc, argv, "46hT:p:P:Ss:", long_options, &option_index)) !=
-1) {
switch(c) { switch(c) {
case 's': case 's':
server = optarg; server = optarg;
break; break;
case 'h': case 'h':
print_help(); print_help();
return 0; return 0;
break; break;
case 'p': case 'p':
socks_proxy_url = optarg; socks_proxy_url = optarg;
socks_proxy_flag = true; socks_proxy_flag = true;
break; break;
case 'P': case 'P':
http_proxy_url = optarg; http_proxy_url = optarg;
http_proxy_flag = true; http_proxy_flag = true;
break; break;
case 'S': case 'S':
silent_flag = true; silent_flag = true;
break; break;
case 'T': case 'T':
token = optarg; token = optarg;
break; break;
case '4': case '4':
ipv4_flag = true; ipv4_flag = true;
break; break;
case '6': case '6':
ipv6_flag = true; ipv6_flag = true;
break; break;
case '?': case '?':
print_usage(); print_usage();
return 0; return 0;
break; break;
default: default:
print_usage(); print_usage();
return 0; return 0;
break; break;
} }
} }
if(access(argv[optind],F_OK)) { if(access(argv[optind], F_OK)) {
fprintf(stderr,"Error opening file\n"); fprintf(stderr, "Error opening file\n");
return -1; return -1;
} }
/* curl options */ /* curl options */
curl_easy_setopt(easy_handle,CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(easy_handle,CURLOPT_WRITEDATA,buffer); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer);
curl_easy_setopt(easy_handle,CURLOPT_URL,server); curl_easy_setopt(easy_handle, CURLOPT_URL, server);
/* Proxy options */ /* Proxy options */
if(socks_proxy_flag && http_proxy_flag) { if(socks_proxy_flag && http_proxy_flag) {
fprintf(stderr,"Socks_Proxy and HTTP_PROXY can't be used at once\n"); fprintf(stderr, "Socks_Proxy and HTTP_PROXY can't be used at once\n");
return -1; return -1;
} else if(socks_proxy_flag) { } else if(socks_proxy_flag) {
curl_easy_setopt(easy_handle,CURLOPT_PROXY,socks_proxy_url); curl_easy_setopt(easy_handle, CURLOPT_PROXY, socks_proxy_url);
curl_easy_setopt(easy_handle,CURLOPT_PROXYTYPE, curl_easy_setopt(
CURLPROXY_SOCKS5_HOSTNAME); easy_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
} else if(http_proxy_flag) { } else if(http_proxy_flag) {
curl_easy_setopt(easy_handle,CURLOPT_PROXY,http_proxy_url); curl_easy_setopt(easy_handle, CURLOPT_PROXY, http_proxy_url);
curl_easy_setopt(easy_handle,CURLOPT_PROXYTYPE, curl_easy_setopt(easy_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
CURLPROXY_HTTP);
} }
/* Which address to use */ /* Which address to use */
if(ipv6_flag) if(ipv6_flag)
curl_easy_setopt(easy_handle,CURLOPT_IPRESOLVE, curl_easy_setopt(easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
CURL_IPRESOLVE_V6);
else if(ipv4_flag) else if(ipv4_flag)
curl_easy_setopt(easy_handle,CURLOPT_IPRESOLVE, curl_easy_setopt(easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
CURL_IPRESOLVE_V4);
else else
curl_easy_setopt(easy_handle,CURLOPT_IPRESOLVE, curl_easy_setopt(
CURL_IPRESOLVE_WHATEVER); easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_WHATEVER);
/* Form parameters */ /* Form parameters */
/* File name */ /* File name */
@ -144,29 +140,40 @@ main(int argc, char **argv)
/* TODO: make it iterate on args so you can upload multiple files /* TODO: make it iterate on args so you can upload multiple files
* at once (clainsafecli file1 file2 ... filen) * at once (clainsafecli file1 file2 ... filen)
*/ */
for(int i = optind; i<argc; i++) { for(int i = optind; i < argc; i++) {
curl_formadd(&post,&last, curl_formadd(&post,
CURLFORM_COPYNAME,"file", &last,
CURLFORM_FILE,argv[i], CURLFORM_COPYNAME,
CURLFORM_END); "file",
CURLFORM_FILE,
argv[i],
CURLFORM_END);
/* Actual file content */ /* Actual file content */
curl_formadd(&post,&last, curl_formadd(&post,
CURLFORM_COPYNAME,"file", &last,
CURLFORM_COPYCONTENTS,argv[i], CURLFORM_COPYNAME,
CURLFORM_END); "file",
CURLFORM_COPYCONTENTS,
argv[i],
CURLFORM_END);
if(token) if(token)
curl_formadd(&post,&last, curl_formadd(&post,
CURLFORM_COPYNAME,"token", &last,
CURLFORM_COPYCONTENTS,token, CURLFORM_COPYNAME,
CURLFORM_END); "token",
CURLFORM_COPYCONTENTS,
token,
CURLFORM_END);
curl_easy_setopt(easy_handle,CURLOPT_NOPROGRESS,silent_flag); curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag);
curl_easy_setopt(easy_handle,CURLOPT_PROGRESSFUNCTION,progress); curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress);
curl_easy_setopt(easy_handle,CURLOPT_HTTPPOST,post); curl_easy_setopt(easy_handle, CURLOPT_HTTPPOST, post);
curl_easy_perform(easy_handle); curl_easy_perform(easy_handle);
if(!silent_flag) puts("");
if(!silent_flag)
putchar('\n');
puts(buffer); puts(buffer);
} }
@ -176,10 +183,9 @@ main(int argc, char **argv)
/* Store link if needed */ /* Store link if needed */
if(enable_links_history) { if(enable_links_history) {
snprintf(history_file_path,256,"%s/%s",getenv("HOME"),path); snprintf(history_file_path, 256, "%s/%s", getenv("HOME"), path);
store_link(history_file_path,buffer); store_link(history_file_path, buffer);
} }
free(buffer); free(buffer);
return 0; return 0;
} }