/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "servers.h" #include "ILog.h" #include "curl_serve.h" #include "ftp_servers.h" #include "http_servers.h" #include "smtp_servers.h" #include #include #include void ServersInit(ServerParam init) { SetVerboseLog(init.logFlag); SetSslVerify(init.sslVerifyFlag); } void ServersUnInit(void) { } void HttpGet(ServerHttp *param) { LogInfo("HttpGet\n"); HttpServersGet(param); } void HttpPost(ServerHttp *param) { LogInfo("HttpPost\n"); HttpServersPost(param); } void HttpPostFile(ServerHttp *param) { LogInfo("HttpPostFile\n"); HttpServersPostFile(param); } void HttpPut(ServerHttp *param) { LogInfo("HttpPut\n"); HttpServersPut(param); } void smtp_send_email(ServerSmtp *param) { LogInfo("smtp_send_email\n"); SmtpServersSendEmail(param); // SmtpServersSendEmailOnlyText(param); } ServerHttp *NewServersHttp(const char *url) { if (!url) { LogError("NewServersHttp failed.\n"); return NULL; } ServerHttp result = { .url = url, .postData = NULL, .filePath = NULL, .header = NULL, .reply = NULL, .replyLength = 0, .code = 0}; const int LENGTH = sizeof(ServerHttp); ServerHttp *p = (ServerHttp *)malloc(LENGTH); if (p) { LogInfo("malloc succeed.\n"); memcpy(p, &result, LENGTH); } return p; } void DeleteServersHttp(ServerHttp *ptr) { if (ptr) { if (ptr->reply) { free(ptr->reply); ptr->reply = NULL; } free(ptr); } } ServerFtp *NewServersFtp(const char *url, const FtpsFlag ftpsFlag) { if (!url) { LogError("NewServersFtp failed.\n"); return NULL; } ServerFtp result = {.url = url, .ftpsFlag = ftpsFlag, .user_password = NULL, .filePath = NULL, .timeOutMs = SERVERS_NEVER_TIMEOUT, .code = -1}; const int LENGTH = sizeof(ServerFtp); ServerFtp *p = (ServerFtp *)malloc(LENGTH); if (p) { LogInfo("malloc succeed.\n"); memcpy(p, &result, LENGTH); } return p; } void DeleteServersFtp(ServerFtp *ptr) { if (ptr) { free(ptr); } } void FtpServersCheck(ServerFtp *param) { FtpServersCheckConnect(param); } void FtpDownload(ServerFtp *param) { LogInfo("FtpDownload\n"); FtpServersDownload(param); } void FtpUpload(ServerFtp *param) { LogInfo("FtpUpload\n"); FtpServersUpload(param); } ServerSmtp *new_servers_smtp(const char *url, const char *subject, const char *from, const char *to, const char *userName, const char *password, const char *date) { if (!url || !from || !to || !userName || !password || !subject || !date) { LogError("new_servers_smtp failed.\n"); return NULL; } ServerSmtp result = {.url = url, .subject = subject, .from = from, .to = to, .userName = userName, .password = password, .date = date, .inlineText = NULL, // .text = NULL, // .textLength = 0, .attachment = NULL, .code = -1}; const int LENGTH = sizeof(ServerSmtp); ServerSmtp *p = (ServerSmtp *)malloc(LENGTH); if (p) { LogInfo("malloc succeed.\n"); memcpy(p, &result, LENGTH); } return p; } void delete_servers_smtp(ServerSmtp *ptr) { if (ptr) { free(ptr); } }