/* comparison used in face mapping */ static int face_compare (void *pone, void *ptwo) { FACE *one = static_cast<FACE*>(pone), *two = static_cast<FACE*>(ptwo); if (one->type < two->type) return -1; else if (one->type > two->type) return 1; else return lexcmp (one->nodes, two->nodes, one->type); }
Bool ini_find_section ( FILE *inifile, char *section, Bool top) { char *first; ASSERT (inifile != NULL); ASSERT (section != NULL); if (top) /* Reposition at top if wanted */ fseek (inifile, 0, SEEK_SET); /* Read through file until we find what we are looking for */ while (file_read (inifile, iniline)) { first = strskp (iniline); /* Skip leading spaces */ if (*first == ';' || *first == '#' || *first == 0) continue; /* Comment line */ else if (*first == '!') { first = strskp (first + 1); trace (first); } else if (sscanf (first, "[%[^]]", ini_section) == 1 && lexcmp (ini_section, section) == 0) return (TRUE); } return (FALSE); }
MODULE process_the_switch (void) { char *name, *value; name = strtok (arg, ":") + 1; value = strtok (NULL, ""); if ((lexcmp (name, "q") == 0 || lexcmp (name, "quiet") == 0) && !value) switch_quiet = TRUE; else if ((lexcmp (name, "v") == 0 || lexcmp (name, "version") == 0) && !value) { printf ("%s\n", PRODUCT); printf ("%s\n", BUILDMODEL); printf ("%s\n", COPYRIGHT); printf ("Built on: %s\n", BUILDDATE); exit (0); } else if ((lexcmp (name, "h") == 0 || lexcmp (name, "help") == 0) && !value) { display_command_line_syntax (); exit (0); } else { if (value) xml_put_attr (xml_switches, name, value); else xml_put_attr (xml_switches, name, ""); } }
XML_ATTR * xml_attr_ic ( XML_ITEM *item, const char *name, Bool ignore_case) { XML_ATTR *attr; ASSERT (item); ASSERT (name); if (ignore_case) { FORLIST (attr, item-> attrs) if (attr-> name ? lexcmp (attr-> name, name) == 0 : FALSE) return (attr); } else {
int smtp_send_mail_ex ( SMTP *smtp) { FILE *fpin; int iCnt; sock_t socket_handle; char message_boundary [256], strOut [514], strFile [256], strUUEFile [256], buffer [BUFFER_SIZE + 1], *charset, *nb_bit, *data, *p_buffer, *strRcptUserIds; Bool old_ip_nonblock = ip_nonblock; int rcptUserIdsLen; long current_date, current_time, out_size, in_size; char *quoted_subject = NULL, *in_buf, *out_buf; /* Check required parameters */ if (smtp == NULL) return (SMTP_ERROR_CONNECT); if (smtp->strDestUserIds == NULL) return (SMTP_ERROR_MISSING_DESTINATION); if (smtp->strSubject == NULL) return (SMTP_ERROR_MISSING_SUBJECT); if (smtp->strSmtpServer == NULL) return (SMTP_ERROR_MISSING_SERVER_NAME); /* Make sure we block on socket accesses */ ip_nonblock = FALSE; sock_init (); /* Open up the SMTP port (25 most of the time). */ if (smtp-> connect_retry_cnt < 1) smtp-> connect_retry_cnt = 3; nb_bit = "7"; if (smtp-> strCharSet == NULL || *smtp-> strCharSet == '\0') charset = "US-ASCII"; else { charset = smtp-> strCharSet; nb_bit = "8"; if (smtp-> strSubject) { if (lexcmp (charset, "iso-2022-jp") == 0 || lexcmp (charset, "shift_jis") == 0 || lexcmp (charset, "utf-8") == 0) { quoted_subject = encode_mimeb_string (NULL, 0, (byte *) smtp->strSubject, charset); } else quoted_subject = encode_quoted_string (NULL, 0, (byte *) smtp->strSubject, charset); } } socket_handle = connect_socket (smtp-> strSmtpServer, "smtp", "tcp", NULL, smtp-> connect_retry_cnt, smtp-> retry_wait_time); if (socket_handle == INVALID_SOCKET || getreply (socket_handle, smtp) > SMTP_SERVER_ERROR) { mem_strfree ("ed_subject); sock_term (); return (SMTP_ERROR_CONNECT); } /* Format a SMTP meassage header. */ /* Just say hello to the mail server. */ xstrcpy (strOut, "HELO ", get_hostname (), "\r\n", NULL); send_data (socket_handle, strOut); if (getreply (socket_handle, smtp) > SMTP_SERVER_ERROR) { CLEAN_SEND_MAIL; return (SMTP_ERROR_INIT); } /* Tell the mail server who the message is from. */ xstrcpy (strOut, "MAIL FROM:<", smtp-> strSenderUserId, ">\r\n", NULL); send_data (socket_handle, strOut); if (getreply (socket_handle, smtp) > SMTP_SERVER_ERROR) { CLEAN_SEND_MAIL; return (SMTP_ERROR_INVALID_SENDER); } rcptUserIdsLen = 0; if (smtp-> strDestUserIds) rcptUserIdsLen += strlen (smtp->strDestUserIds) + 1; if (smtp-> strCcUserIds) rcptUserIdsLen += strlen (smtp->strCcUserIds) + 1; if (smtp-> strBccUserIds) rcptUserIdsLen += strlen (smtp->strBccUserIds) + 1; strRcptUserIds = (char *) mem_alloc (rcptUserIdsLen); p_buffer = strRcptUserIds; data = smtp-> strDestUserIds; while (*data) *p_buffer++ = *data++; if (smtp-> strCcUserIds) { *p_buffer++ = ';'; data = smtp-> strCcUserIds; while (*data) *p_buffer++ = *data++; } if (smtp-> strBccUserIds) { *p_buffer++ = ';'; data = smtp-> strBccUserIds; while (*data) *p_buffer++ = *data++; } *p_buffer = '\0'; /* The following tells the mail server who to send it to. */ iCnt = 0; if (*strRcptUserIds) { FOREVER { getstrfld (strRcptUserIds, iCnt++, 0, ",;", buffer); if (*buffer) { xstrcpy (strOut, "RCPT TO:<", buffer, ">\r\n", NULL); send_data (socket_handle, strOut); if (getreply (socket_handle, smtp) > SMTP_SERVER_ERROR) { CLEAN_SEND_MAIL; return (SMTP_ERROR_INVALID_RECEIPT_USER); } } else break; } } mem_free (strRcptUserIds); /* Now give it the Subject and the message to send. */ send_data (socket_handle, "DATA\r\n"); if (getreply (socket_handle, smtp) > SMTP_SERVER_ERROR) { CLEAN_SEND_MAIL; return (SMTP_ERROR_INVALID_DATA); } /* Set the date and time of the message. */ get_date_time_now (¤t_date, ¤t_time); xstrcpy ( strOut, "Date: ", encode_mime_time (current_date, current_time), " \r\n", NULL ); /* The following shows all who it was sent to. */ if ( smtp-> strFullDestUserIds && *smtp-> strFullDestUserIds ) { replacechrswith (smtp-> strFullDestUserIds, ";", ','); xstrcat (strOut, "To: ", smtp-> strFullDestUserIds, "\r\n", NULL); } else { replacechrswith (smtp-> strDestUserIds, ";", ','); xstrcat (strOut, "To: ", smtp-> strDestUserIds, "\r\n", NULL); } /* Set up the Reply-To path. */ if (!smtp-> strRetPathUserId || !*smtp-> strRetPathUserId) smtp-> strRetPathUserId = smtp-> strSenderUserId; if ( strstr( smtp-> strRetPathUserId, "<" ) != NULL && strstr( smtp-> strRetPathUserId, ">" ) != NULL ) xstrcat (strOut, "Reply-To:", smtp-> strRetPathUserId, "\r\n", NULL); else xstrcat (strOut, "Reply-To:<", smtp-> strRetPathUserId, ">\r\n", NULL); if ( smtp-> strFullSenderUserId && *smtp-> strFullSenderUserId ) { xstrcat (strOut, "Sender: ", smtp-> strFullSenderUserId, "\r\n", NULL); xstrcat (strOut, "From: ", smtp-> strFullSenderUserId, "\r\n", NULL); } else { xstrcat (strOut, "Sender: ", smtp-> strSenderUserId, "\r\n", NULL); xstrcat (strOut, "From: ", smtp-> strSenderUserId, "\r\n", NULL); } send_data (socket_handle, strOut); *strOut = '\0'; /* Post any CC's. */ if (smtp->strFullCcUserIds && *smtp->strFullCcUserIds) { replacechrswith (smtp->strFullCcUserIds, ";", ','); xstrcat (strOut, "Cc:", smtp->strFullCcUserIds, "\r\n", NULL ); } else if (smtp->strCcUserIds && *smtp->strCcUserIds) { replacechrswith (smtp->strCcUserIds, ";", ','); xstrcat (strOut, "Cc:", smtp->strCcUserIds, "\r\n", NULL ); } /* Post any BCC's. */ if (smtp->strFullBccUserIds && *smtp->strFullBccUserIds) { replacechrswith (smtp->strFullBccUserIds, ";", ','); xstrcat (strOut, "Bcc:", smtp->strFullBccUserIds, "\r\n", NULL); } else if (smtp->strBccUserIds && *smtp->strBccUserIds) { replacechrswith (smtp->strBccUserIds, ";", ','); xstrcat (strOut, "Bcc:", smtp->strBccUserIds, "\r\n", NULL); } /* Post any Return-Receipt-To. */ if (smtp->strRrcpUserId && *smtp->strRrcpUserId) xstrcat (strOut, "Return-Receipt-To:", smtp->strRrcpUserId, ">\r\n", NULL); if (smtp->strMailerName && *smtp->strMailerName) xstrcat (strOut, "X-Mailer: ", smtp->strMailerName, "\r\n", NULL); else strcat (strOut, "X-Mailer: sflmail function\r\n"); /* Set the mime version. */ get_date_time_now (¤t_date, ¤t_time); sprintf (message_boundary, "%s.%ld.%ld", MESSAGE_BOUNDARY, current_date, current_time); if ( smtp->strHtmlMessageBody && *smtp->strHtmlMessageBody ) xstrcat (strOut, "MIME-Version: 1.0\r\n", "Content-Type: multipart/alternative; boundary=\"", message_boundary,"\"\r\n", NULL); else xstrcat (strOut, "MIME-Version: 1.0\r\n", "Content-Type: Multipart/Mixed; boundary=\"", message_boundary,"\"\r\n", NULL); send_data (socket_handle, strOut); *strOut = '\0'; /* Write out any message comment included. */ if (smtp->strMsgComment && *smtp->strMsgComment) xstrcpy (strOut, "Comments: ", smtp->strMsgComment, "\r\n", NULL); /* Send the subject and message body. */ if (quoted_subject) xstrcat (strOut, "Subject: ", quoted_subject, "\r\n\r\n", NULL); else xstrcat (strOut, "Subject: ", smtp->strSubject, "\r\n\r\n", NULL); send_data (socket_handle, strOut); /* Keep rfc822 in mind with all the sections. */ if (smtp->strMessageBody && *smtp->strMessageBody) { /* check if we got html/alternate files */ if ( smtp->strHtmlMessageBody && *smtp->strHtmlMessageBody ) { xstrcpy (strOut, "\r\n\r\n--", message_boundary, "\r\n", "Content-Type: text/html; charset=", charset, "\r\n", "Content-Transfer-Encoding: 7BIT\r\n", "Content-description: Body of message\r\n\r\n", NULL); send_data (socket_handle, strOut); send_body (socket_handle, smtp->strHtmlMessageBody); send_data (socket_handle, "\r\n"); xstrcpy (strOut, "\r\n--", message_boundary, "\r\n", "Content-Type: text/plain; charset=", charset, "\r\n", "Content-Transfer-Encoding: ", nb_bit, "BIT\r\n", "Content-description: Body of message\r\n\r\n", NULL); send_data (socket_handle, strOut); send_body (socket_handle, smtp-> strMessageBody); send_data (socket_handle, "\r\n"); } else { xstrcpy (strOut, "\r\n--", message_boundary, "\r\n", "Content-Type: text/plain; charset=", charset, "\r\n", "Content-Transfer-Encoding: ", nb_bit, "BIT\r\n", "Content-description: Body of message\r\n\r\n", NULL); send_data (socket_handle, strOut); send_body (socket_handle, smtp-> strMessageBody); send_data (socket_handle, "\r\n"); } } /* Include any Text type files and Attach them to the message. */ if (smtp->strTxtFiles && *smtp->strTxtFiles) { iCnt = 0; FOREVER { getstrfld (smtp->strTxtFiles, iCnt++, 0, ",;", strFile); strcrop (strskp (strFile)); if (*strFile) { fpin = fopen (strFile, "rb"); if (!fpin) { strcpy (smtp->strlast_smtp_message, strFile); { CLEAN_SEND_MAIL; return (SMTP_ERROR_MISSING_ATTACH_FILE); } } xstrcpy (strOut, "\r\n--", message_boundary, "\r\n", "Content-Type: text/plain; charset=", charset, "\r\n", "Content-Transfer-Encoding: ", nb_bit, "BIT\r\n", "Content-Disposition: attachment; filename=", getfilename (strFile), "\r\n\r\n", NULL); send_data (socket_handle, strOut); while (fgets (buffer, BUFFER_SIZE, fpin)) { if (*buffer == '.') write_TCP (socket_handle, ".", 1); send_data (socket_handle, buffer); } fclose (fpin); } else break; } }
static int eval_count (int argc, SCRIPT_NODE **argv, SCRIPT_NODE *result) { long item, n; SCRIPT_NODE *identifier = argc > 0 ? argv [0] : NULL, *condition = argc > 1 ? argv [1] : NULL; char *name, *xml_name; SCOPE_BLOCK *for_block; SCOPE_ITEM *scope_item; XML_ITEM *from_xml, *xml_item; Bool error = FALSE; if (identifier-> type == GG_SYMBOL) { if ((evaluate_script_node (identifier-> op1) != 0) || (evaluate_script_node (identifier-> op2) != 0)) return -1; from_xml = lookup_from_xml (identifier-> op1); if (! from_xml) return -1; name = (identifier-> op2) ? string_result (identifier-> op2) : NULL; } else { gg_report_error ('E', "Function argument must be an identifier."); return -1; } n = 0; if (from_xml) { for_block = create_scope_block ("count"); for_block-> children = TRUE; xml_item = xml_first_child (from_xml); item = 0; while (xml_item) { while (xml_item) { xml_name = xml_item_name (xml_item); if (xml_name && name) { if (ignorecase) { if (lexcmp (xml_name, name) == 0) break; } else { if (streq (xml_name, name)) break; } } else /* Take all named children; others are part of value */ if (xml_name && (! name)) break; xml_item = xml_next_sibling (xml_item); } item++; if (xml_item) { if (condition) { scope_item = create_scope_item (for_block, xml_item, item); for_block-> scope_item = scope_item; for_block-> xml_item = xml_item; if (evaluate_script (condition) != 0) { error = TRUE; break; } number_result (condition); if ((condition-> result_type == TYPE_NUMBER) && (condition-> result_n != 0)) n++; gg_clean (condition); } else n++; xml_item = xml_next_sibling (xml_item); } } destroy_scope_block (); if (error) return -1; } result-> result_type = TYPE_NUMBER; result-> result_n = n; return 0; }
TA_RetCode TA_AllocStringFromYahooName( TA_Libc *libHandle, TA_DecodingParam *marketDecodingParam, const char *yahooSymbol, TA_String **allocatedCategoryName, TA_String **allocatedSymbolName, unsigned int allowOnlineProcessing ) { TA_PROLOG; TA_RetCode retCode; const char *symbol; unsigned int symbolLength; const char *ext; const char *countryAbbrev; const char *exchangeString; const char *typeString; unsigned int i; char *tempBuffer; TA_String *allocCategory; TA_String *allocSymbol; TA_StringCache *stringCache; TA_CountryId countryId; TA_YahooMarketPage *allocatedMarketPage; TA_TRACE_BEGIN( libHandle, TA_AllocStringFromYahooName ); /* Validate parameter */ if( !libHandle || !marketDecodingParam || !yahooSymbol || !allocatedCategoryName || !allocatedSymbolName ) { TA_TRACE_RETURN( TA_BAD_PARAM ); } stringCache = TA_GetGlobalStringCache( libHandle ); /* Set a pointer on where the symbol start. */ symbol = yahooSymbol; /* Size of the symbol. */ symbolLength = getstrfldlen( symbol, 0, 0, "." ); if( symbolLength < 2 ) { TA_TRACE_RETURN( TA_BAD_PARAM ); } else symbolLength--; /* The 3 strings forming the final Category string. */ countryAbbrev = NULL; exchangeString = NULL; typeString = NULL; /* Identify if there is an extension. */ ext = strchr( symbol, '.' ); if( ext ) { ext++; if( *ext == '\0' ) ext = NULL; } /* If ext != NULL, ext points on first char of the extension. */ if( ext ) { /* Identify known USA/CAN extension. */ for( i=0; i < NB_YAHOO_EXCHANGE_EXTENSION; i++ ) { if( lexcmp( TA_YahooExtensionTable[i].extension, ext ) == 0 ) { countryId = TA_YahooExtensionTable[i].countryId; countryAbbrev = TA_CountryIdToAbbrev( countryId ); exchangeString = TA_YahooExtensionTable[i].exchange; typeString = TA_YahooExtensionTable[i].type; break; /* Exit the loop */ } } /* Unknown extension, let's use the whole thing * as the symbol and keep going as if nothing * happened. */ if( !countryAbbrev ) ext = NULL; /* No known extension. */ } if( !exchangeString ) { /* If online access is not allowed, and the * symbol does not have a known extension, it * is not possible to identify the exchange. * * With online access, the exchange can be * found by doing further investigation on the * Yahoo! web sites. */ if( !allowOnlineProcessing ) return TA_INVALID_SECURITY_EXCHANGE; /* OK, we need to proceed by extracting the info * from Yahoo! web sites. */ retCode = internalMarketPageAlloc( libHandle, marketDecodingParam, yahooSymbol, &allocatedMarketPage ); if( retCode != TA_SUCCESS ) return retCode; TA_DEBUG_ASSERT( libHandle, allocatedMarketPage->exchange != NULL ); TA_DEBUG_ASSERT( libHandle, allocatedMarketPage->type != NULL ); /* All these string pointer are globals. So the allocatedMarketPage * can be freed and the member-poitners are still valid. */ countryAbbrev = TA_CountryIdToAbbrev( allocatedMarketPage->countryId ); exchangeString = allocatedMarketPage->exchange; typeString = allocatedMarketPage->type; internalMarketPageFree( allocatedMarketPage ); } TA_DEBUG_ASSERT( libHandle, typeString != NULL ); TA_DEBUG_ASSERT( libHandle, exchangeString != NULL ); TA_DEBUG_ASSERT( libHandle, countryAbbrev != NULL ); /* Build the Category string into a buffer. */ tempBuffer = TA_Malloc( libHandle, strlen( countryAbbrev ) + strlen( exchangeString ) + strlen( typeString ) + 3 ); sprintf( tempBuffer, "%s.%s.%s", countryAbbrev, exchangeString, typeString ); /* Allocate the Category string. */ allocCategory = TA_StringAlloc_UC( stringCache, tempBuffer ); TA_Free( libHandle, tempBuffer ); if( !allocCategory ) { TA_TRACE_RETURN( TA_ALLOC_ERR ); } /* Allocate the symbol string. */ allocSymbol = TA_StringAllocN_UC( stringCache, symbol, symbolLength ); if( !allocSymbol ) { TA_StringFree( stringCache, allocCategory ); TA_TRACE_RETURN( TA_ALLOC_ERR ); } /* Everything went fine, return the info to the caller. */ *allocatedCategoryName = allocCategory; *allocatedSymbolName = allocSymbol; TA_TRACE_RETURN( TA_SUCCESS ); }