Exemple #1
0
int read_client_rqst(int client_sockfd, HTTPMessage ** msg_ptr, 
					 char * buf, int size)
{
  memset(buf, 0, size);
  int n = read(client_sockfd, buf, size-1);
  buf[size-1] = '\0';
  if(n<0)
    error("\nERROR READING FROM CLIENT SOCKET\n");
  printf("\n\n--------------------\n***Client Request***\n%s***End***\n\n\n", buf);

  /* Initialize Message */
  HTTPMessage * client_rqst = init_HTTPMessage(CLIENT_RQST, buf);
  *(msg_ptr) = client_rqst;

  /* Extract Request Fields */
  int line_f1_len = extract_field(REQUEST, buf,
	                              &(client_rqst->msg_line_f1)); 
  int line_f2_len = extract_field(FILENAME,buf+line_f1_len, 
								  &(client_rqst->msg_line_f2));
  int line_f3_len = extract_field(HTTPVER, buf+line_f1_len+line_f2_len,
								  &(client_rqst->msg_line_f3));

  //print_msg_fields(client_rqst);  

  if(client_rqst->msg_line_f1 == NULL ||
	 client_rqst->msg_line_f1 == NULL ||
	 client_rqst->msg_line_f1 == NULL)
  {
	return -1;
  }
  return 1;
}
Exemple #2
0
/**
 * Process a slave replication registration message.
 *
 * We store the various bits of information the slave gives us and generate
 * a reply message.
 *
 * @param	router		The router instance
 * @param	slave		The slave server
 * @param	queue		The BINLOG_DUMP packet
 * @return			Non-zero if data was sent
 */
