Tcl_Command cmdToken;
/* We try with curl1, if it already exists with curl2...*/
- handleName=(char *)Tcl_Alloc(10);
+ handleName=(char *)Tcl_Alloc(32);
for (i=1;;i++) {
sprintf(handleName,"curl%d",i);
if (!Tcl_GetCommandInfo(interp,handleName,&info)) {
case 1:
Tcl_Free(curlData->outFile);
curlData->outFile=curlstrdup(Tcl_GetString(objv));
+ if (curlData->outFlag) {
+ if (curlData->outHandle!=NULL) {
+ fclose(curlData->outHandle);
+ curlData->outHandle=NULL;
+ }
+ }
if ((strcmp(curlData->outFile,""))&&(strcmp(curlData->outFile,"stdout"))) {
curlData->outFlag=1;
} else {
case 2:
Tcl_Free(curlData->inFile);
curlData->inFile=curlstrdup(Tcl_GetString(objv));
+ if (curlData->inFlag) {
+ if (curlData->inHandle!=NULL) {
+ fclose(curlData->inHandle);
+ curlData->inHandle=NULL;
+ }
+ }
if ((strcmp(curlData->inFile,""))&&(strcmp(curlData->inFile,"stdin"))) {
curlData->inFlag=1;
} else {
case 44:
Tcl_Free(curlData->headerFile);
curlData->headerFile=curlstrdup(Tcl_GetString(objv));
+ if (curlData->headerFlag) {
+ if (curlData->headerHandle!=NULL) {
+ fclose(curlData->headerHandle);
+ curlData->headerHandle=NULL;
+ }
+ curl_easy_setopt(curlHandle,CURLOPT_HEADERDATA,NULL);
+ }
if ((strcmp(curlData->headerFile,""))&&(strcmp(curlData->headerFile,"stdout"))
&&(strcmp(curlData->headerFile,"stderr"))) {
curlData->headerFlag=1;
}
break;
case 61:
+ if (curlData->headerFlag) {
+ if (curlData->headerHandle!=NULL) {
+ fclose(curlData->headerHandle);
+ curlData->headerHandle=NULL;
+ }
+ curl_easy_setopt(curlHandle,CURLOPT_HEADERDATA,NULL);
+ curlData->headerFlag=0;
+ }
if (curl_easy_setopt(curlHandle,CURLOPT_HEADERFUNCTION,
curlHeaderReader)) {
return TCL_ERROR;
case 62:
Tcl_Free(curlData->bodyVarName);
curlData->bodyVarName=curlstrdup(Tcl_GetString(objv));
+ if (curlData->outFlag) {
+ if (curlData->outHandle!=NULL) {
+ fclose(curlData->outHandle);
+ curlData->outHandle=NULL;
+ }
+ curl_easy_setopt(curlHandle,CURLOPT_WRITEDATA,NULL);
+ }
+ curlData->outFlag=0;
if (curl_easy_setopt(curlHandle,CURLOPT_WRITEFUNCTION,
curlBodyReader)) {
return TCL_ERROR;
break;
case 65:
curlData->writeProc=curlstrdup(Tcl_GetString(objv));
+ if (curlData->outFlag) {
+ if (curlData->outHandle!=NULL) {
+ fclose(curlData->outHandle);
+ curlData->outHandle=NULL;
+ }
+ curl_easy_setopt(curlHandle,CURLOPT_WRITEDATA,NULL);
+ }
curlData->outFlag=0;
if (curl_easy_setopt(curlHandle,CURLOPT_WRITEFUNCTION,
curlWriteProcInvoke)) {
break;
case 66:
curlData->readProc=curlstrdup(Tcl_GetString(objv));
+ if (curlData->inFlag) {
+ if (curlData->inHandle!=NULL) {
+ fclose(curlData->inHandle);
+ curlData->inHandle=NULL;
+ }
+ curl_easy_setopt(curlHandle,CURLOPT_READDATA,NULL);
+ }
curlData->inFlag=0;
if (strcmp(curlData->readProc,"")) {
if (curl_easy_setopt(curlHandle,CURLOPT_READFUNCTION,
headerContent[charLength]=0;
/* There may be multiple 'Set-Cookie' headers, so we use a list */
if (Tcl_StringCaseMatch(headerName,"Set-Cookie",1)) {
- Tcl_SetVar2(curlData->interp,curlData->headerVar,headerName, \
+ Tcl_SetVar2(curlData->interp,curlData->headerVar,headerName,
headerContent,TCL_LIST_ELEMENT|TCL_APPEND_VALUE);
} else {
Tcl_SetVar2(curlData->interp,curlData->headerVar,headerName,
headerContent,0);
}
+ Tcl_Free(headerContent);
+ Tcl_Free(headerName);
}
regExp=Tcl_RegExpCompile(curlData->interp,"(^(HTTP|http)[^\r]+)(\r*)(\n)");
match=Tcl_RegExpExec(curlData->interp,regExp,header,header);
Tcl_SetVar2(curlData->interp,curlData->headerVar,"http",
httpStatus,0);
+ Tcl_Free(httpStatus);
}
return size*nmemb;
}
Tcl_Command cmdToken;
/* We try with scurl1, if it already exists with scurl2...*/
- shandleName=(char *)Tcl_Alloc(10);
+ shandleName=(char *)Tcl_Alloc(32);
for (i=1;;i++) {
sprintf(shandleName,"scurl%d",i);
if (!Tcl_GetCommandInfo(interp,shandleName,&info)) {