comparison src/gaimrc.c @ 4634:d19872836812

[gaim-migrate @ 4941] This will let you set up different proxy settings for different accounts. Mainly useful to the corporate users that need to connect to an internal jabber server, and still want to connect to "external" stuff through a proxy, or something along those lines. I'm sure someone will come up with another use for it. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 02 Mar 2003 18:48:02 +0000
parents 7e1591c6d0d8
children 78d5be1af6a6
comparison
equal deleted inserted replaced
4633:812148fb2e2f 4634:d19872836812
544 if (strcmp(p->option, "alias")) 544 if (strcmp(p->option, "alias"))
545 return account; 545 return account;
546 546
547 g_snprintf(account->alias, sizeof(account->alias), "%s", p->value[0]); 547 g_snprintf(account->alias, sizeof(account->alias), "%s", p->value[0]);
548 548
549 if (!fgets(buf, sizeof(buf), f))
550 return account;
551
552 if (!strcmp(buf, "\t}"))
553 return account;
554
555 p = parse_line(buf, &parse_buffer);
556
557 if (strcmp(p->option, "proxy_opts"))
558 return account;
559
560 if(atoi(p->value[0]) != PROXY_USE_GLOBAL) {
561 account->gpi = g_new0(struct gaim_proxy_info, 1);
562 account->gpi->proxytype = atoi(p->value[0]);
563 g_snprintf(account->gpi->proxyhost, sizeof(account->gpi->proxyhost),
564 "%s", p->value[1]);
565 account->gpi->proxyport = atoi(p->value[2]);
566 g_snprintf(account->gpi->proxyuser, sizeof(account->gpi->proxyuser),
567 "%s", p->value[3]);
568 g_snprintf(account->gpi->proxypass, sizeof(account->gpi->proxypass),
569 "%s", p->value[4]);
570 }
571
549 return account; 572 return account;
550 573
551 } 574 }
552 575
553 static void gaimrc_write_user(FILE *f, struct gaim_account *account) 576 static void gaimrc_write_user(FILE *f, struct gaim_account *account)
594 fprintf(f, "\t\ticonfile { %s }\n", tmp); 617 fprintf(f, "\t\ticonfile { %s }\n", tmp);
595 g_free(tmp); 618 g_free(tmp);
596 } 619 }
597 #endif 620 #endif
598 fprintf(f, "\t\talias { %s }\n", account->alias); 621 fprintf(f, "\t\talias { %s }\n", account->alias);
622 fprintf(f, "\t\tproxy_opts ");
623 if(account->gpi) {
624 fprintf(f, "{ %d } { %s } { %d } { %s } { %s }\n",
625 account->gpi->proxytype, account->gpi->proxyhost,
626 account->gpi->proxyport, account->gpi->proxyuser,
627 (c = escape_text2(account->gpi->proxypass)));
628 free(c);
629 } else {
630 fprintf(f, "{ %d }\n", PROXY_USE_GLOBAL);
631 }
599 } 632 }
600 633
601 static void gaimrc_read_users(FILE *f) 634 static void gaimrc_read_users(FILE *f)
602 { 635 {
603 char buf[2048]; 636 char buf[2048];
986 } 1019 }
987 1020
988 len = c - proxy; 1021 len = c - proxy;
989 1022
990 if (!strncmp(proxy, "http://", len + 3)) 1023 if (!strncmp(proxy, "http://", len + 3))
991 proxytype = PROXY_HTTP; 1024 global_proxy_info.proxytype = PROXY_HTTP;
992 else 1025 else
993 return FALSE; 1026 return FALSE;
994 1027
995 debug_printf("found http proxy\n"); 1028 debug_printf("found http proxy\n");
996 /* Get past "://" */ 1029 /* Get past "://" */
1040 c++; 1073 c++;
1041 } 1074 }
1042 1075
1043 /* NOTE: HTTP_PROXY takes precendence. */ 1076 /* NOTE: HTTP_PROXY takes precendence. */
1044 if (host[0]) 1077 if (host[0])
1045 strcpy(proxyhost, host); 1078 strcpy(global_proxy_info.proxyhost, host);
1046 else 1079 else
1047 *proxyhost = '\0'; 1080 *global_proxy_info.proxyhost = '\0';
1048 1081
1049 if (user[0]) 1082 if (user[0])
1050 strcpy(proxyuser, user); 1083 strcpy(global_proxy_info.proxyuser, user);
1051 else 1084 else
1052 *proxyuser = '\0'; 1085 *global_proxy_info.proxyuser = '\0';
1053 1086
1054 if (pass[0]) 1087 if (pass[0])
1055 strcpy(proxypass, pass); 1088 strcpy(global_proxy_info.proxypass, pass);
1056 else 1089 else
1057 *proxypass = '\0'; 1090 *global_proxy_info.proxypass = '\0';
1058 1091
1059 proxyport = port; 1092 global_proxy_info.proxyport = port;
1060 1093
1061 debug_printf("host '%s'\nuser '%s'\npassword '%s'\nport %d\n", 1094 debug_printf("host '%s'\nuser '%s'\npassword '%s'\nport %d\n",
1062 proxyhost, proxyuser, proxypass, proxyport); 1095 global_proxy_info.proxyhost, global_proxy_info.proxyuser,
1096 global_proxy_info.proxypass, global_proxy_info.proxyport);
1063 1097
1064 return TRUE; 1098 return TRUE;
1065 } 1099 }
1066 1100
1067 static void gaimrc_read_proxy(FILE *f) 1101 static void gaimrc_read_proxy(FILE *f)
1069 char buf[2048]; 1103 char buf[2048];
1070 struct parse parse_buffer; 1104 struct parse parse_buffer;
1071 struct parse *p; 1105 struct parse *p;
1072 1106
1073 buf[0] = 0; 1107 buf[0] = 0;
1074 proxyhost[0] = 0; 1108 global_proxy_info.proxyhost[0] = 0;
1075 debug_printf("gaimrc_read_proxy\n"); 1109 debug_printf("gaimrc_read_proxy\n");
1076 1110
1077 while (buf[0] != '}') { 1111 while (buf[0] != '}') {
1078 if (buf[0] == '#') 1112 if (buf[0] == '#')
1079 continue; 1113 continue;
1082 return; 1116 return;
1083 1117
1084 p = parse_line(buf, &parse_buffer); 1118 p = parse_line(buf, &parse_buffer);
1085 1119
1086 if (!strcmp(p->option, "host")) { 1120 if (!strcmp(p->option, "host")) {
1087 g_snprintf(proxyhost, sizeof(proxyhost), "%s", 1121 g_snprintf(global_proxy_info.proxyhost,
1088 p->value[0]); 1122 sizeof(global_proxy_info.proxyhost), "%s", p->value[0]);
1089 debug_printf("set proxyhost %s\n", proxyhost); 1123 debug_printf("set proxyhost %s\n", global_proxy_info.proxyhost);
1090 } else if (!strcmp(p->option, "port")) { 1124 } else if (!strcmp(p->option, "port")) {
1091 proxyport = atoi(p->value[0]); 1125 global_proxy_info.proxyport = atoi(p->value[0]);
1092 } else if (!strcmp(p->option, "type")) { 1126 } else if (!strcmp(p->option, "type")) {
1093 proxytype = atoi(p->value[0]); 1127 global_proxy_info.proxytype = atoi(p->value[0]);
1094 } else if (!strcmp(p->option, "user")) { 1128 } else if (!strcmp(p->option, "user")) {
1095 g_snprintf(proxyuser, sizeof(proxyuser), "%s", 1129 g_snprintf(global_proxy_info.proxyuser,
1096 p->value[0]); 1130 sizeof(global_proxy_info.proxyuser), "%s", p->value[0]);
1097 } else if (!strcmp(p->option, "pass")) { 1131 } else if (!strcmp(p->option, "pass")) {
1098 g_snprintf(proxypass, sizeof(proxypass), "%s", 1132 g_snprintf(global_proxy_info.proxypass,
1099 p->value[0]); 1133 sizeof(global_proxy_info.proxypass), "%s", p->value[0]);
1100 } 1134 }
1101 } 1135 }
1102 if (proxyhost[0]) 1136 if (global_proxy_info.proxyhost[0])
1103 proxy_info_is_from_gaimrc = 1; 1137 proxy_info_is_from_gaimrc = 1;
1104 else if (!proxyhost[0]) { 1138 else {
1105
1106 gboolean getVars = TRUE; 1139 gboolean getVars = TRUE;
1107 proxy_info_is_from_gaimrc = 0; 1140 proxy_info_is_from_gaimrc = 0;
1108 1141
1109 if (g_getenv("HTTP_PROXY")) 1142 if (g_getenv("HTTP_PROXY"))
1110 g_snprintf(proxyhost, sizeof(proxyhost), "%s", 1143 g_snprintf(global_proxy_info.proxyhost,
1111 g_getenv("HTTP_PROXY")); 1144 sizeof(global_proxy_info.proxyhost), "%s",
1145 g_getenv("HTTP_PROXY"));
1112 else if (g_getenv("http_proxy")) 1146 else if (g_getenv("http_proxy"))
1113 g_snprintf(proxyhost, sizeof(proxyhost), "%s", 1147 g_snprintf(global_proxy_info.proxyhost,
1114 g_getenv("http_proxy")); 1148 sizeof(global_proxy_info.proxyhost), "%s",
1149 g_getenv("http_proxy"));
1115 else if (g_getenv("HTTPPROXY")) 1150 else if (g_getenv("HTTPPROXY"))
1116 g_snprintf(proxyhost, sizeof(proxyhost), "%s", 1151 g_snprintf(global_proxy_info.proxyhost,
1117 g_getenv("HTTPPROXY")); 1152 sizeof(global_proxy_info.proxyhost), "%s",
1118 1153 g_getenv("HTTPPROXY"));
1119 if (*proxyhost != '\0') 1154
1120 getVars = !gaimrc_parse_proxy_uri(proxyhost); 1155 if (*global_proxy_info.proxyhost != '\0')
1156 getVars = !gaimrc_parse_proxy_uri(global_proxy_info.proxyhost);
1121 1157
1122 if (getVars) 1158 if (getVars)
1123 { 1159 {
1124 if (g_getenv("HTTP_PROXY_PORT")) 1160 if (g_getenv("HTTP_PROXY_PORT"))
1125 proxyport = atoi(g_getenv("HTTP_PROXY_PORT")); 1161 global_proxy_info.proxyport = atoi(g_getenv("HTTP_PROXY_PORT"));
1126 else if (g_getenv("http_proxy_port")) 1162 else if (g_getenv("http_proxy_port"))
1127 proxyport = atoi(g_getenv("http_proxy_port")); 1163 global_proxy_info.proxyport = atoi(g_getenv("http_proxy_port"));
1128 else if (g_getenv("HTTPPROXYPORT")) 1164 else if (g_getenv("HTTPPROXYPORT"))
1129 proxyport = atoi(g_getenv("HTTPPROXYPORT")); 1165 global_proxy_info.proxyport = atoi(g_getenv("HTTPPROXYPORT"));
1130 1166
1131 if (g_getenv("HTTP_PROXY_USER")) 1167 if (g_getenv("HTTP_PROXY_USER"))
1132 g_snprintf(proxyuser, sizeof(proxyuser), "%s", 1168 g_snprintf(global_proxy_info.proxyuser,
1133 g_getenv("HTTP_PROXY_USER")); 1169 sizeof(global_proxy_info.proxyuser), "%s",
1170 g_getenv("HTTP_PROXY_USER"));
1134 else if (g_getenv("http_proxy_user")) 1171 else if (g_getenv("http_proxy_user"))
1135 g_snprintf(proxyuser, sizeof(proxyuser), "%s", 1172 g_snprintf(global_proxy_info.proxyuser,
1136 g_getenv("http_proxy_user")); 1173 sizeof(global_proxy_info.proxyuser), "%s",
1174 g_getenv("http_proxy_user"));
1137 else if (g_getenv("HTTPPROXYUSER")) 1175 else if (g_getenv("HTTPPROXYUSER"))
1138 g_snprintf(proxyuser, sizeof(proxyuser), "%s", 1176 g_snprintf(global_proxy_info.proxyuser,
1139 g_getenv("HTTPPROXYUSER")); 1177 sizeof(global_proxy_info.proxyuser), "%s",
1178 g_getenv("HTTPPROXYUSER"));
1140 1179
1141 if (g_getenv("HTTP_PROXY_PASS")) 1180 if (g_getenv("HTTP_PROXY_PASS"))
1142 g_snprintf(proxypass, sizeof(proxypass), "%s", 1181 g_snprintf(global_proxy_info.proxypass,
1143 g_getenv("HTTP_PROXY_PASS")); 1182 sizeof(global_proxy_info.proxypass), "%s",
1183 g_getenv("HTTP_PROXY_PASS"));
1144 else if (g_getenv("http_proxy_pass")) 1184 else if (g_getenv("http_proxy_pass"))
1145 g_snprintf(proxypass, sizeof(proxypass), "%s", 1185 g_snprintf(global_proxy_info.proxypass,
1146 g_getenv("http_proxy_pass")); 1186 sizeof(global_proxy_info.proxypass), "%s",
1187 g_getenv("http_proxy_pass"));
1147 else if (g_getenv("HTTPPROXYPASS")) 1188 else if (g_getenv("HTTPPROXYPASS"))
1148 g_snprintf(proxypass, sizeof(proxypass), "%s", 1189 g_snprintf(global_proxy_info.proxypass,
1149 g_getenv("HTTPPROXYPASS")); 1190 sizeof(global_proxy_info.proxypass), "%s",
1150 1191 g_getenv("HTTPPROXYPASS"));
1151 1192
1152 if (proxyhost[0]) 1193 if (global_proxy_info.proxyhost[0])
1153 proxytype = PROXY_HTTP; 1194 global_proxy_info.proxytype = PROXY_HTTP;
1154 } 1195 }
1155 } 1196 }
1156 } 1197 }
1157 1198
1158 static void gaimrc_write_proxy(FILE *f) 1199 static void gaimrc_write_proxy(FILE *f)
1159 { 1200 {
1160 char *str; 1201 char *str;
1161 1202
1162 fprintf(f, "proxy {\n"); 1203 fprintf(f, "proxy {\n");
1163 if (proxy_info_is_from_gaimrc) { 1204 if (proxy_info_is_from_gaimrc) {
1164 fprintf(f, "\thost { %s }\n", proxyhost); 1205 fprintf(f, "\thost { %s }\n", global_proxy_info.proxyhost);
1165 fprintf(f, "\tport { %d }\n", proxyport); 1206 fprintf(f, "\tport { %d }\n", global_proxy_info.proxyport);
1166 fprintf(f, "\ttype { %d }\n", proxytype); 1207 fprintf(f, "\ttype { %d }\n", global_proxy_info.proxytype);
1167 fprintf(f, "\tuser { %s }\n", proxyuser); 1208 fprintf(f, "\tuser { %s }\n", global_proxy_info.proxyuser);
1168 fprintf(f, "\tpass { %s }\n", (str = escape_text2(proxypass))); 1209 fprintf(f, "\tpass { %s }\n",
1210 (str = escape_text2(global_proxy_info.proxypass)));
1169 free(str); 1211 free(str);
1170 } else { 1212 } else {
1171 fprintf(f, "\thost { %s }\n", ""); 1213 fprintf(f, "\thost { %s }\n", "");
1172 fprintf(f, "\tport { %d }\n", 0); 1214 fprintf(f, "\tport { %d }\n", 0);
1173 fprintf(f, "\ttype { %d }\n", 0); 1215 fprintf(f, "\ttype { %d }\n", 0);