static int
blr_slave_register(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
{
GWBUF	*resp;
uint8_t	*ptr;
int	len, slen;

	ptr = GWBUF_DATA(queue);
	len = extract_field(ptr, 24);
	ptr += 4;		// Skip length and sequence number
	if (*ptr++ != COM_REGISTER_SLAVE)
		return 0;
	slave->serverid = extract_field(ptr, 32);
	ptr += 4;
	slen = *ptr++;
	if (slen != 0)
	{
		slave->hostname = strndup((char *)ptr, slen);
		ptr += slen;
	}
	else
		slave->hostname = NULL;
	slen = *ptr++;
	if (slen != 0)
	{
		ptr += slen;
		slave->user = strndup((char *)ptr, slen);
	}
	else
		slave->user = NULL;
	slen = *ptr++;
	if (slen != 0)
	{
		slave->passwd = strndup((char *)ptr, slen);
		ptr += slen;
	}
	else
		slave->passwd = NULL;
	slave->port = extract_field(ptr, 16);
	ptr += 2;
	slave->rank = extract_field(ptr, 32);

	/*
	 * Now construct a response
	 */
	if ((resp = gwbuf_alloc(11)) == NULL)
		return 0;
	ptr = GWBUF_DATA(resp);
	encode_value(ptr, 7, 24);	// Payload length
	ptr += 3;
	*ptr++ = 1;			// Sequence number
	encode_value(ptr, 0, 24);
	ptr += 3;
	encode_value(ptr, slave->serverid, 32);
	slave->state = BLRS_REGISTERED;
	return slave->dcb->func.write(slave->dcb, resp);
}
Exemple #3
0
/**
 * Rotate the slave to the new binlog file
 *
 * @param slave 	The slave instance
 * @param ptr		The rotate event (minus header and OK byte)
 */
void
blr_slave_rotate(ROUTER_SLAVE *slave, uint8_t *ptr)
{
int	len = EXTRACT24(ptr + 9);	// Extract the event length

	len = len - (19 + 8 + 4);	// Remove length of header, checksum and position
	if (len > BINLOG_FNAMELEN)
		len = BINLOG_FNAMELEN;
	ptr += 19;	// Skip header
	slave->binlog_pos = extract_field(ptr, 32);
	slave->binlog_pos += (extract_field(ptr+4, 32) << 32);
	memcpy(slave->binlogfile, ptr + 8, len);
	slave->binlogfile[len] = 0;
}
static int update_range_verify(int marker,
                               unsigned char *flags,
                               const char **note) {

   char field[255];
   int found_update = 0;

   if (extract_field (*note, STREET_PREFIX, field, sizeof(field)) == -1) {
      roadmap_messagebox ("Error", "Can't find street name.");
      return -1;
   }

   if (extract_field (*note, CITY_PREFIX, field, sizeof(field)) == -1) {
      roadmap_messagebox ("Error", "Can't find city name.");
      return -1;
   }

   if (extract_field (*note, UPDATE_LEFT, field, sizeof(field)) != -1) {
      if (atoi(field) <= 0) {
         roadmap_messagebox ("Error", "Left range is invalid.");
         return -1;
      }

      found_update++;
   }

   if (extract_field (*note, UPDATE_RIGHT, field, sizeof(field)) != -1) {
      if (atoi(field) <= 0) {
         roadmap_messagebox ("Error", "Right range is invalid.");
         return -1;
      }

      found_update++;
   }

   if (!found_update) {
      roadmap_messagebox ("Error", "No range updates were found.");
      return -1;
   }

   return 0;
}
Exemple #5
0
void
disasm_fields(const struct opcode *popcode, instr_t instr, vm_offset_t loc, 
	char *disasm_str, size_t slen)
{
	char * pstr;
	enum function_mask func;
	int len;

#define ADD_LEN(s)	do { \
		len = (s); \
		slen -= len; \
		pstr += len; \
	} while(0)
#define APP_PSTR(fmt, arg)	ADD_LEN(snprintf(pstr, slen, (fmt), (arg)))
#define APP_PSTRS(fmt)		ADD_LEN(snprintf(pstr, slen, "%s", (fmt)))

	pstr = disasm_str;

	func =  popcode->func;
	if (func & Op_BC) {
		u_int BO, BI;
		BO = extract_field(instr, 31 - 10, 5);
		BI = extract_field(instr, 31 - 15, 5);
		func &= ~Op_BC;
		if (BO & 4) {
			/* standard, no decrement */
			if (BO & 16) {
				if (popcode->code == 0x40000000) {
					APP_PSTRS("c");
					func |= Op_BO | Op_BI;
				}
			}
			else {
				APP_PSTRS(condstr[((BO & 8) >> 1) + (BI & 3)]);
				if (BI >= 4)
					func |= Op_crfS;
			}
		}
		else {
			/* decrement and branch */
			if (BO & 2)
Exemple #6
0
int bladerf_get_cal_field(struct bladerf *dev, char *field,
                            char *data, size_t data_size)
{
    int status;
    char cal[CAL_BUFFER_SIZE];

    status = dev->fn->get_cal(dev, cal);
    if (status < 0)
        return status;
    else
        return extract_field(cal, CAL_BUFFER_SIZE, field, data, data_size);
}
static void
extract_info(EContactEditorIm *editor)
{
	if (editor->username != NULL)
		g_free(editor->username);

	editor->username = extract_field(editor, "entry-username");

	/*
	 * NOTE: We don't need to handle the option menus.
	 *       These are set by the callbacks.
	 */
}
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
{
    AVFilterContext *ctx = inlink->dst;
    SeparateFieldsContext *s = ctx->priv;
    AVFilterLink *outlink = ctx->outputs[0];
    int ret;

    inpicref->height = outlink->h;
    inpicref->interlaced_frame = 0;

    if (!s->second) {
        goto clone;
    } else {
        AVFrame *second = s->second;

        extract_field(second, s->nb_planes, second->top_field_first);

        if (second->pts != AV_NOPTS_VALUE &&
            inpicref->pts != AV_NOPTS_VALUE)
            second->pts += inpicref->pts;
        else
            second->pts = AV_NOPTS_VALUE;

        ret = ff_filter_frame(outlink, second);
        if (ret < 0)
            return ret;
clone:
        s->second = av_frame_clone(inpicref);
        if (!s->second)
            return AVERROR(ENOMEM);
    }

    extract_field(inpicref, s->nb_planes, !inpicref->top_field_first);

    if (inpicref->pts != AV_NOPTS_VALUE)
        inpicref->pts *= 2;

    return ff_filter_frame(outlink, inpicref);
}
Exemple #9
0
int bladerf_get_otp_field(struct bladerf *dev, char *field,
                             char *data, size_t data_size)
{
    int status;
    char otp[OTP_BUFFER_SIZE];

    memset(otp, 0xff, OTP_BUFFER_SIZE);

    status = dev->fn->get_otp(dev, otp);
    if (status < 0)
        return status;
    else
        return extract_field(otp, OTP_BUFFER_SIZE, field, data, data_size);
}
static int flush_frame(AVFilterLink *outlink, int64_t pts, int64_t *out_pts)
{
    AVFilterContext *ctx = outlink->src;
    SeparateFieldsContext *s = ctx->priv;
    int ret = 0;

    if (s->second) {
        *out_pts = s->second->pts += pts;
        extract_field(s->second, s->nb_planes, s->second->top_field_first);
        ret = ff_filter_frame(outlink, s->second);
        s->second = NULL;
    }

    return ret;
}
Exemple #11
0
int extract_max_size(str *body, str *max_size)
{
	static const str field = str_init("a=max-size:");
	return extract_field(body, max_size, field);
}
Exemple #12
0
int extract_accept_wrapped_types(str *body, str *accept_wrapped_types)
{
	static const str field = str_init("a=accept-wrapped-types:");
	return extract_field(body, accept_wrapped_types, field);
}
Exemple #13
0
int extract_ptime(str *body, str *ptime)
{
	static const str field = str_init("a=ptime:");
	return extract_field(body, ptime, field);
}
Exemple #14
0
void
disasm_fields(const struct opcode *popcode, instr_t instr, vm_offset_t loc, 
	char *disasm_str)
{
	char * pstr;
	enum function_mask func;

	pstr = disasm_str;

	func =  popcode->func;
	if (func & Op_OE) {
		u_int OE;
		/* also for Op_S (they are the same) */
		OE = extract_field(instr, 31 - 21, 1);
		if (OE) {
			pstr += sprintf(pstr, "o");
		}
		func &= ~Op_OE;
	}
	switch (func & Op_LKM) {
	case Op_Rc:
		if (instr & 0x1) {
			pstr += sprintf(pstr, ".");
		}
		break;
	case Op_AA:
		if (instr & 0x2) {
			pstr += sprintf(pstr, "a");
			loc = 0; /* Absolute address */
		}
	case Op_LK:
		if (instr & 0x1) {
			pstr += sprintf(pstr, "l");
		}
		break;
	default:
		func &= ~Op_LKM;
	}
	pstr += sprintf(pstr, "\t");

	/* XXX: special cases here, out of flags in a 32bit word. */
	if (strcmp(popcode->name, "wrteei") == 0) {
		int E;
		E = extract_field(instr, 31 - 16, 5);
		pstr += sprintf(pstr, "%d", E);
		return;
	}
	/* XXX: end of special cases here. */

	if (func & Op_D) {
		u_int D;
		/* also for Op_S (they are the same) */
		D = extract_field(instr, 31 - 10, 5);
		pstr += sprintf(pstr, "r%d, ", D);
		func &= ~Op_D;
	}
	if (func & Op_crbD) {
		u_int crbD;
		crbD = extract_field(instr, 31 - 10, 5);
		pstr += sprintf(pstr, "crb%d, ", crbD);
		func &= ~Op_crbD;
	}
	if (func & Op_crfD) {
		u_int crfD;
		crfD = extract_field(instr, 31 - 8, 3);
		pstr += sprintf(pstr, "crf%d, ", crfD);
		func &= ~Op_crfD;
	}
	if (func & Op_L) {
		u_int L;
		L = extract_field(instr, 31 - 10, 1);
		if (L) {
			pstr += sprintf(pstr, "L, ");
		}
		func &= ~Op_L;
	}
	if (func & Op_FM) {
		u_int FM;
		FM = extract_field(instr, 31 - 10, 8);
		pstr += sprintf(pstr, "%d, ", FM);
		func &= ~Op_FM;
	}
	if (func & Op_TO) {
		u_int TO;
		TO = extract_field(instr, 31 - 10, 1);
		pstr += sprintf(pstr, "%d, ", TO);
		func &= ~Op_TO;
	}
	if (func & Op_crfS) {
		u_int crfS;
		crfS = extract_field(instr, 31 - 13, 3);
		pstr += sprintf(pstr, "%d, ", crfS);
		func &= ~Op_crfS;
	}
	if (func & Op_BO) {
		u_int BO;
		BO = extract_field(instr, 31 - 10, 5);
		pstr += sprintf(pstr, "%d, ", BO);
		func &= ~Op_BO;
	}
	if (func & Op_A) {
		u_int A;
		A = extract_field(instr, 31 - 15, 5);
		pstr += sprintf(pstr, "r%d, ", A);
		func &= ~Op_A;
	}
	if (func & Op_B) {
		u_int B;
		B = extract_field(instr, 31 - 20, 5);
		pstr += sprintf(pstr, "r%d, ", B);
		func &= ~Op_B;
	}
	if (func & Op_C) {
		u_int C;
		C = extract_field(instr, 31 - 25, 5);
		pstr += sprintf(pstr, "r%d, ", C);
		func &= ~Op_C;
	}
	if (func & Op_BI) {
		u_int BI;
		BI = extract_field(instr, 31 - 10, 5);
		pstr += sprintf(pstr, "%d, ", BI);
		func &= ~Op_BI;
	}
	if (func & Op_crbA) {
		u_int crbA;
		crbA = extract_field(instr, 31 - 15, 5);
		pstr += sprintf(pstr, "%d, ", crbA);
		func &= ~Op_crbA;
	}
	if (func & Op_crbB) {
		u_int crbB;
		crbB = extract_field(instr, 31 - 20, 5);
		pstr += sprintf(pstr, "%d, ", crbB);
		func &= ~Op_crbB;
	}
	if (func & Op_CRM) {
		u_int CRM;
		CRM = extract_field(instr, 31 - 19, 8);
		pstr += sprintf(pstr, "0x%x, ", CRM);
		func &= ~Op_CRM;
	}
	if (func & Op_LI) {
		int LI;
		LI = extract_field(instr, 31 - 29, 24);
		/* Need to sign extend and shift up 2, then add addr */
		LI = LI << 8;
		LI = LI >> 6;
		LI += loc;
		pstr += sprintf (pstr, "0x%x, ", LI);
		func &= ~Op_LI;
	}
Exemple #15
0
/*
**  mailmsg() sends a message to the owner of the file, if one is defined,
**  telling of errors (i.e., link not available).
*/
PUBLIC void mailmsg ARGS4(
	int,		cur,
	char *,		owner_address,
	char *,		filename,
	char *,		linkname)
{
    FILE *fd, *fp;
    char *address = NULL;
    char *searchpart = NULL;
    char *cmd = NULL, *cp;
#ifdef ALERTMAIL
    BOOLEAN skip_parsing = FALSE;
#endif
#if !CAN_PIPE_TO_MAILER
    char *ccaddr;
    char subject[128];
    char my_tmpfile[LY_MAXPATH];
#endif
#if USE_VMS_MAILER
    BOOLEAN isPMDF = LYMailPMDF();
    char hdrfile[LY_MAXPATH];
    char *command = NULL;

    CTRACE((tfp, "mailmsg(%d, \"%s\", \"%s\", \"%s\")\n", cur,
	NONNULL(owner_address),
	NONNULL(filename),
	NONNULL(linkname)));

#endif /* VMS */

    if (!LYSystemMail())
	return;

#ifdef ALERTMAIL
    if (owner_address == NULL) {
	owner_address = ALERTMAIL;
	skip_parsing = TRUE;
    }
#endif

    if (isEmpty(owner_address))
	return;
    if ((cp = (char *)strchr(owner_address,'\n')) != NULL) {
#ifdef ALERTMAIL
	if (skip_parsing)
	    return;		/* invalidly defined - ignore - kw */
#else
	*cp = '\0';
#endif
    }
    if (!strncasecomp(owner_address, "lynx-dev@", 9)) {
	/*
	 *  Silently refuse sending bad link messages to lynx-dev.
	 */
	return;
    }
    StrAllocCopy(address, owner_address);

#ifdef ALERTMAIL
    /*
     *  If we are using a fixed address given by ALERTMAIL, it is
     *  supposed to already be in usable form, without URL-isms like
     *  ?-searchpart and URL-escaping.  So skip some code. - kw
     */
    if (!skip_parsing)
#endif
    {
	/*
	 *	Check for a ?searchpart. - FM
	 */
	if ((cp = strchr(address, '?')) != NULL) {
	    StrAllocCopy(searchpart, cp);
	    *cp = '\0';
	    cp = (searchpart + 1);
	    if (*cp != '\0') {
		/*
		 * Seek and handle to=address(es) fields.
		 * Appends to address.  We ignore any other
		 * headers in the ?searchpart.  - FM
		 */
		extract_field(&address, searchpart, "to=");
	    }
	}

	convert_explorer(address);

	/*
	 *  Unescape the address field. - FM
	 */
	SafeHTUnEscape(address);
    }

    if (trim_comma(address)) {
	FREE(address);
	CTRACE((tfp, "mailmsg: No address in '%s'.\n", owner_address));
	return;
    }

#if CAN_PIPE_TO_MAILER
    if ((fd = LYPipeToMailer()) == 0) {
	FREE(address);
	CTRACE((tfp, "mailmsg: '%s' failed.\n", cmd));
	return;
    }

    fprintf(fd, "To: %s\n", address);
    fprintf(fd, "Subject: Lynx Error in %s\n", filename);
    if (!isEmpty(personal_mail_address)) {
	fprintf(fd, "Cc: %s\n", personal_mail_address);
    }
    fprintf(fd, "X-URL: %s\n", filename);
    fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION);
#else
    if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) {
	CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", my_tmpfile));
	FREE(address);
	return;
    }
    sprintf(subject, "Lynx Error in %.56s", filename);
    ccaddr = personal_mail_address;
#if USE_VMS_MAILER
    if (isPMDF) {
	FILE *hfd;
	if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) {
	    CTRACE((tfp, "mailmsg: Could not fopen '%s'.\n", hdrfile));
	    FREE(address);
	    return;
	}

	if (!isEmpty(personal_mail_address)) {
	    fprintf(fd, "Cc: %s\n", personal_mail_address);
	}
	fprintf(fd, "X-URL: %s\n", filename);
	fprintf(fd, "X-Mailer: %s, Version %s\n\n", LYNX_NAME, LYNX_VERSION);
	/*
	 *  For PMDF, put the subject in the
	 *  header file and close it. - FM
	 */
	fprintf(hfd, "Subject: Lynx Error in %.56s\n\n", filename);
	LYCloseTempFP(hfd);
    }
#endif /* USE_VMS_MAILER */
#endif /* CAN_PIPE_TO_MAILER */

    fprintf(fd, gettext("The link   %s :?: %s \n"),
		links[cur].lname, links[cur].target);
    fprintf(fd, gettext("called \"%s\"\n"), LYGetHiliteStr(cur, 0));
    fprintf(fd, gettext("in the file \"%s\" called \"%s\"\n"), filename, linkname);
    fprintf(fd, "%s\n\n", gettext("was requested but was not available."));
    fprintf(fd, "%s\n\n", gettext("Thought you might want to know."));

    fprintf(fd, "%s\n", gettext("This message was automatically generated by"));
    fprintf(fd, "%s %s", LYNX_NAME, LYNX_VERSION);
    if ((LynxSigFile != NULL) &&
	(fp = fopen(LynxSigFile, TXT_R)) != NULL) {
	fputs("-- \n", fd);
	while (LYSafeGets(&cmd, fp) != NULL)
	    fputs(cmd, fd);
	LYCloseInput(fp);
    }
#if CAN_PIPE_TO_MAILER
    pclose(fd);
#else
    LYCloseTempFP(fd);
#if USE_VMS_MAILER
    if (isPMDF) {
	/*
	 *  Now set up the command. - FM
	 */
	HTSprintf0(&command,
		"%s %s %s,%s ",
		system_mail,
		system_mail_flags,
		hdrfile,
		my_tmpfile);
    } else {
	/*
	 *  For "generic" VMS MAIL, include the
	 *  subject in the command. - FM
	 */
	HTSprintf0(&command,
		"%s %s/self/subject=\"Lynx Error in %.56s\" %s ",
		system_mail,
		system_mail_flags,
		filename,
		my_tmpfile);
    }
    vms_append_addrs(&command, address, "");

    LYSystem(command);	/* VMS */
    FREE(command);
    FREE(cmd);
    LYRemoveTemp(my_tmpfile);
    if (isPMDF) {
	LYRemoveTemp(hdrfile);
    }
#else /* DOS */
    LYSendMailFile (
	address,
	my_tmpfile,
	subject,
	ccaddr,
	"");
    LYRemoveTemp(my_tmpfile);
#endif /* USE_VMS_MAILER */
#endif /* CAN_PIPE_TO_MAILER */

    if (traversal) {
	FILE *ofp;

	if ((ofp = LYAppendToTxtFile(TRAVERSE_ERRORS)) == NULL) {
	    if ((ofp = LYNewTxtFile(TRAVERSE_ERRORS)) == NULL) {
		perror(NOOPEN_TRAV_ERR_FILE);
		exit_immediately(EXIT_FAILURE);
	    }
	}

	fprintf(ofp, "%s\t%s \tin %s\n",
		     links[cur].lname, links[cur].target, filename);
	LYCloseOutput(ofp);
    }

    FREE(address);
    return;
}
Exemple #16
0
/*
**  mailform() sends form content to the mailto address(es). - FM
*/
PUBLIC void mailform ARGS4(
    CONST char *,	mailto_address,
    CONST char *,	mailto_subject,
    CONST char *,	mailto_content,
    CONST char *,	mailto_type)
{
    FILE *fd;
    char *address = NULL;
    char *ccaddr = NULL;
    char *keywords = NULL;
    char *cp = NULL;
    char self[MAX_SUBJECT + 10];
    char subject[MAX_SUBJECT + 10];
    char *searchpart = NULL;
    char buf[512];
    int ch, len, i;
#if USE_VMS_MAILER
    static char *cmd;
    char *command = NULL;
    BOOLEAN isPMDF = LYMailPMDF();
    char hdrfile[LY_MAXPATH];
#endif
#if !CAN_PIPE_TO_MAILER
    char my_tmpfile[LY_MAXPATH];
#endif

    CTRACE((tfp, "mailto_address: \"%s\"\n", NONNULL(mailto_address)));
    CTRACE((tfp, "mailto_subject: \"%s\"\n", NONNULL(mailto_subject)));
    CTRACE((tfp, "mailto_content: \"%s\"\n", NONNULL(mailto_content)));
    CTRACE((tfp, "mailto_type:    \"%s\"\n", NONNULL(mailto_type)));

    if (!LYSystemMail())
	return;

    if (!mailto_address || !mailto_content) {
	HTAlert(BAD_FORM_MAILTO);
	return;
    }
    subject[0] = '\0';
    self[0] = '\0';

    if ((cp = (char *)strchr(mailto_address,'\n')) != NULL)
	*cp = '\0';
    StrAllocCopy(address, mailto_address);

    /*
     *	Check for a ?searchpart. - FM
     */
    if ((cp = strchr(address, '?')) != NULL) {
	StrAllocCopy(searchpart, cp);
	*cp = '\0';
	cp = (searchpart + 1);
	if (*cp != '\0') {
	    /*
	     *	Seek and handle a subject=foo. - FM
	     */
	    extract_subject(subject, searchpart);

	    /*
	     *	Seek and handle to=address(es) fields.
	     *	Appends to address. - FM
	     */
	    extract_field(&address, searchpart, "to=");

	    /*
	     *	Seek and handle cc=address(es) fields.	Excludes
	     *	Bcc=address(es) as unsafe.  We may append our own
	     *	cc (below) as a list for the actual mailing. - FM
	     */
	    extract_field(&ccaddr, searchpart, "cc=");

	    /*
	     *	Seek and handle keywords=term(s) fields. - FM
	     */
	    extract_field(&keywords, searchpart, "keywords=");

	    if (keywords != NULL) {
		if (*keywords != '\0') {
		    SafeHTUnEscape(keywords);
		} else {
		    FREE(keywords);
		}
	    }

	    FREE(searchpart);
	}
    }

    if (convert_explorer(address)) {
	HTAlert(BAD_FORM_MAILTO);
	goto cleanup;
    }
    if (ccaddr != NULL) {
	if (convert_explorer(ccaddr)) {
	    FREE(ccaddr);
	}
    }

    /*
     *	Unescape the address and ccaddr fields. - FM
     */
    SafeHTUnEscape(address);
    if (ccaddr != NULL) {
	SafeHTUnEscape(ccaddr);
    }

    /*
     *	Allow user to edit the default Subject - FM
     */
    if (isEmpty(subject)) {
	if (!isEmpty(mailto_subject)) {
	    LYstrncpy(subject, mailto_subject, MAX_SUBJECT);
	} else {
	    sprintf(subject, "mailto:%.63s", address);
	}
    }
    _statusline(SUBJECT_PROMPT);
    if ((ch = LYgetstr(subject, VISIBLE, MAX_SUBJECT, NORECALL)) < 0) {
	/*
	 * User cancelled via ^G. - FM
	 */
	HTInfoMsg(FORM_MAILTO_CANCELLED);
	goto cleanup;
    }

    /*
     *	Allow user to specify a self copy via a CC:
     *	entry, if permitted. - FM
     */
    if (!LYNoCc) {
	sprintf(self, "%.*s", MAX_SUBJECT,
		isEmpty(personal_mail_address) ? "" : personal_mail_address);
	_statusline("Cc: ");
	if ((ch = LYgetstr(self, VISIBLE, MAX_SUBJECT, NORECALL)) < 0) {
	    /*
	     * User cancelled via ^G. - FM
	     */
	    HTInfoMsg(FORM_MAILTO_CANCELLED);
	    goto cleanup;
	}
	remove_tildes(self);
	if (ccaddr == NULL) {
	    StrAllocCopy(ccaddr, self);
	} else {
	    StrAllocCat(ccaddr, ",");
	    StrAllocCat(ccaddr, self);
	}
    }

#if CAN_PIPE_TO_MAILER
    if ((fd = LYPipeToMailer()) == 0) {
	HTAlert(FORM_MAILTO_FAILED);
	goto cleanup;
    }

    if (!isEmpty(mailto_type)) {
	fprintf(fd, "Mime-Version: 1.0\n");
	fprintf(fd, "Content-Type: %s\n", mailto_type);
    }
    fprintf(fd, "To: %s\n", address);
    if (!isEmpty(personal_mail_address))
	fprintf(fd, "From: %s\n", personal_mail_address);
    if (!isEmpty(ccaddr))
	fprintf(fd, "Cc: %s\n", ccaddr);
    fprintf(fd, "Subject: %s\n\n", subject);
    if (!isEmpty(keywords))
	fprintf(fd, "Keywords: %s\n", keywords);
    _statusline(SENDING_FORM_CONTENT);
#else	/* e.g., VMS, DOS */
    if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) {
	HTAlert(FORM_MAILTO_FAILED);
	goto cleanup;
    }
#if USE_VMS_MAILER
    if (isPMDF) {
	FILE *hfd;
	if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) {
	    HTAlert(FORM_MAILTO_FAILED);
	    LYCloseTempFP(fd);
	    goto cleanup;
	}
	if (!isEmpty(mailto_type)) {
	    fprintf(hfd, "Mime-Version: 1.0\n");
	    fprintf(hfd, "Content-Type: %s\n", mailto_type);
	    if (!isEmpty(personal_mail_address))
		fprintf(hfd, "From: %s\n", personal_mail_address);
	}
	/*
	 *  For PMDF, put any keywords and the subject
	 *  in the header file and close it. - FM
	 */
	if (!isEmpty(keywords)) {
	    fprintf(hfd, "Keywords: %s\n", keywords);
	}
	fprintf(hfd, "Subject: %s\n\n", subject);
	LYCloseTempFP(hfd);
    } else if (mailto_type &&
	       !strncasecomp(mailto_type, "multipart/form-data", 19)) {
	/*
	 *  Ugh!  There's no good way to include headers while
	 *  we're still using "generic" VMS MAIL, so we'll put
	 *  this in the body of the message. - FM
	 */
	fprintf(fd, "X-Content-Type: %s\n\n", mailto_type);
    }
