static int ssl_cipher_process_rulestr(const char *rule_str,
                CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p,
                SSL_CIPHER **ca_list)
	{
	unsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength;
	const char *l, *start, *buf;
	int j, multi, found, rule, retval, ok, buflen;
	unsigned long cipher_id = 0;
	char ch;
	retval = 1;
	l = rule_str;
	for (;;)
		{
		ch = *l;
		if (ch == '\0')
			break;
		if (ch == '-')
			{ rule = CIPHER_DEL; l++; }
		else if (ch == '+')
			{ rule = CIPHER_ORD; l++; }
		else if (ch == '!')
			{ rule = CIPHER_KILL; l++; }
		else if (ch == '@')
			{ rule = CIPHER_SPECIAL; l++; }
		else
			{ rule = CIPHER_ADD; }
		if (ITEM_SEP(ch))
			{
			l++;
			continue;
			}
		alg_mkey = 0;
		alg_auth = 0;
		alg_enc = 0;
		alg_mac = 0;
		alg_ssl = 0;
		algo_strength = 0;
		start=l;
		for (;;)
			{
			ch = *l;
			buf = l;
			buflen = 0;
#ifndef CHARSET_EBCDIC
			while (	((ch >= 'A') && (ch <= 'Z')) ||
				((ch >= '0') && (ch <= '9')) ||
				((ch >= 'a') && (ch <= 'z')) ||
				 (ch == '-'))
#else
			while (	isalnum(ch) || (ch == '-'))
#endif
				 {
				 ch = *(++l);
				 buflen++;
				 }
			if (buflen == 0)
				{
				SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
				       SSL_R_INVALID_COMMAND);
				retval = found = 0;
				l++;
				break;
				}
			if (rule == CIPHER_SPECIAL)
				{
				found = 0;
				break;
				}
			if (ch == '+')
				{
				multi=1;
				l++;
				}
			else
				multi=0;
			j = found = 0;
			cipher_id = 0;
			while (ca_list[j])
				{
				if (!strncmp(buf, ca_list[j]->name, buflen) &&
				    (ca_list[j]->name[buflen] == '\0'))
					{
					found = 1;
					break;
					}
				else
					j++;
				}
			if (!found)
				break;
			if (ca_list[j]->algorithm_mkey)
				{
				if (alg_mkey)
					{
					alg_mkey &= ca_list[j]->algorithm_mkey;
					if (!alg_mkey) { found = 0; break; }
					}
				else
					alg_mkey = ca_list[j]->algorithm_mkey;
				}
			if (ca_list[j]->algorithm_auth)
				{
				if (alg_auth)
					{
					alg_auth &= ca_list[j]->algorithm_auth;
					if (!alg_auth) { found = 0; break; }
					}
				else
					alg_auth = ca_list[j]->algorithm_auth;
				}
			if (ca_list[j]->algorithm_enc)
				{
				if (alg_enc)
					{
					alg_enc &= ca_list[j]->algorithm_enc;
					if (!alg_enc) { found = 0; break; }
					}
				else
					alg_enc = ca_list[j]->algorithm_enc;
				}
			if (ca_list[j]->algorithm_mac)
				{
				if (alg_mac)
					{
					alg_mac &= ca_list[j]->algorithm_mac;
					if (!alg_mac) { found = 0; break; }
					}
				else
					alg_mac = ca_list[j]->algorithm_mac;
				}
			if (ca_list[j]->algo_strength & SSL_EXP_MASK)
				{
				if (algo_strength & SSL_EXP_MASK)
					{
					algo_strength &= (ca_list[j]->algo_strength & SSL_EXP_MASK) | ~SSL_EXP_MASK;
					if (!(algo_strength & SSL_EXP_MASK)) { found = 0; break; }
					}
				else
					algo_strength |= ca_list[j]->algo_strength & SSL_EXP_MASK;
				}
			if (ca_list[j]->algo_strength & SSL_STRONG_MASK)
				{
				if (algo_strength & SSL_STRONG_MASK)
					{
					algo_strength &= (ca_list[j]->algo_strength & SSL_STRONG_MASK) | ~SSL_STRONG_MASK;
					if (!(algo_strength & SSL_STRONG_MASK)) { found = 0; break; }
					}
				else
					algo_strength |= ca_list[j]->algo_strength & SSL_STRONG_MASK;
				}
			if (ca_list[j]->valid)
				{
				cipher_id = ca_list[j]->id;
				}
			else
				{
				if (ca_list[j]->algorithm_ssl)
					{
					if (alg_ssl)
						{
						alg_ssl &= ca_list[j]->algorithm_ssl;
						if (!alg_ssl) { found = 0; break; }
						}
					else
						alg_ssl = ca_list[j]->algorithm_ssl;
					}
				}
			if (!multi) break;
			}
		if (rule == CIPHER_SPECIAL)
			{
			ok = 0;
			if ((buflen == 8) &&
				!strncmp(buf, "STRENGTH", 8))
				ok = ssl_cipher_strength_sort(head_p, tail_p);
			else
				SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
					SSL_R_INVALID_COMMAND);
			if (ok == 0)
				retval = 0;
			while ((*l != '\0') && !ITEM_SEP(*l))
				l++;
			}
		else if (found)
			{
			ssl_cipher_apply_rule(cipher_id,
				alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength,
				rule, -1, head_p, tail_p);
			}
		else
			{
			while ((*l != '\0') && !ITEM_SEP(*l))
				l++;
			}
		if (*l == '\0') break;
		}
	return(retval);
	}