#else	/* !VMS (DOS) */
#if USE_BLAT_MAILER
    if (mail_is_blat) {
	if (strlen(subject) > MAX_SUBJECT)
	    subject[MAX_SUBJECT] = '\0';
    } else
#endif
    {
	if (!isEmpty(mailto_type)) {
	    fprintf(fd, "Mime-Version: 1.0\n");
	    fprintf(fd, "Content-Type: %s\n", mailto_type);
	}
	fprintf(fd,"To: %s\n", address);
	if (!isEmpty(personal_mail_address))
	    fprintf(fd,"From: %s\n", personal_mail_address);
	fprintf(fd,"Subject: %.70s\n\n", subject);
    }
#endif /* VMS */
#endif /* CAN_PIPE_TO_MAILER */

    /*
     *	Break up the content into lines with a maximum length of 78.
     *	If the ENCTYPE was text/plain, we have physical newlines and
     *	should take them into account.	Otherwise, the actual newline
     *	characters in the content are hex escaped. - FM
     */
    while((cp = strchr(mailto_content, '\n')) != NULL) {
	*cp = '\0';
	i = 0;
	len = strlen(mailto_content);
	while (len > 78) {
	    strncpy(buf, &mailto_content[i], 78);
	    buf[78] = '\0';
	    fprintf(fd, "%s\n", buf);
	    i += 78;
	    len = strlen(&mailto_content[i]);
	}
	fprintf(fd, "%s\n", &mailto_content[i]);
	mailto_content = (cp+1);
    }
    i = 0;
    len = strlen(mailto_content);
    while (len > 78) {
	strncpy(buf, &mailto_content[i], 78);
	buf[78] = '\0';
	fprintf(fd, "%s\n", buf);
	i += 78;
	len = strlen(&mailto_content[i]);
    }
    if (len)
	fprintf(fd, "%s\n", &mailto_content[i]);

#if CAN_PIPE_TO_MAILER
    pclose(fd);
    LYSleepMsg();
#else
    LYCloseTempFP(fd);
#if USE_VMS_MAILER
    /*
     *	Set the mail command. - FM
     */
    if (isPMDF) {
	/*
	 *  Now set up the command. - FM
	 */
	HTSprintf0(&cmd,
		"%s %s %s,%s ",
		system_mail,
		system_mail_flags,
		hdrfile,
		my_tmpfile);
    } else {
	/*
	 *  For "generic" VMS MAIL, include the subject in the
	 *  command, and ignore any keywords to minimize risk
	 *  of them making the line too long or having problem
	 *  characters. - FM
	 */
	HTSprintf0(&cmd,
		"%s %s%s/subject=\"%s\" %s ",
		system_mail,
		system_mail_flags,
		(strncasecomp(system_mail, "MAIL", 4) ? "" : "/noself"),
		subject,
		my_tmpfile);
    }
    StrAllocCopy(command, cmd);

    vms_append_addrs(&command, address, "");
    if (!isEmpty(ccaddr)) {
	vms_append_addrs(&command, ccaddr, "/CC");
    }

    stop_curses();
    printf("%s\n\n$ %s\n\n%s", SENDING_FORM_CONTENT, command, PLEASE_WAIT);
    LYSystem(command);	/* Mail (VMS) */
    FREE(command);
    LYSleepAlert();
    start_curses();
    LYRemoveTemp(my_tmpfile);
    if (isPMDF)
	LYRemoveTemp(hdrfile);
#else /* DOS */
    LYSendMailFile (
	address,
	my_tmpfile,
	subject,
	ccaddr,
	SENDING_FORM_CONTENT);
    LYRemoveTemp(my_tmpfile);
#endif /* USE_VMS_MAILER */
#endif /* CAN_PIPE_TO_MAILER */

cleanup:
    FREE(address);
    FREE(ccaddr);
    FREE(keywords);
    return;
}
Exemple #17
0
/**
 * Process a COM_BINLOG_DUMP message from the slave. This is the
 * final step in the process of registration. The new master, MaxScale
 * must send a response packet and generate a fake BINLOG_ROTATE event
 * with the binlog file requested by the slave. And then send a
 * FORMAT_DESCRIPTION_EVENT that has been saved from the real master.
 *
 * Once send MaxScale must continue to send binlog events to the slave.
 *
 * @param	router		The router instance
 * @param	slave		The slave server
 * @param	queue		The BINLOG_DUMP packet
 * @return			The number of bytes written to the slave
 */
static int
blr_slave_binlog_dump(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
{
GWBUF		*resp;
uint8_t		*ptr;
int		len, flags, serverid, rval, binlognamelen;
REP_HEADER	hdr;
uint32_t	chksum;

	ptr = GWBUF_DATA(queue);
	len = extract_field(ptr, 24);
	binlognamelen = len - 11;
	ptr += 4;		// Skip length and sequence number
	if (*ptr++ != COM_BINLOG_DUMP)
	{
        	LOGIF(LE, (skygw_log_write(
			LOGFILE_ERROR,
			"blr_slave_binlog_dump expected a COM_BINLOG_DUMP but received %d",
			*(ptr-1))));
		return 0;
	}

	slave->binlog_pos = extract_field(ptr, 32);
	ptr += 4;
	flags = extract_field(ptr, 16);
	ptr += 2;
	serverid = extract_field(ptr, 32);
	ptr += 4;
	strncpy(slave->binlogfile, (char *)ptr, binlognamelen);
	slave->binlogfile[binlognamelen] = 0;

	slave->seqno = 1;


	if (slave->nocrc)
		len = 19 + 8 + binlognamelen;
	else
		len = 19 + 8 + 4 + binlognamelen;

	// Build a fake rotate event
	resp = gwbuf_alloc(len + 5);
	hdr.payload_len = len + 1;
	hdr.seqno = slave->seqno++;
	hdr.ok = 0;
	hdr.timestamp = 0L;
	hdr.event_type = ROTATE_EVENT;
	hdr.serverid = router->masterid;
	hdr.event_size = len;
	hdr.next_pos = 0;
	hdr.flags = 0x20;
	ptr = blr_build_header(resp, &hdr);
	encode_value(ptr, slave->binlog_pos, 64);
	ptr += 8;
	memcpy(ptr, slave->binlogfile, binlognamelen);
	ptr += binlognamelen;

	if (!slave->nocrc)
	{
		/*
		 * Now add the CRC to the fake binlog rotate event.
		 *
		 * The algorithm is first to compute the checksum of an empty buffer
		 * and then the checksum of the event portion of the message, ie we do not
		 * include the length, sequence number and ok byte that makes up the first
		 * 5 bytes of the message. We also do not include the 4 byte checksum itself.
		 */
		chksum = crc32(0L, NULL, 0);
		chksum = crc32(chksum, GWBUF_DATA(resp) + 5, hdr.event_size - 4);
		encode_value(ptr, chksum, 32);
	}

	rval = slave->dcb->func.write(slave->dcb, resp);

	/* Send the FORMAT_DESCRIPTION_EVENT */
	if (slave->binlog_pos != 4)
		blr_slave_send_fde(router, slave);

	slave->dcb->low_water  = router->low_water;
	slave->dcb->high_water = router->high_water;
	dcb_add_callback(slave->dcb, DCB_REASON_DRAINED, blr_slave_callback, slave);
	slave->state = BLRS_DUMPING;

	LOGIF(LM, (skygw_log_write(
		LOGFILE_MESSAGE,
			"%s: New slave %s, server id %d,  requested binlog file %s from position %lu",
				router->service->name, slave->dcb->remote,
					slave->serverid,
					slave->binlogfile, slave->binlog_pos)));

	if (slave->binlog_pos != router->binlog_position ||
			strcmp(slave->binlogfile, router->binlog_name) != 0)
	{
		spinlock_acquire(&slave->catch_lock);
		slave->cstate &= ~CS_UPTODATE;
		slave->cstate |= CS_EXPECTCB;
		spinlock_release(&slave->catch_lock);
		poll_fake_write_event(slave->dcb);
	}
	return rval;
}
static int update_range_export(int marker,
                               const char **name,
                               const char **description,
                               const char  *keys[ED_MARKER_MAX_ATTRS],
                               char        *values[ED_MARKER_MAX_ATTRS],
                               int         *count) {

   char field[255];
   const char *note = editor_marker_note (marker);
   *count = 0;
   *description = NULL;
   *name = NULL;

   if (extract_field (note, STREET_PREFIX, field, sizeof(field)) == -1) {
      roadmap_log (ROADMAP_ERROR, "Update range - Can't find street name.");
      return -1;
   } else {
      keys[*count] = "street";
      values[*count] = strdup(field);
      (*count)++;
   }

   if (extract_field (note, CITY_PREFIX, field, sizeof(field)) == -1) {
      roadmap_log (ROADMAP_ERROR, "Update range - Can't find city name.");
      return -1;
   } else {
      keys[*count] = "city";
      values[*count] = strdup(field);
      (*count)++;
   }

   if (extract_field (note, UPDATE_LEFT, field, sizeof(field)) != -1) {
      if (atoi(field) <= 0) {
         roadmap_log (ROADMAP_ERROR, "Update range - Left range is invalid.");
         return -1;
      } else {
         keys[*count] = "left";
         values[*count] = strdup(field);
         (*count)++;
      }
   }

   if (extract_field (note, UPDATE_RIGHT, field, sizeof(field)) != -1) {
      if (atoi(field) <= 0) {
         roadmap_log (ROADMAP_ERROR, "Update range - Right range is invalid.");
         return -1;
      } else {
         keys[*count] = "right";
         values[*count] = strdup(field);
         (*count)++;
      }
   }

   if (*count < 2) {
      roadmap_log (ROADMAP_ERROR,
                     "Update range - No range updates were found.");
      return -1;
   }

   return 0;
}
Exemple #19
0
/**
 * Handle a query from the slave. This is expected to be one of the "standard"
 * queries we expect as part of the registraton process. Most of these can
 * be dealt with by replying the stored responses we got from the master
 * when MaxScale registered as a slave. The exception to the rule is the
 * request to obtain the current timestamp value of the server.
 *
 * Seven select statements are currently supported:
 *	SELECT UNIX_TIMESTAMP();
 *	SELECT @master_binlog_checksum
 *	SELECT @@GLOBAL.GTID_MODE
 *	SELECT VERSION()
 *	SELECT 1
 *	SELECT @@version_comment limit 1
 *	SELECT @@hostname
 *
 * Two show commands are supported:
 *	SHOW VARIABLES LIKE 'SERVER_ID'
 *	SHOW VARIABLES LIKE 'SERVER_UUID'
 *
 * Five set commands are supported:
 *	SET @master_binlog_checksum = @@global.binlog_checksum
 *	SET @master_heartbeat_period=...
 *	SET @slave_slave_uuid=...
 *	SET NAMES latin1
 *	SET NAMES utf8
 *
 * @param router        The router instance this defines the master for this replication chain
 * @param slave         The slave specific data
 * @param queue         The incoming request packet
 * @return		Non-zero if data has been sent
 */
static int
blr_slave_query(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, GWBUF *queue)
{
char	*qtext, *query_text;
char	*sep = " 	,=";
char	*word, *brkb;
int	query_len;

	qtext = GWBUF_DATA(queue);
	query_len = extract_field((uint8_t *)qtext, 24) - 1;
	qtext += 5;		// Skip header and first byte of the payload
	query_text = strndup(qtext, query_len);

	LOGIF(LT, (skygw_log_write(
		LOGFILE_TRACE, "Execute statement from the slave '%s'", query_text)));
	/*
	 * Implement a very rudimental "parsing" of the query text by extarcting the
	 * words from the statement and matchng them against the subset of queries we
	 * are expecting from the slave. We already have responses to these commands,
	 * except for the select of UNIX_TIMESTAMP(), that we have saved from MaxScale's
	 * own interaction with the real master. We simply replay these saved responses
	 * to the slave.
	 */
	word = strtok_r(query_text, sep, &brkb);
	if (strcasecmp(word, "SELECT") == 0)
	{
		word = strtok_r(NULL, sep, &brkb);
		if (strcasecmp(word, "UNIX_TIMESTAMP()") == 0)
		{
			free(query_text);
			return blr_slave_send_timestamp(router, slave);
		}
		else if (strcasecmp(word, "@master_binlog_checksum") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.chksum2);
		}
		else if (strcasecmp(word, "@@GLOBAL.GTID_MODE") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.gtid_mode);
		}
		else if (strcasecmp(word, "1") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.select1);
		}
		else if (strcasecmp(word, "VERSION()") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.selectver);
		}
		else if (strcasecmp(word, "@@version_comment") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.selectvercom);
		}
		else if (strcasecmp(word, "@@hostname") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.selecthostname);
		}
	}
	else if (strcasecmp(word, "SHOW") == 0)
	{
		word = strtok_r(NULL, sep, &brkb);
		if (strcasecmp(word, "VARIABLES") == 0)
		{
			word = strtok_r(NULL, sep, &brkb);
			if (strcasecmp(word, "LIKE") == 0)
			{
				word = strtok_r(NULL, sep, &brkb);
				if (strcasecmp(word, "'SERVER_ID'") == 0)
				{
					free(query_text);
					return blr_slave_replay(router, slave, router->saved_master.server_id);
				}
				else if (strcasecmp(word, "'SERVER_UUID'") == 0)
				{
					free(query_text);
					return blr_slave_replay(router, slave, router->saved_master.uuid);
				}
			}
		}
	}
	else if (strcasecmp(query_text, "SET") == 0)
	{
		word = strtok_r(NULL, sep, &brkb);
		if (strcasecmp(word, "@master_heartbeat_period") == 0)
		{
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.heartbeat);
		}
		else if (strcasecmp(word, "@master_binlog_checksum") == 0)
		{
			word = strtok_r(NULL, sep, &brkb);
			if (strcasecmp(word, "'none'") == 0)
				slave->nocrc = 1;
			else
				slave->nocrc = 0;
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.chksum1);
		}
		else if (strcasecmp(word, "@slave_uuid") == 0)
		{
			if ((word = strtok_r(NULL, sep, &brkb)) != NULL)
				slave->uuid = strdup(word);
			free(query_text);
			return blr_slave_replay(router, slave, router->saved_master.setslaveuuid);
		}
		else if (strcasecmp(word, "NAMES") == 0)
		{
			word = strtok_r(NULL, sep, &brkb);
			if (strcasecmp(word, "latin1") == 0)
			{
				free(query_text);
				return blr_slave_replay(router, slave, router->saved_master.setnames);
			}
			else if (strcasecmp(word, "utf8") == 0)
			{
				free(query_text);
				return blr_slave_replay(router, slave, router->saved_master.utf8);
			}
		}
	}
	free(query_text);

	query_text = strndup(qtext, query_len);
	LOGIF(LE, (skygw_log_write(
		LOGFILE_ERROR, "Unexpected query from slave server %s", query_text)));
	free(query_text);
	blr_slave_send_error(router, slave, "Unexpected SQL query received from slave.");
	return 0;
}
Exemple #20
0
Message::PARSER_RESULT Message::parse_header(char* line)
{
	char* field[2];

	if(!extract_field(line, field))
	{
		return LINE_MALFORMED;
	}

	/*The content length line gets special treatment because it gives the
	 * size of the body, for the rest of the fields, we should proceed normally
	 * and store them in their structure.*/
	//If the header line is "content-length".
	if(!body && !strcmp(field[0], "content-length"))
	{
		// Get the content length by converting from its textual representation.
		size_t content_length = atoi(field[1]);

		// Create a buffer to hold the body.
		char* buffer = (char*)malloc(content_length);

		if(!buffer) // If there is no memory left.
		{
			return OUT_OF_MEMORY;
		}

		/*Create a body object the size of content_length. Set its memory
		 * pointer to NULL because we will be giving a memory area later
		 * when the body is actually received.*/
		body = new MemFile(buffer, content_length, false);

		if(!body) // If creating the body failed.
		{
			free(buffer);
			return OUT_OF_MEMORY; // Return the appropriate error.
		}
	}
	/* If the from-url is present, this means the message comes from another
	 * resource.*/
	else if(!strcmp(field[0], "from-url"))
	{
		if(!from_url)
		{
			from_url = new URL();

			if(!from_url) // If no memory could be allocated.
			{
				return OUT_OF_MEMORY;
			}
		}

		if(from_url->parse(field[1]) != URL::VALID)
		{
			// Do not delete the allocated url string, it is now owned by the URL.
			return LINE_MALFORMED;
		}
	}
	/* If the To-Url is present, this means the message comes from another
	 * resource.*/
	else if(!strcmp(field[0], "to-url"))
	{
		if(!to_url)
		{
			to_url = new URL();

			if(!to_url) // If no memory could be allocated.
			{
				return OUT_OF_MEMORY;
			}
		}

		if(to_url->parse(field[1]) != URL::VALID)
		{
			// Do not delete the allocated url string, it is now owned by the URL.
			return LINE_MALFORMED;
		}
	}
	else
	{
		// Store fields.
		add_field(field[0], field[1]);
	}

	return PARSING_SUCESSFUL; // Parsing that line was successful.
}
Exemple #21
0
/************************************************************************
** Function: ProcessUsgDetail
**
** Purpose: Read a  detail usage record from usage file.
**
** returns:	SUCCESS - no errors, or "soft" (minor) error.  SUCCESS
**		          means that the record will be saved in either
**		          CDR_DATA or CDR_DATA_WORK.
**		FAILURE - serious parsing error. return FAILURE implies
**		          "hard" error.  Such records will be written to
**		          the bad image file.
**		          Note that records with hard errors will be
**		          written to bad image file as is.  This means
**		          error codes are NOT saved.  This is why we
**		          return immediately for FAILURE case.
**
** General idea is that missing data will be considered a "soft" error
** where as non-numeric data in a numeric field will be considered a
** hard error.
*************************************************************************
*/
int ProcessUsgDetail(CDR_DATA_STRUCT *cdr_data,
        RECORD_TYPE_STRUCT *rec_type,
        int  minimize,
        int  *checksum1,
        int  *checksum2,
        int  *checksum3)
{
   char *ptr;
   char tmpstr[1024];
   char gstrScratch1[1024];
   int  pos;	/* floating pointer into cdr_data->usg_rec */

   /* for time field, we need to convert to the usage time zone if
   ** it is provided. But sometime we do not have timezone in usage
   ** file, in this case we will convert to default timezone?
   ** To convert time, we need to wait after the whole usage record
   ** has been processed, then do conversion if necessary
   */

   short trans_dt_type = -1; /* -1 means not supplied in usg file,no op */
   short second_dt_type = -1;/* -1 means not supplied in usg file,no op */
   short rate_dt_type = -1;  /* -1 means not supplied in usg file,no op */
   short new_timezone = FALSE; /* to indicate whether there is a timezone
                               ** in the usage record 
                               */
   char usage_tz[szUnixTZ+1+3];
   char unix_tz[szUnixTZ+1];
   short size;     /* size of input field */
   tiny isdst;     /* ignored */

   int  i;
   int  j;

   pos = 0;
   ptr = gstrScratch1;

   if(mpsIsLogLevelHigh())
   {
      sprintf(tmpstr, "\nProcessing Record Type \'%s\'",
         rec_type->record_type);
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
      sprintf(tmpstr, "===================================");
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
      sprintf(tmpstr, "%-20.20s   %-20.20s   %-12.12s %-5.5s %-15.12s",
         "Field Name From", "Field Name To","Field Type", "Size","Field Value");
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
      sprintf(tmpstr,
         "===============        ===============        ============ ===== ===========");
      emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
   }

   for(i = rec_type->from_pos; i <= rec_type->to_pos; i++)
   {
      size = gsField_Mapping[i].field_from_size;
      /* Skip over some fields if in minimize / non-debug mode */
      if ( minimize && !mpsIsLogLevelHigh() )
      {
         switch(gsField_Mapping[i].field_to_id)
         {
         case to_type_id_usg:
         case to_point_origin:
         case to_point_target:
         case to_trans_dt:
         case to_timezone:
         case to_external_id:
         case to_external_id_type:
         case to_home_carrier_sid_bid:
         case to_num_tax_details:
            break;

         default:
            pos += size;
            continue;
         }
      }

      switch(gsField_Mapping[i].field_from_type)
      {
      case binary:
         j = ParseHex((char *)cdr_data->usg_rec+pos, (int) size);
         pos += size;
         if(mpsIsLogLevelHigh())
         {
            sprintf(tmpstr, 
               "%-20.20s   %-20.20s   %-12.12s %-6d%-12d",
               gsField_Mapping[i].field_from_name,
               gsField_Mapping[i].field_to_name,
               "(binary)",
               size,
               j);
            emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
         }
         break;
      default:
         if((gsField_Mapping[i].field_to_id == to_annotation)   ||
            (gsField_Mapping[i].field_to_id == to_customer_tag) ||
            (gsField_Mapping[i].field_to_id == to_roaming_detail))
         {
            extract_field_no_strip(&ptr, (char *)cdr_data->usg_rec, &pos, (int) size);
         } else {
            extract_field(&ptr, (char *)cdr_data->usg_rec, &pos, (int) size);
         }
         if(mpsIsLogLevelHigh())
         {
            sprintf(tmpstr, 
               "%-20.20s   %-20.20s   %-12.12s %-6d%-s",
               gsField_Mapping[i].field_from_name,
               gsField_Mapping[i].field_to_name,
               "(a/n str)",
               size,
               ptr);
            emit(ERRLOC,MPS_GENERIC_INFORM,tmpstr);
         }
         break;
      } 
      if(gsField_Mapping[i].is_ignored)
      {
         continue;
      }
      if(gsField_Mapping[i].is_required && ptr[0] == '\0' &&
         gsField_Mapping[i].field_from_type != binary)
      {
         emit(ERRLOC,CAP_FIELD_MISSING_X,gsField_Mapping[i].field_from_name);
         set_cdr_error_code(cdr_data, CAP_FIELD_MISSING); 
         sprintf(tmpstr, "%d,Field: \"%s\"",
            CAP_FIELD_MISSING,gsField_Mapping[i].field_to_name);

         emit(ERRLOC,MPS_GEN_ERROR,tmpstr );
         set_mps_error_struct(tmpstr,""); 
      }

      /* if we need to convert from string to a numeric field *
      ** we need to check no digital char and overflow        */
      if(gsField_Mapping[i].field_to_type != to_string)
      {
         if(gsField_Mapping[i].field_from_type != binary)
         {
            if(numeric_string(ptr))
            {
               if(gsField_Mapping[i].field_to_type == to_numeric)
               {
               }
               else
               {
                  if(convert_to_number(ptr,&j, 
                     (short) gsField_Mapping[i].field_to_type) == FAILURE)
                  {
                     /* conversion caused overflow */
                     j = 0;
                     set_cdr_error_code(cdr_data, CAP_VALUE_OVERFLOW);
                     sprintf(tmpstr,
                        "%d,convert \"%s\" to \"%s\" caused overflow",
                        CAP_VALUE_OVERFLOW,
                        ptr,
                        gsField_Mapping[i].field_to_name);
                     set_mps_error_struct(tmpstr,"");
                  }
               }
            }
            else
            {
               /* some non-numeric characters for numeric field */
               j = 0;
               set_cdr_error_code(cdr_data, CAP_BAD_NUM_FIELD);
               sprintf(tmpstr,
                  "%d,Field value: \"%s\"",
                  CAP_BAD_NUM_FIELD,
                  ptr);
               emit(ERRLOC,CAP_BAD_NUM_FIELD );
               sprintf(tmpstr, "%-20.20s: \"%s\"",
                  gsField_Mapping[i].field_from_name,gstrScratch1);
               emit(ERRLOC,MPS_GEN_ERROR,tmpstr );
               set_mps_error_struct(tmpstr,""); 
            }
         }
         else
         {
            /* when we get a binary field, we need to check overflow
            ** since we may get the int and try to convert to a tiny */
            if(check_overflow(j, (short) gsField_Mapping[i].field_to_type) == FAILURE)
            {
               j = 0;
               /* conversion caused overflow */
               set_cdr_error_code(cdr_data, CAP_VALUE_OVERFLOW);
               sprintf(tmpstr,
                  "%d,convert %d to \"%s\" caused overflow",
                  CAP_VALUE_OVERFLOW,
                  j,
                  gsField_Mapping[i].field_to_name);
               emit(ERRLOC,MPS_GEN_ERROR,tmpstr );
               set_mps_error_struct(tmpstr,"");
            }
         } 
      } 

      switch(gsField_Mapping[i].field_to_id)
      {
      case to_ext_tracking_id:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->ext_tracking_id, ptr, szExtTrackingId);
            cdr_data->ext_tracking_id[szExtTrackingId] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->ext_tracking_id, tmpstr,szExtTrackingId);
            cdr_data->ext_tracking_id[szExtTrackingId] = '\0';
         }
         break;
      case to_trans_id:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->trans_id, ptr, szTransID);
            cdr_data->trans_id[szTransID] = '\0';
         }
         else
         {
            sprintf(cdr_data->trans_id,"%d",j);
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->trans_id, tmpstr, szTransID);
            cdr_data->trans_id[szTransID] = '\0';
         }
         break;
      case to_element_id:
         cdr_data->element_id = j;
         break;
      case to_type_id_usg:
         cdr_data->type_id_usg = j;
         cdr_data->orig_type_id_usg = j;
         break;
      case to_rate_class:
         cdr_data->rate_class = j;
         break;
      case to_bill_class:
         cdr_data->bill_class = j;
         break;
      case to_num_tax_details:
         cdr_data->num_tax_details = j;
         break;
      case to_provider_id:
         cdr_data->provider_id = j;
         break;
      case to_provider_class:
         cdr_data->provider_class = j;
         break;
      case to_jurisdiction:
         cdr_data->jurisdiction = j;
         break;
      case to_rate_currency_code:
         cdr_data->rate_currency_code = j;
         break;
      case to_emf_create_date:
         break;
      case to_point_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_origin, ptr, szUsagePoint);
            cdr_data->point_origin[szUsagePoint] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_origin, tmpstr, szUsagePoint);
            cdr_data->point_origin[szUsagePoint] = '\0';
         }
         break;
      case to_country_dial_code_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->country_dial_code_origin, ptr, 
               szDialCode);
            cdr_data->country_dial_code_origin[szDialCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->country_dial_code_origin, tmpstr, szDialCode);
            cdr_data->country_dial_code_origin[szDialCode] = '\0';
         }
         break;
      case to_point_tax_code_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_tax_code_origin, ptr, szTaxCode);
            cdr_data->point_tax_code_origin[szTaxCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_tax_code_origin, tmpstr, szTaxCode);
            cdr_data->point_tax_code_origin[szTaxCode] = '\0';
         }
         break;
      case to_point_tax_code_type_origin:
         cdr_data->point_tax_code_type_origin = j;
         break;
      case to_point_target:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_target, ptr, szUsagePoint);
            cdr_data->point_target[szUsagePoint] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_target, tmpstr, szUsagePoint);
            cdr_data->point_target[szUsagePoint] = '\0';
         }
         break;
      case to_point_tax_code_target:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->point_tax_code_target, ptr, szTaxCode);
            cdr_data->point_tax_code_target[szTaxCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->point_tax_code_target, tmpstr, szTaxCode);
            cdr_data->point_tax_code_target[szTaxCode] = '\0';
         }
         break;
      case to_point_tax_code_type_target:
         cdr_data->point_tax_code_type_target = j;
         break;
      case to_trans_dt:
         /* if time comes in as unix time save it in the trans_time field
         ** and do conversion later by using a timezone 
         */
         if(gsField_Mapping[i].field_to_type == to_int)
            cdr_data->trans_time = j;
         else
         {
            /* if time comes in as char string save the string and convert
            ** to YYYYMMDD HH:MM:SS according the input format
            */
            if(convert_date_string(cdr_data->trans_dt, gstrScratch1,
               gsField_Mapping[i].date_format_type) == FAILURE)
            {
               emit(ERRLOC, MPS_BAD_FIELD, "trans_dt", cdr_data->trans_dt);
               set_cdr_error_code(cdr_data, CAP_BAD_PRIMTIME);
               sprintf(tmpstr,
                  "%d,%s: \"%s\"",
                  CAP_BAD_PRIMTIME,gsField_Mapping[i].field_to_name,
                  cdr_data->trans_dt);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               break;
            }
         }
         trans_dt_type = gsField_Mapping[i].field_to_type;
         break;
      case to_second_dt:
         /* if time comes in as unix time save it in the trans_time field
         ** and do conversion later by using a timezone 
         */
         if(gsField_Mapping[i].field_to_type == to_int)
            cdr_data->second_time = j;
         else
         {
            /* if time comes in as char string save the string and convert
            ** to YYYYMMDD HH:MM:SS according the input format later 
            */
            if(convert_date_string(cdr_data->second_dt, gstrScratch1,
               gsField_Mapping[i].date_format_type) == FAILURE)
            {
               emit(ERRLOC, MPS_BAD_FIELD,"second_dt",cdr_data->second_dt);
               set_cdr_error_code(cdr_data, CAP_BAD_SECONDTIME);
               sprintf(tmpstr,
                  "%d,%s: \"%s\"",
                  CAP_BAD_SECONDTIME,
                  gsField_Mapping[i].field_to_name,
                  cdr_data->second_dt);

               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               break;
            }
         }
         second_dt_type = gsField_Mapping[i].field_to_type;
         break;
      case to_timezone:
         cdr_data->timezone = j;
         new_timezone = TRUE;
         break;
      case to_primary_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->primary_units), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->primary_units), ptr);
            if ( arb_numeric_to_int( &(cdr_data->primary_units), &j) == FAILURE)
            {
               j = cdr_data->primary_units.low;
            }
         }
         *checksum1 += j;
         break;
      case to_primary_type:
         cdr_data->primary_type = j;
         break;
      case to_second_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->second_units), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->second_units), ptr);
            if ( arb_numeric_to_int( &(cdr_data->second_units), &j) == FAILURE)
            {
               j = cdr_data->second_units.low;
            }
         }
         *checksum2 += j;
         break;
      case to_second_type:
         cdr_data->second_type = j;
         break;
      case to_third_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->third_units), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->third_units), ptr);
            if ( arb_numeric_to_int( &(cdr_data->third_units), &j) == FAILURE)
            {
               j = cdr_data->third_units.low;
            }
         }
         *checksum3 += j;
         break;
      case to_third_type:
         cdr_data->third_type = j;
         break;
      case to_federal_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->federal_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->federal_tax), ptr);
         }
         break;
      case to_state_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->state_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->state_tax), ptr);
         }
         break;
      case to_county_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->county_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->county_tax), ptr);
         }
         break;
      case to_city_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->city_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->city_tax), ptr);
         }
         break;
      case to_other_tax:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->other_tax), j);
         }
         else
         {
            arb_numeric_from_string(&(cdr_data->other_tax), ptr);
         }
         break;
      case to_units_currency_code:
         cdr_data->units_currency_code = j;
         break;
      case to_annotation:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->annotation, ptr, size);
            cdr_data->annotation[size] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->annotation, tmpstr, size);
            cdr_data->annotation[size] = '\0';
         }
         break;
      case to_customer_tag:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->customer_tag, ptr, szCustomerTag);
            cdr_data->customer_tag[szCustomerTag] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->customer_tag, tmpstr, szCustomerTag);
            cdr_data->customer_tag[szCustomerTag] = '\0';
         }
         break;
      case to_geocode:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->geocode, ptr, szTaxCode);
            cdr_data->geocode[szTaxCode] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->geocode, tmpstr, szTaxCode);
            cdr_data->geocode[szTaxCode] = '\0';
         }
         break;
      case to_roaming_detail:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->roaming_detail, ptr, size);
            cdr_data->roaming_detail[size] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->roaming_detail, tmpstr, size);
            cdr_data->roaming_detail[size] = '\0';
         }
         break;	    
      case to_rated_units:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->rated_units), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->rated_units), ptr);
         break;
      case to_total_amt:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->total_amt), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->total_amt), ptr);
         break;
      case to_base_amt:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->base_amt), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->base_amt), ptr);

         break;
      case to_unrounded_amount:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->unrounded_amount), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->unrounded_amount), ptr);
         break;
      case to_foreign_amount:
         if(gsField_Mapping[i].field_from_type == binary)
         {
            arb_numeric_from_int(&(cdr_data->foreign_amount), j);
         }
         else
            arb_numeric_from_string(&(cdr_data->foreign_amount), ptr);
         break;
      case to_rate_period:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->rate_period, ptr, szRatePeriod);
            cdr_data->rate_period[szRatePeriod] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->rate_period, tmpstr, szRatePeriod);
            cdr_data->rate_period[szRatePeriod] = '\0';
         }
         break;
      case to_rate_dt:
         /* if time comes in as unix time save it in the trans_time field
         ** and do conversion later by using a timezone 
         */
         if(gsField_Mapping[i].field_to_type == to_int)
            cdr_data->rate_time = j;
         else
         {
            if(convert_date_string(cdr_data->rate_dt, gstrScratch1,
               gsField_Mapping[i].date_format_type) == FAILURE)
            { 
               emit(ERRLOC, MPS_BAD_FIELD,"rate_dt",cdr_data->rate_dt);
               set_cdr_error_code(cdr_data, CAP_BAD_RATETIME);
               sprintf(tmpstr,
                  "%d,%s: \"%s\"",
                  CAP_BAD_RATETIME,
                  gsField_Mapping[i].field_to_name,
                  cdr_data->rate_dt);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               break;
            }
         }
         rate_dt_type = gsField_Mapping[i].field_to_type;
         break;
      case to_no_bill:
         cdr_data->no_bill = j;
         break;
      case to_comp_status:
         cdr_data->comp_status = j;
         break;
      case to_cdr_status:
         cdr_data->cdr_status = j;
         break;
      case to_external_id:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->external_id, ptr, size);
            cdr_data->external_id[size] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->external_id, tmpstr, size);
            cdr_data->external_id[size] = '\0';
         }
         break;
      case to_external_id_type:
         cdr_data->external_id_type = j;
         break;
      case to_account_no:
         cdr_data->account_no = j;
         break;
      case to_kp_subscr_no:
         cdr_data->kp_subscr_no = j;
         break;
      case to_kp_subscr_no_resets:
         cdr_data->kp_subscr_no_resets = j;
         break;
      case to_kp_server_id:
         cdr_data->kp_server_id = j;
         break;
      case to_ccard_account:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_account, ptr, szCCardAcct);
            cdr_data->miu_ccard_account[szCCardAcct] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_account, tmpstr, szCCardAcct);
            cdr_data->miu_ccard_account[szCCardAcct] = '\0';
         }
         break;
      case to_ccard_carrier_code:
         cdr_data->miu_ccard_carrier_code = j;
         break;
      case to_ccard_ownr_fname:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_ownr_fname, ptr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_fname[szCCardOwnr] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_ownr_fname, tmpstr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_fname[szCCardOwnr] = '\0';
         }
         break;
      case to_ccard_ownr_lname:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_ownr_lname, ptr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_lname[szCCardOwnr] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_ownr_lname, tmpstr, szCCardOwnr);
            cdr_data->miu_ccard_ownr_lname[szCCardOwnr] = '\0';
         }
         break;
      case to_ccard_expire:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_expire, ptr, szCCardExpire);
            cdr_data->miu_ccard_expire[szCCardExpire] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_expire, tmpstr, szCCardExpire);
            cdr_data->miu_ccard_expire[szCCardExpire] = '\0';
         }
         break;
      case to_ccard_carrier:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->miu_ccard_carrier, ptr, szCCCarrier);
            cdr_data->miu_ccard_carrier[szCCCarrier] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->miu_ccard_carrier, tmpstr, szCCCarrier);
            cdr_data->miu_ccard_carrier[szCCCarrier] = '\0';
         }
         break;
      case to_free_flag:
         cdr_data->free_flag = j;
         break;
      case to_home_carrier_sid_bid:
         cdr_data->home_carrier_sid_bid = j;
         break;
      case to_open_item_id:
         cdr_data->open_item_id = j;
         break;
      case to_cell_name_origin:
         if(gsField_Mapping[i].field_from_type != binary)
         {
            strncpy(cdr_data->cell_name_origin, ptr, szCellName);
            cdr_data->cell_name_origin[szCellName] = '\0';
         }
         else
         {
            sprintf(tmpstr,"%d",j);
            strncpy(cdr_data->cell_name_origin, tmpstr, szCellName);
            cdr_data->cell_name_origin[szCellName] = '\0';
         }
         break;
     }
   }

   if(new_timezone)
   {
      if(timezone_lookup(cdr_data->timezone,unix_tz,&isdst) != SUCCESS)
      {
         emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
         set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
         sprintf(tmpstr,"%d,Timezone:%d",CAP_BAD_TIMEZONE,cdr_data->timezone);
         emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
         set_mps_error_struct(tmpstr,"");
         return(SUCCESS);
      }
      /* if we get a unix time do conversion 
      ** from int to arbor/bp date format */

      if(trans_dt_type == to_int || second_dt_type == to_int || 
         rate_dt_type == to_int)
      {
         if(mpsGetGuideTZ() == TIMEZONE_NOT_USED) 
         {
            /* convert to input usage record's timezone
            ** (already saved in cdr_data)
            */
            strcpy(usage_tz, unix_tz);
         }
         else
         {
            /* Use guiding timezone instead.
            ** NOTE: in this case, the timezone from the usage record
            **       IS DISCARDED !!
            */
            strcpy(usage_tz, mpsGetGuideTZstr());
            cdr_data->timezone = mpsGetGuideTZ();  /* int version of mpsGetGuideTZstr() */
         }

         /* ----------------------------------------------------
         ** Convert trans_dt & second_dt to appropriate timezone
         ** since we are converting a unix time_t, the "from_tz" arg
         ** of convert_timezone (arg 3) is not used.
         */

         if(trans_dt_type == to_int)
         {
            if(convert_timezone(cdr_data->trans_time, cdr_data->trans_dt, "GMT0", usage_tz)
               == FAILURE)
            {
               emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
               set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
               sprintf(tmpstr,
                  "%d,Timezone:%d",
                  CAP_BAD_TIMEZONE,cdr_data->timezone);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               return(SUCCESS);
            }
         }
         if(second_dt_type == to_int)
         {
            if(convert_timezone(cdr_data->second_time, cdr_data->second_dt, "GMT0", usage_tz)
               == FAILURE)
            {
               emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
               set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
               sprintf(tmpstr,
                  "%d,Timezone:%d",
                  CAP_BAD_TIMEZONE,cdr_data->timezone);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               return(SUCCESS);
            }
         }
         if(rate_dt_type == to_int)
         {
            if(convert_timezone(cdr_data->rate_time, cdr_data->rate_dt, "GMT0", usage_tz)
               == FAILURE)
            {
               emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
               set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
               sprintf(tmpstr,
                  "%d,Timezone:%d",
                  CAP_BAD_TIMEZONE,cdr_data->timezone);
               emit(ERRLOC, MPS_GEN_ERROR, tmpstr );
               set_mps_error_struct(tmpstr,"");
               return(SUCCESS);
            }
         }
      }
   }
   else
   {
      /* no timezone provided, get the default time zone later */
      if(trans_dt_type == to_int || second_dt_type == to_int ||
         rate_dt_type == to_int)
      {
         if(mpsGetGuideTZ() == TIMEZONE_NOT_USED)
         {
            /* no default set, do not know what to convert to, hard error */
            emit(ERRLOC,CAP_NO_TIMEZONE);
            sprintf(tmpstr,
               "%d,No timezone",
               CAP_NO_TIMEZONE);
            emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
            set_mps_error_struct(tmpstr,"");
            return(SUCCESS);
         }
         else
         {
            /* Use guiding timezone */
            strcpy(usage_tz, mpsGetGuideTZstr());
            cdr_data->timezone = mpsGetGuideTZ();  /* int version of mpsGetGuideTZstr() */

            /* ----------------------------------------------------
            ** Convert trans_dt & second_dt to appropriate timezone
            */

            if(trans_dt_type == to_int)
            {
               if(convert_timezone(cdr_data->trans_time, cdr_data->trans_dt,
                  "GMT0", usage_tz) == FAILURE)
               {
                  emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
                  set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
                  sprintf(tmpstr,
                     "%d,Timezone:%d",
                     CAP_BAD_TIMEZONE,cdr_data->timezone);
                  emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
                  set_mps_error_struct(tmpstr,"");
                  return(SUCCESS);
               }
            }
            if(second_dt_type == to_int)
            {
               if(convert_timezone(cdr_data->second_time, cdr_data->second_dt,
                  "GMT0", usage_tz) == FAILURE)
               {
                  emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
                  set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
                  sprintf(tmpstr,
                     "%d,Timezone:%d",
                     CAP_BAD_TIMEZONE,cdr_data->timezone);
                  emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
                  set_mps_error_struct(tmpstr,"");
                  return(SUCCESS);
               }
            }
            if(rate_dt_type == to_int)
            {
               if(convert_timezone(cdr_data->rate_time, cdr_data->rate_dt,
                  "GMT0", usage_tz) == FAILURE)
               {
                  emit(ERRLOC, CAP_BAD_USG_TIMEZONE, cdr_data->timezone);
                  set_cdr_error_code(cdr_data, CAP_BAD_TIMEZONE);
                  sprintf(tmpstr,
                     "%d,Timezone:%d",
                     CAP_BAD_TIMEZONE,cdr_data->timezone);
                  emit(ERRLOC,MPS_GEN_ERROR, tmpstr );
                  set_mps_error_struct(tmpstr,"");
                  return(SUCCESS);
               }
            }
         }
      }
   }
   return(SUCCESS);

} /* ProcessUsgDetail() */
Exemple #22
0
int extract_path(str *body, str *path)
{
	static const str field = str_init("a=path:");
	return extract_field(body, path, field);
}
Exemple #23
0
int extract_rtcp(str *body, str *rtcp)
{
	static const str field = str_init("a=rtcp:");
	return extract_field(body, rtcp, field);
}
Exemple #24
0
/*
**  reply_by_mail() invokes sendmail on Unix or mail on VMS to send
**  a comment from the users to the owner
*/
PUBLIC void reply_by_mail ARGS4(
	char *,		mail_address,
	char *,		filename,
	CONST char *,	title,
	CONST char *,	refid)
{
#ifndef NO_ANONYMOUS_EMAIL
    static char *personal_name = NULL;
#endif
    char user_input[LINESIZE];
    FILE *fd, *fp;
    char *label = NULL;
    char *from_address = NULL;
    char *cc_address = NULL;
    char *to_address = NULL;
    char *the_subject = NULL;
    char *ccaddr = NULL;
    char *keywords = NULL;
    char *searchpart = NULL;
    char *body = NULL;
    char *cp = NULL, *cp1 = NULL;
    int i;
    int c = 0;	/* user input */
    char my_tmpfile[LY_MAXPATH];
    char default_subject[MAX_SUBJECT + 10];
#if USE_VMS_MAILER
    char *command = NULL;
    BOOLEAN isPMDF = LYMailPMDF();
    char hdrfile[LY_MAXPATH];
    FILE *hfd = 0;
#else
#if !CAN_PIPE_TO_MAILER
    char tmpfile2[LY_MAXPATH];
#endif
    char buf[4096];	/* 512 */
    char *header = NULL;
    int n;
#endif /* USE_VMS_MAILER */

    CTRACE((tfp, "reply_by_mail(\"%s\", \"%s\", \"%s\", \"%s\")\n",
	NONNULL(mail_address),
	NONNULL(filename),
	NONNULL(title),
	NONNULL(refid)));

    term_letter = FALSE;

    if (!LYSystemMail())
	return;

    if (isEmpty(mail_address)) {
	HTAlert(NO_ADDRESS_IN_MAILTO_URL);
	return;
    }
    StrAllocCopy(to_address, mail_address);

    if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) {
	HTAlert(MAILTO_URL_TEMPOPEN_FAILED);
	return;
    }