['static int ssl_cipher_process_rulestr(const char *rule_str,\n                CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p,\n                SSL_CIPHER **ca_list)\n\t{\n\tunsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength;\n\tconst char *l, *start, *buf;\n\tint j, multi, found, rule, retval, ok, buflen;\n\tunsigned long cipher_id = 0;\n\tchar ch;\n\tretval = 1;\n\tl = rule_str;\n\tfor (;;)\n\t\t{\n\t\tch = *l;\n\t\tif (ch == \'\\0\')\n\t\t\tbreak;\n\t\tif (ch == \'-\')\n\t\t\t{ rule = CIPHER_DEL; l++; }\n\t\telse if (ch == \'+\')\n\t\t\t{ rule = CIPHER_ORD; l++; }\n\t\telse if (ch == \'!\')\n\t\t\t{ rule = CIPHER_KILL; l++; }\n\t\telse if (ch == \'@\')\n\t\t\t{ rule = CIPHER_SPECIAL; l++; }\n\t\telse\n\t\t\t{ rule = CIPHER_ADD; }\n\t\tif (ITEM_SEP(ch))\n\t\t\t{\n\t\t\tl++;\n\t\t\tcontinue;\n\t\t\t}\n\t\talg_mkey = 0;\n\t\talg_auth = 0;\n\t\talg_enc = 0;\n\t\talg_mac = 0;\n\t\talg_ssl = 0;\n\t\talgo_strength = 0;\n\t\tstart=l;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tch = *l;\n\t\t\tbuf = l;\n\t\t\tbuflen = 0;\n#ifndef CHARSET_EBCDIC\n\t\t\twhile (\t((ch >= \'A\') && (ch <= \'Z\')) ||\n\t\t\t\t((ch >= \'0\') && (ch <= \'9\')) ||\n\t\t\t\t((ch >= \'a\') && (ch <= \'z\')) ||\n\t\t\t\t (ch == \'-\'))\n#else\n\t\t\twhile (\tisalnum(ch) || (ch == \'-\'))\n#endif\n\t\t\t\t {\n\t\t\t\t ch = *(++l);\n\t\t\t\t buflen++;\n\t\t\t\t }\n\t\t\tif (buflen == 0)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,\n\t\t\t\t       SSL_R_INVALID_COMMAND);\n\t\t\t\tretval = found = 0;\n\t\t\t\tl++;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (rule == CIPHER_SPECIAL)\n\t\t\t\t{\n\t\t\t\tfound = 0;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (ch == \'+\')\n\t\t\t\t{\n\t\t\t\tmulti=1;\n\t\t\t\tl++;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tmulti=0;\n\t\t\tj = found = 0;\n\t\t\tcipher_id = 0;\n\t\t\twhile (ca_list[j])\n\t\t\t\t{\n\t\t\t\tif (!strncmp(buf, ca_list[j]->name, buflen) &&\n\t\t\t\t    (ca_list[j]->name[buflen] == \'\\0\'))\n\t\t\t\t\t{\n\t\t\t\t\tfound = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\tif (!found)\n\t\t\t\tbreak;\n\t\t\tif (ca_list[j]->algorithm_mkey)\n\t\t\t\t{\n\t\t\t\tif (alg_mkey)\n\t\t\t\t\t{\n\t\t\t\t\talg_mkey &= ca_list[j]->algorithm_mkey;\n\t\t\t\t\tif (!alg_mkey) { found = 0; break; }\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\talg_mkey = ca_list[j]->algorithm_mkey;\n\t\t\t\t}\n\t\t\tif (ca_list[j]->algorithm_auth)\n\t\t\t\t{\n\t\t\t\tif (alg_auth)\n\t\t\t\t\t{\n\t\t\t\t\talg_auth &= ca_list[j]->algorithm_auth;\n\t\t\t\t\tif (!alg_auth) { found = 0; break; }\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\talg_auth = ca_list[j]->algorithm_auth;\n\t\t\t\t}\n\t\t\tif (ca_list[j]->algorithm_enc)\n\t\t\t\t{\n\t\t\t\tif (alg_enc)\n\t\t\t\t\t{\n\t\t\t\t\talg_enc &= ca_list[j]->algorithm_enc;\n\t\t\t\t\tif (!alg_enc) { found = 0; break; }\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\talg_enc = ca_list[j]->algorithm_enc;\n\t\t\t\t}\n\t\t\tif (ca_list[j]->algorithm_mac)\n\t\t\t\t{\n\t\t\t\tif (alg_mac)\n\t\t\t\t\t{\n\t\t\t\t\talg_mac &= ca_list[j]->algorithm_mac;\n\t\t\t\t\tif (!alg_mac) { found = 0; break; }\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\talg_mac = ca_list[j]->algorithm_mac;\n\t\t\t\t}\n\t\t\tif (ca_list[j]->algo_strength & SSL_EXP_MASK)\n\t\t\t\t{\n\t\t\t\tif (algo_strength & SSL_EXP_MASK)\n\t\t\t\t\t{\n\t\t\t\t\talgo_strength &= (ca_list[j]->algo_strength & SSL_EXP_MASK) | ~SSL_EXP_MASK;\n\t\t\t\t\tif (!(algo_strength & SSL_EXP_MASK)) { found = 0; break; }\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\talgo_strength |= ca_list[j]->algo_strength & SSL_EXP_MASK;\n\t\t\t\t}\n\t\t\tif (ca_list[j]->algo_strength & SSL_STRONG_MASK)\n\t\t\t\t{\n\t\t\t\tif (algo_strength & SSL_STRONG_MASK)\n\t\t\t\t\t{\n\t\t\t\t\talgo_strength &= (ca_list[j]->algo_strength & SSL_STRONG_MASK) | ~SSL_STRONG_MASK;\n\t\t\t\t\tif (!(algo_strength & SSL_STRONG_MASK)) { found = 0; break; }\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\talgo_strength |= ca_list[j]->algo_strength & SSL_STRONG_MASK;\n\t\t\t\t}\n\t\t\tif (ca_list[j]->valid)\n\t\t\t\t{\n\t\t\t\tcipher_id = ca_list[j]->id;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (ca_list[j]->algorithm_ssl)\n\t\t\t\t\t{\n\t\t\t\t\tif (alg_ssl)\n\t\t\t\t\t\t{\n\t\t\t\t\t\talg_ssl &= ca_list[j]->algorithm_ssl;\n\t\t\t\t\t\tif (!alg_ssl) { found = 0; break; }\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\talg_ssl = ca_list[j]->algorithm_ssl;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (!multi) break;\n\t\t\t}\n\t\tif (rule == CIPHER_SPECIAL)\n\t\t\t{\n\t\t\tok = 0;\n\t\t\tif ((buflen == 8) &&\n\t\t\t\t!strncmp(buf, "STRENGTH", 8))\n\t\t\t\tok = ssl_cipher_strength_sort(head_p, tail_p);\n\t\t\telse\n\t\t\t\tSSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,\n\t\t\t\t\tSSL_R_INVALID_COMMAND);\n\t\t\tif (ok == 0)\n\t\t\t\tretval = 0;\n\t\t\twhile ((*l != \'\\0\') && !ITEM_SEP(*l))\n\t\t\t\tl++;\n\t\t\t}\n\t\telse if (found)\n\t\t\t{\n\t\t\tssl_cipher_apply_rule(cipher_id,\n\t\t\t\talg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl, algo_strength,\n\t\t\t\trule, -1, head_p, tail_p);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\twhile ((*l != \'\\0\') && !ITEM_SEP(*l))\n\t\t\t\tl++;\n\t\t\t}\n\t\tif (*l == \'\\0\') break;\n\t\t}\n\treturn(retval);\n\t}']