#if USE_VMS_MAILER
    if (isPMDF) {
	if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) {
	    HTAlert(MAILTO_URL_TEMPOPEN_FAILED);
	    return;
	}
    }
#endif /* VMS */
    default_subject[0] = '\0';

    /*
     *	Check for a ?searchpart. - FM
     */
    if ((cp = strchr(to_address, '?')) != NULL) {
	StrAllocCopy(searchpart, cp);
	*cp = '\0';
	cp = (searchpart + 1);
	if (*cp != '\0') {
	    /*
	     *	Seek and handle a subject=foo. - FM
	     */
	    extract_subject(default_subject, searchpart);

	    /*
	     *	Seek and handle to=address(es) fields.
	     *	Appends to address. - FM
	     */
	    extract_field(&to_address, searchpart, "to=");

	    /*
	     *	Seek and handle cc=address(es) fields.	Excludes
	     *	Bcc=address(es) as unsafe.  We may append our own
	     *	cc (below) as a list for the actual mailing. - FM
	     */
	    extract_field(&ccaddr, searchpart, "cc=");

	    /*
	     *	Seek and handle keywords=term(s) fields. - FM
	     */
	    extract_field(&keywords, searchpart, "keywords=");

	    if (keywords != NULL) {
		if (*keywords != '\0') {
		    SafeHTUnEscape(keywords);
		} else {
		    FREE(keywords);
		}
	    }

	    /*
	     *	Seek and handle body=foo fields. - FM
	     */
	    extract_body(&body, searchpart);

	    FREE(searchpart);
	}
    }

    if (convert_explorer(to_address)) {
	HTAlert(NO_ADDRESS_IN_MAILTO_URL);
	goto cancelled;
    }
    if (ccaddr != NULL) {
	if (convert_explorer(ccaddr)) {
	    FREE(ccaddr);
	}
    }

    /*
     *	Unescape the address and ccaddr fields. - FM
     */
    SafeHTUnEscape(to_address);
    if (ccaddr != NULL) {
	SafeHTUnEscape(ccaddr);
    }

    /*
     *	Set the default subject. - FM
     */
    if (isEmpty(default_subject) && !isEmpty(title)) {
	strncpy(default_subject, title, MAX_SUBJECT);
	default_subject[MAX_SUBJECT] = '\0';
    }

    /*
     *	Use ^G to cancel mailing of comment
     *	and don't let SIGINTs exit lynx.
     */
    signal(SIGINT, terminate_letter);

#if USE_VMS_MAILER
    if (isPMDF || !body) {
	/*
	 *  Put the X-URL and X-Mailer lines in the hdrfile
	 *  for PMDF or my_tmpfile for VMS MAIL. - FM
	 */
	fprintf((isPMDF ? hfd : fd),
		"X-URL: %s%s\n",
		isEmpty(filename) ? STR_MAILTO_URL : filename,
		isEmpty(filename) ? to_address : "");
	fprintf((isPMDF ? hfd : fd),
		"X-Mailer: %s, Version %s\n", LYNX_NAME, LYNX_VERSION);
#ifdef NO_ANONYMOUS_EMAIL
	if (!isPMDF) {
	    fprintf(fd, "\n");
	}
#endif /* NO_ANONYMOUS_EMAIL */
    }
#else /* Unix/DOS/Windows */
    /*
     *	Put the To: line in the header.
     */
#ifndef DOSPATH
    asprintf(&header, "To: %s\n", to_address);
    if (!header) {
	fprintf(stderr, "Out of memory, you lose!\n");
	exit(1);
    }
#endif

    /*
     *	Put the Mime-Version, Content-Type and
     *	Content-Transfer-Encoding in the header.
     *	This assumes that the same character set is used
     *	for composing the mail which is currently selected
     *	as display character set...
     *	Don't send a charset if we have a CJK character set
     *	selected, since it may not be appropriate for mail...
     *	Also don't use an unofficial "x-" charset.
     *	Also if the charset would be "us-ascii" (7-bit replacements
     *	selected, don't send any MIME headers. - kw
     */
    if (strncasecomp(LYCharSet_UC[current_char_set].MIMEname,
		     "us-ascii", 8) != 0) {
	StrAllocCat(header, "Mime-Version: 1.0\n");
	if (!LYHaveCJKCharacterSet &&
	    strncasecomp(LYCharSet_UC[current_char_set].MIMEname, "x-", 2)
	    != 0) {
	    HTSprintf(&header, "Content-Type: text/plain; charset=%s\n",
		    LYCharSet_UC[current_char_set].MIMEname);
	}
	StrAllocCat(header, "Content-Transfer-Encoding: 8bit\n");
    }
    /*
     *	Put the X-URL and X-Mailer lines in the header.
     */
    if (!isEmpty(filename)) {
	HTSprintf(&header, "X-URL: %s\n", filename);
    } else {
	HTSprintf(&header, "X-URL: mailto:%s\n", to_address);
    }
    HTSprintf(&header, "X-Mailer: %s, Version %s\n", LYNX_NAME, LYNX_VERSION);

    if (!isEmpty(refid)) {
	HTSprintf(&header, "In-Reply-To: <%s>\n", refid);
    }
#endif /* VMS */

    /*
     *	Clear the screen and inform the user.
     */
    LYclear();
    LYmove(2,0);
    scrollok(LYwin, TRUE);	/* Enable scrolling. */
    if (body)
	LYaddstr(SENDING_MESSAGE_WITH_BODY_TO);
    else
	LYaddstr(SENDING_COMMENT_TO);
    show_addresses(to_address);
    if (
#if USE_VMS_MAILER
	(isPMDF == TRUE) &&
#endif /* VMS */
	(cp = ccaddr) != NULL)
    {
	if (strchr(cp, ',') != NULL) {
	    LYaddstr(WITH_COPIES_TO);
	} else {
	    LYaddstr(WITH_COPY_TO);
	}
	show_addresses(ccaddr);
    }
    LYaddstr(CTRL_G_TO_CANCEL_SEND);

#if USE_VMS_MAILER
    if (isPMDF || !body) {
#endif /* USE_VMS_MAILER */
#ifndef NO_ANONYMOUS_EMAIL
    /*
     *	Get the user's personal name.
     */
    LYaddstr(ENTER_NAME_OR_BLANK);
#if USE_VMS_MAILER
    if (isPMDF) {
	label = "Personal_name: ";
    } else {
	label = "X-Personal_name: ";
    }
#else
    label = "X-Personal_Name: ";
#endif /* USE_VMS_MAILER */
    if (!header_prompt(label, &personal_name, LINESIZE)) {
	goto cancelled;
    }
    if (*personal_name) {
#if USE_VMS_MAILER
	fprintf((isPMDF ? hfd : fd), "%s: %s\n", label, personal_name);
#else
	HTSprintf(&header, "%s: %s\n", label, personal_name);
#endif /* VMS */
    }

    /*
     *	Get the user's return address.
     */
    LYaddstr(ENTER_MAIL_ADDRESS_OR_OTHER);
    LYaddstr(MEANS_TO_CONTACT_FOR_RESPONSE);
#if USE_VMS_MAILER
    if (isPMDF) {
	label = "From";
    } else {
	label = "X-From";
    }
#else
    label = "From";
#endif /* VMS */
    /* Add the personal mail address if there is one. */
    if (personal_mail_address)
	StrAllocCopy(from_address, personal_mail_address);
    if (!header_prompt(label, &from_address, LINESIZE)) {
	goto cancelled;
    }
#if USE_VMS_MAILER
    if (*from_address) {
	fprintf(isPMDF ? hfd : fd, "%s: %s\n", label, from_address);
    }
    if (!isPMDF) {
	fprintf(fd, "\n");
    }
#else
    HTSprintf(&header, "%s: %s\n", label, from_address);
#endif /* USE_VMS_MAILER */
#endif /* !NO_ANONYMOUS_EMAIL */
#if USE_VMS_MAILER
    }
#endif /* USE_VMS_MAILER */

    /*
     *	Get the subject line.
     */
    LYaddstr(ENTER_SUBJECT_LINE);
    label = "Subject";
    if (*default_subject) {
	StrAllocCopy(the_subject, default_subject);
    } else if (!isEmpty(filename)) {
	HTSprintf(&the_subject, "%s", filename);
    } else {
	HTSprintf(&the_subject, "mailto:%s", to_address);
    }
    if (!header_prompt(label, &the_subject, MAX_SUBJECT)) {
	goto cancelled;
    }

    /*
     *	Offer a CC line, if permitted. - FM
     */
    if (!LYNoCc) {
	LYaddstr(ENTER_ADDRESS_FOR_CC);
	LYaddstr(BLANK_FOR_NO_COPY);
	if (personal_mail_address)
	    StrAllocCopy(cc_address, personal_mail_address);
	if (!header_prompt("Cc", &cc_address, LINESIZE)) {
	    goto cancelled;
	}
	comma_append(&ccaddr, cc_address);
    }

#if !USE_VMS_MAILER
    HTSprintf(&header, "%s: %s\n", label, the_subject);
#if !CAN_PIPE_TO_MAILER
    if (*to_address) {
	HTSprintf(&header, "To: %s\n", to_address);
    }
#endif

    /*
    **	Add the Cc: header. - FM
    */
    if (!isEmpty(ccaddr)) {
	HTSprintf(&header, "Cc: %s\n", ccaddr);
    }

    /*
    **	Add the Keywords: header. - FM
    */
    if (!isEmpty(keywords)) {
	HTSprintf(&header, "Keywords: %s\n", keywords);
    }

    /*
     *	Terminate the header.
     */
    StrAllocCat(header, "\n");
    CTRACE((tfp,"**header==\n%s",header));
#endif /* !VMS */

    if (!no_editor && !isEmpty(editor)) {

	if (body) {
	    cp1 = body;
	    while((cp = strchr(cp1, '\n')) != NULL) {
		*cp++ = '\0';
		fprintf(fd, "%s\n", cp1);
		cp1 = cp;
	    }
	} else if (strcmp(HTLoadedDocumentURL(), "")) {
	    /*
	     *	Ask if the user wants to include the original message.
	     */
	    BOOLEAN is_preparsed = (BOOL) (LYPreparsedSource &&
				    HTisDocumentSource());
	    if (HTConfirm(is_preparsed
		? INC_PREPARSED_MSG_PROMPT
		: INC_ORIG_MSG_PROMPT) == YES) {
		print_wwwfile_to_fd(fd, (BOOL) !is_preparsed);
	    }
	}
	LYCloseTempFP(fd);	/* Close the tmpfile. */
	scrollok(LYwin,FALSE);	/* Stop scrolling.    */

	if (term_letter || LYCharIsINTERRUPT(c))
	    goto cleanup;

	/*
	 *  Spawn the users editor on the mail file
	 */
	edit_temporary_file(my_tmpfile, "", SPAWNING_EDITOR_FOR_MAIL);

    } else if (body) {
	/*
	 *  Let user review the body. - FM
	 */
	LYclear();
	LYmove(0,0);
	LYaddstr(REVIEW_MESSAGE_BODY);
	LYrefresh();
	cp1 = body;
	i = (LYlines - 5);
	while((cp = strchr(cp1, '\n')) != NULL) {
	    if (i <= 0) {
		LYaddstr(RETURN_TO_CONTINUE);
		LYrefresh();
		c = LYgetch();
		LYaddstr("\n");
		if (term_letter || LYCharIsINTERRUPT(c)) {
		    goto cancelled;
		}
		i = (LYlines - 2);
	    }
	    *cp++ = '\0';
	    fprintf(fd, "%s\n", cp1);
	    LYaddstr(cp1);
	    LYaddstr("\n");
	    cp1 = cp;
	    i--;
	}
	while (i >= 0) {
	    LYaddstr("\n");
	    i--;
	}
	LYrefresh();
	LYCloseTempFP(fd);	/* Close the tmpfile.	  */
	scrollok(LYwin,FALSE);	/* Stop scrolling.	  */

    } else {
	/*
	 *  Use the internal line editor for the message.
	 */
	LYaddstr(ENTER_MESSAGE_BELOW);
	LYaddstr(ENTER_PERIOD_WHEN_DONE_A);
	LYaddstr(ENTER_PERIOD_WHEN_DONE_B);
	LYaddstr("\n\n");
	LYrefresh();
	*user_input = '\0';
	if (LYgetstr(user_input, VISIBLE, sizeof(user_input), NORECALL) < 0 ||
	    term_letter || STREQ(user_input, ".")) {
	    goto cancelled;
	}

	while (!STREQ(user_input, ".") && !term_letter) {
	    LYaddstr("\n");
	    remove_tildes(user_input);
	    fprintf(fd, "%s\n", user_input);
	    *user_input = '\0';
	    if (LYgetstr(user_input, VISIBLE,
			 sizeof(user_input), NORECALL) < 0) {
		goto cancelled;
	    }
	}

	fprintf(fd, "\n");	/* Terminate the message. */
	LYCloseTempFP(fd);	/* Close the tmpfile.	  */
	scrollok(LYwin,FALSE);	/* Stop scrolling.	  */
    }

#if !USE_VMS_MAILER
    /*
     *	Ignore CTRL-C on this last question.
     */
    signal(SIGINT, SIG_IGN);
#endif /* !VMS */
    LYStatusLine = (LYlines - 1);
    c = HTConfirm (body ? SEND_MESSAGE_PROMPT : SEND_COMMENT_PROMPT);
    LYStatusLine = -1;
    if (c != YES) {
	LYclear();  /* clear the screen */
	goto cleanup;
    }
    if ((body == NULL && LynxSigFile != NULL) &&
	(fp = fopen(LynxSigFile, TXT_R)) != NULL) {
	LYStatusLine = (LYlines - 1);
	if (term_letter) {
	    _user_message(APPEND_SIG_FILE, LynxSigFile);
	    c = 0;
	} else {
	    char *msg = NULL;
	    HTSprintf0(&msg, APPEND_SIG_FILE, LynxSigFile);
	    c = HTConfirm(msg);
	    FREE(msg);
	}
	LYStatusLine = -1;
	if (c == YES) {
	    if ((fd = fopen(my_tmpfile, TXT_A)) != NULL) {
		char *buffer = NULL;
		fputs("-- \n", fd);
		while (LYSafeGets(&buffer, fp) != NULL) {
		    fputs(buffer, fd);
		}
		LYCloseOutput(fd);
		FREE(buffer);
	    }
	}
	LYCloseInput(fp);
    }
    LYclear();  /* Clear the screen. */

    /*
     *	Send the message.
     */
#if USE_VMS_MAILER
    /*
     *	Set the mail command. - FM
     */
    if (isPMDF) {
	/*
	 *  For PMDF, put any keywords and the subject
	 *  in the header file and close it. - FM
	 */
	if (!isEmpty(keywords)) {
	    fprintf(hfd, "Keywords: %s\n", keywords);
	}
	fprintf(hfd, "Subject: %s\n\n", the_subject);
	LYCloseTempFP(hfd);
	/*
	 *  Now set up the command. - FM
	 */
	HTSprintf0(&command, "%s %s %s,%s ",
		system_mail,
		system_mail_flags,
		hdrfile,
		my_tmpfile);
    } else {
	/*
	 *  For "generic" VMS MAIL, include the subject in the
	 *  command, and ignore any keywords to minimize risk
	 *  of them making the line too long or having problem
	 *  characters. - FM
	 */
	HTSprintf0(&command, "%s %s%s/subject=\"%s\" %s ",
		system_mail,
		system_mail_flags,
		(strncasecomp(system_mail, "MAIL", 4) ? "" : "/noself"),
		the_subject,
		my_tmpfile);
    }

    vms_append_addrs(&command, to_address, "");
    if (!isEmpty(ccaddr)) {
	vms_append_addrs(&command, ccaddr, "/CC");
    }

    stop_curses();
    printf("%s\n\n$ %s\n\n%s", SENDING_COMMENT, command, PLEASE_WAIT);
    LYSystem(command);	/* SENDING COMMENT (VMS) */
    FREE(command);
    LYSleepAlert();
    start_curses();
#else /* Unix/DOS/Windows */
    /*
     *	Send the tmpfile into sendmail.
     */
    _statusline(SENDING_YOUR_MSG);
#if CAN_PIPE_TO_MAILER
    signal(SIGINT, SIG_IGN);
    if ((fp = LYPipeToMailer()) == 0) {
	HTInfoMsg(CANCELLED);
    }
#else
    if ((fp = LYOpenTemp(tmpfile2, ".txt", "w")) == NULL) {
	HTAlert(MAILTO_URL_TEMPOPEN_FAILED);
    }
#endif /* CAN_PIPE_TO_MAILER */
    if (fp != 0) {
	fd = fopen(my_tmpfile, TXT_R);
	if (fd == NULL) {
	    HTInfoMsg(CANCELLED);
#if CAN_PIPE_TO_MAILER
	    pclose(fp);
#else
	    LYCloseTempFP(fp);
#endif /* CAN_PIPE_TO_MAILER */
	} else {
#if USE_BLAT_MAILER
	    if (!mail_is_blat)
		fputs(header, fp);
#else
	    fputs(header, fp);
#endif
	    while ((n = fread(buf, 1, sizeof(buf), fd)) != 0) {
		fwrite(buf, 1, n, fp);
	    }
#if CAN_PIPE_TO_MAILER
	    pclose(fp);
#else
	    LYCloseTempFP(fp);	/* Close the tmpfile. */
	    LYSendMailFile (
		to_address,
		tmpfile2,
		the_subject,
		ccaddr,
		SENDING_COMMENT);
	    LYRemoveTemp(tmpfile2);	/* Delete the tmpfile. */
#endif /* CAN_PIPE_TO_MAILER */
	    LYCloseInput(fd); /* Close the tmpfile. */
	}
    }
#endif /* USE_VMS_MAILER */
    goto cleanup;

    /*
     *	Come here to cleanup and exit.
     */
cancelled:
    HTInfoMsg(CANCELLED);
    LYCloseTempFP(fd);		/* Close the tmpfile.	*/
    scrollok(LYwin,FALSE);	/* Stop scrolling.	*/
cleanup:
    signal(SIGINT, cleanup_sig);
    term_letter = FALSE;

#if USE_VMS_MAILER
    while (LYRemoveTemp(my_tmpfile) == 0)
	;		 /* Delete the tmpfile(s). */
    if (isPMDF) {
	LYRemoveTemp(hdrfile); /* Delete the hdrfile. */
    }
#else
    FREE(header);
    LYRemoveTemp(my_tmpfile);  /* Delete the tmpfile. */
#endif /* VMS */

    FREE(from_address);
    FREE(the_subject);
    FREE(cc_address);
    FREE(to_address);
    FREE(ccaddr);
    FREE(keywords);
    FREE(body);
    return;
}